接上文: Laravel教程: 3分鐘實現小程序微信支付接入(上)——喚起支付php
綁定回調路由 routes/api.php小程序
Route::any('/gateway/wxpay/callback', 'PayController@callback')->name('pay.callback');
注意前一篇文章的添加 .env
與此處路由的 URL 要保持一致。:segmentfault
WECHAT_PAYMENT_NOTIFY_URL=https://www.mysite.com/gateway/wxpay/callback
app/Http/Controllers/PayController.php 添加 callback 方法api
/** * 微信支付回調 * * @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; } } ); }