支付完成回调

This commit is contained in:
2022-09-13 15:49:38 +08:00
parent f4eec7077f
commit 22138a3d9d
4 changed files with 38 additions and 3 deletions

View File

@@ -7,7 +7,6 @@ use app\model\Payment;
use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application;
use think\facade\Config;
use think\facade\Db;
use think\facade\Request;
use think\facade\Route;
use think\facade\View;
@@ -128,7 +127,21 @@ class Wechat
*/
public function paid()
{
$this->initWechat();
return $this->app->handlePaidNotify(function ($message, $fail) {
$order = Payment::where('trade_no', $message['out_trade_no'])->find();
if (! $order || $order->paid_at) {
return true;
}
if (key_exists('result_code', $message) && $message['result_code'] === 'SUCCESS') {
$order->paid();
} else {
$fail('Order not exists.');
}
});
}
}