1.下载yansongda/pay支付组件通过composer命令
composer require yansongda/pay
4.直接上手
protected $config = [
'app_id' => '', //APPID
'mch_id' => '', //商户id
'key' => '', //api秘钥
'sandbox' => true,
'notify_url' => '', //支付异步通知地址
// 'cert_client' => './cert/apiclient_cert.pem', // optional,退款等情况时用到
//'cert_key' => './cert/apiclient_key.pem',// optional,退款等情况时用到
'log' => [ // optional
'file' => './logs/wechat.log',
'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
'type' => 'single', // optional, 可选 daily.
'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
],
'http' => [ // optional
'timeout' => 5.0,
'connect_timeout' => 5.0,
// 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
],
'mode' => 'dev', // optional, dev/hk;当为 `hk` 时,为香港 gateway。 沙盒环境
];
public function wxpay(Request $request)
{
$order = [
'out_trade_no' => time(),
'total_fee' => 101, // **单位:分** , 沙盒环境金额固定101
'body' => '书币充值',
// 'openid' => 'onkVf1FjWS5SBIixxxxxxx',
];
$pay = Pay::wechat($this->config)->scan($order);
return $pay;
}
public function wx_notify()
{
$pay = Pay::wechat($this->config);
try {
$data = $pay->verify(); // 是的,验签就这么简单!
//订单状态修改
Log::debug('Wechat notify', $data->all());
} catch (\Exception $e) {
DB::table('order')->where('order', $orderId)->update(['type' => 3]);
$e->getMessage();
}
//return $pay->success()->send();// laravel 框架中请直接 `return $pay->success()`
return $pay->success();// laravel 框架中请直接 `return $pay->success()`
}
5.微信配置
?
2.创建控制器
php artisan make:controller AliPayController
3.引入yansongda/pay包
use Yansongda\Pay\Pay;
亲测可用
|