63 lines
2.0 KiB
PHP
63 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\enum\PayEnum;
|
|
use app\common\enum\user\UserTerminalEnum;
|
|
use app\common\logic\PayNotifyLogic;
|
|
use app\common\model\retail\Cashierclass;
|
|
use app\common\service\pay\WeChatPayService;
|
|
use app\Request;
|
|
use Error;
|
|
use support\Log;
|
|
use Webman\Config;
|
|
use Yansongda\Pay\Pay;
|
|
|
|
/**
|
|
* 支付
|
|
* Class PayController
|
|
* @package app\api\controller
|
|
*/
|
|
class PayController extends BaseApiController
|
|
{
|
|
|
|
public $notNeedLogin = ['notifyMnp', 'aa'];
|
|
|
|
/**
|
|
* @notes 小程序支付回调
|
|
* @return \Psr\Http\Message\ResponseInterface
|
|
* @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
|
|
* @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
|
|
* @throws \ReflectionException
|
|
* @throws \Throwable
|
|
* @author 段誉
|
|
* @date 2023/2/28 14:21
|
|
*/
|
|
public function notifyMnp()
|
|
{
|
|
$config = Config::get('payment');
|
|
Pay::config($config);
|
|
$result = Pay::wechat()->callback(Request()->post());
|
|
if($result && $result->event_type=='TRANSACTION.SUCCESS'){
|
|
$ciphertext=$result->resource->ciphertext;
|
|
if ($ciphertext['trade_state'] === 'SUCCESS') {
|
|
$extra['transaction_id'] = $ciphertext['transaction_id'];
|
|
$attach = $ciphertext['attach'];
|
|
$message['out_trade_no'] = mb_substr($ciphertext['out_trade_no'], 0, 18);
|
|
switch ($attach) {
|
|
case 'cashierclass':
|
|
$order = Cashierclass::where(['number' => $message['out_trade_no']])->findOrEmpty();
|
|
if ($order->isEmpty() || $order->paid == PayEnum::ISPAID) {
|
|
return true;
|
|
}
|
|
PayNotifyLogic::handle('cashierclass', $message['out_trade_no'], $ciphertext);
|
|
break;
|
|
}
|
|
return Pay::wechat()->success();
|
|
}
|
|
}
|
|
|
|
// return (new WeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
|
|
}
|
|
}
|