支付完成回调

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

@@ -4,11 +4,18 @@ namespace app\controller;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use GuzzleHttp\Client; use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use think\facade\Config; use think\facade\Config;
class Check class Check
{ {
/**
* Notes : 微信被封检测
*
* @Date : 2022/9/13 13:39
* @Author : <Jason.C>
* @throws GuzzleException
*/
public function index() public function index()
{ {
$url = $GLOBALS['data']['data']['url']; $url = $GLOBALS['data']['data']['url'];

View File

@@ -7,7 +7,6 @@ use app\model\Payment;
use EasyWeChat\Factory; use EasyWeChat\Factory;
use EasyWeChat\OfficialAccount\Application; use EasyWeChat\OfficialAccount\Application;
use think\facade\Config; use think\facade\Config;
use think\facade\Db;
use think\facade\Request; use think\facade\Request;
use think\facade\Route; use think\facade\Route;
use think\facade\View; use think\facade\View;
@@ -128,7 +127,21 @@ class Wechat
*/ */
public function paid() 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.');
}
});
} }
} }

View File

@@ -2,6 +2,7 @@
namespace app\model; namespace app\model;
use Carbon\Carbon;
use think\Model; use think\Model;
use think\model\relation\BelongsTo; use think\model\relation\BelongsTo;
@@ -13,4 +14,17 @@ class Payment extends Model
{ {
return $this->belongsTo(Order::class); return $this->belongsTo(Order::class);
} }
/**
* Notes : 订单支付完成后续操作
*
* @Date : 2022/9/13 15:41
* @Author : <Jason.C>
*/
public function paid()
{
$this->paid_at = Carbon::now(); // 更新支付时间为当前时间
$this->status = 1;
$this->save();
}
} }

View File

@@ -27,7 +27,8 @@
"aliyuncs/oss-sdk-php": "^2.6", "aliyuncs/oss-sdk-php": "^2.6",
"topthink/think-view": "^1.0", "topthink/think-view": "^1.0",
"overtrue/wechat": "~5.0", "overtrue/wechat": "~5.0",
"guzzlehttp/guzzle": "^7.5" "guzzlehttp/guzzle": "^7.5",
"nesbot/carbon": "^2.62"
}, },
"require-dev": { "require-dev": {
"symfony/var-dumper": "^4.2", "symfony/var-dumper": "^4.2",