Laravel教程: 3分钟实现小程序微信支付接入(下)——回调发货逻辑
接上文: Laravel教程: 3分钟实现小程序微信支付接入(上)——唤起支付
编码
绑定回调路由 routes/api.php
Route::any('/gateway/wxpay/callback', 'PayController@callback')->name('pay.callback');
注意前一篇文章的添加 .env
与此处路由的 URL 要保持一致。:
WECHAT_PAYMENT_NOTIFY_URL=https://www.mysite.com/gateway/wxpay/callback
app/Http/Controllers/PayController.php 添加 callback 方法
/** * 微信支付回调 * * @return Response */ public function callback() { return $this->buy_repository->callback(); }
appRepositoriesBuyRepository.php 添加 callback 逻辑
public function callback() { $this->wxpay = app('easywechat.payment'); return $this->wxpay->handlePaidNotify( function ($message, $fail) { if ($message['result_code'] === 'FAIL') { logger()->warning('WXPAY_CALLBACK', ['FAIL', $message]); return true; } else if ($message['return_code'] === 'SUCCESS') { // TODO: 你的发货逻辑 return true; } } ); }
相关推荐
taiyangyu 2020-09-10
CodeAndroid 2020-09-10
powderhose 2020-06-12
mazegong 2020-06-09
sucheng 2020-06-08
hgzhang 2020-06-08
且听真言 2020-06-08
且听真言 2020-05-11
kgshuo 2020-09-25
Tomato 2020-09-10
small 2020-07-29
sucheng 2020-07-26
zuoliangzhu 2020-07-20
CodeAndroid 2020-07-14
xiaoxubbs 2020-07-04
sucheng 2020-06-25
kgshuo 2020-06-14
意外金喜 2020-06-14