香洲二院小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
mini_xzey/app/Http/Controllers/Notify/NotifyController.php

70 lines
2.1 KiB

<?php
declare(strict_types = 1);
namespace App\Http\Controllers\Notify;
use App\Dictionary\WeChat\Payment\V2Api;
use App\Http\Controllers\Controller;
use App\Http\Logics\Notify\NotifyLogic;
use App\Utils\Traits\Logger;
use EasyWeChat\Kernel\Exceptions\InvalidArgumentException;
use EasyWeChat\Kernel\Exceptions\RuntimeException;
use EasyWeChat\Pay\Message;
use Psr\Http\Message\ResponseInterface;
use ReflectionException;
use Throwable;
class NotifyController extends Controller
{
use Logger;
protected NotifyLogic $notify_logic;
/**
* NotifyController Construct
*/
public function __construct()
{
$this->notify_logic = new NotifyLogic();
$this->setChannel('notify');
}
/**
* @return ResponseInterface
* @throws InvalidArgumentException
* @throws RuntimeException
* @throws ReflectionException
* @throws Throwable
*/
public function notify(): ResponseInterface
{
$app = getWeChatMiniProgramPaymentApp();
$server = $app->getServer();
$server->handlePaid(function (Message $message, \Closure $next) use ($app) {
// $message->out_trade_no 获取商户订单号
// $message->payer['openid'] 获取支付者 openid
// 🚨🚨🚨 注意:推送信息不一定靠谱哈,请务必验证
// 建议是拿订单号调用微信支付查询接口,
$this->info('接收回调消息', $message->toArray());
try{
// 验证签名通过,业务处理
$app->getValidator()->validate($app->getRequest());
// 业务处理
$result = $this->notify_logic->notifyHandle($message);
$this->info('接受回调消息结果', ['result' => $result]);
} catch(\Exception $e){
// 验证失败
$err_msg = '订单验证签名失败:'. $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine();
$this->error($err_msg, [$message->toArray()]);
}
return $next($message);
});
return $server->serve();
}
}