| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace App\Http\Controllers\Api\v1;
- use App\Http\Controllers\Api\BaseController;
- use App\Services\NotifyService;
- use App\Services\RedisService;
- use App\Services\SiyuanService;
- use App\Services\WechatService;
- /**
- * 回调控制器
- * @author wesmiler
- * @since 2020/11/10
- * Class NotifyController
- * @package App\Http\Controllers
- */
- class NotifyController extends BaseController
- {
- /**
- * 构造函数
- * @author wesmiler
- * @since 2020/11/11
- * NotifyController constructor.
- */
- public function __construct()
- {
- parent::__construct();
- $this->service = new SiyuanService();
- }
- /**
- * 支付回调
- */
- public function pay($scene){
- $postData = request()->all();
- $sign = request()->headers->get('Wechatpay-Signature');
- $nonce = request()->headers->get('Wechatpay-Nonce');
- $timestamp = request()->headers->get('Wechatpay-Timestamp');
- /* $sign = 'JnLbXF3HLEeAVuyVoyedezPV8+mRZ93+rmlbHOIm1I0+YKboBTUmVNwlV9KKOVPXPBQENxjHqT6fR5Qx326uVZryb\/JM+lTdvl3j+XVD0F5NJWZKGu7Zykf69yYMY3wbe1++em\/iiouZLg8\/5KRp7nvNMLL383gemOMRbsYN3+dZ++62qrmVZxo00fHlK+AjxXmV38KRCLtfLWfIsUXw9Zi8hXqHbf+s\/pBthV+Ouasw0Eit4f4E3aDjp4baFD70s\/RsbcqTn8UqxCurRNgm7kCtLphzStPnEUC1dfvIWZQIuJ+BaAqstj9y7RW5CdF7aZPqhXnPETvB8ZynSTYl3Q==';
- $timestamp = '1626663968';
- $nonce = 'yWa6xnLUDyqfVYhjTnWcafDuNzgoXMNa';*/
- $postStr = file_get_contents("php://input");
- $signStr = "{$timestamp}\n{$nonce}\n{$postStr}\n";
- $id = isset($postData['id'])? '_'.$postData['id'] : '';
- RedisService::set('caches:payments:'.$scene.':result'.$id.'_'.date('YmdHis'), ['result'=> $postData,'sign'=> $sign,'date'=> date('Y-m-d H:i:s')], 7200);
- $postData = isset($postData['resource'])? $postData['resource'] : [];
- if(empty($scene) || empty($postData)){
- return NotifyService::make()->rebackMsg('回调参数错误');
- }
- // 解密
- $ciphertext = isset($postData['ciphertext'])? $postData['ciphertext'] : '';
- RedisService::set('caches:payments:'.$scene.':result'.$id.'_ciphertext', ['result'=> $postData,'date'=> date('Y-m-d H:i:s')], 7200);
- if(empty($ciphertext)){
- return NotifyService::make()->rebackMsg('解密数据不存在');
- }
- $postData = WechatService::decryptNotifyData($postData);
- $postData = $postData? json_decode($postData, true) : [];
- var_dump($postData);
- $outTradeNo = isset($postData['out_trade_no']) ? $postData['out_trade_no'] : '';
- if(empty($postData) || empty($outTradeNo)){
- return NotifyService::make()->rebackMsg('获取解密数据失败');
- }
- $postData['id'] = $id;
- $postData['sign'] = $sign;
- RedisService::set('caches:payments:'.$scene.':result_'.$outTradeNo, ['result'=> $postData], 7200);
- RedisService::set('caches:payments:'.$scene.':check', ['data'=> $postData,'signStr'=> $signStr,'sign'=> $sign], 3600);
- if (WechatService::checkJsapiNotifyV3($signStr, $sign) === true) {
- switch($scene){
- case 'index': // 供灯订单
- return NotifyService::make()->notifyGongdeng($postData, $outTradeNo);
- case 'recharge': // 充值
- break;
- default:
- break;
- }
- }
- return NotifyService::make()->rebackMsg('回调失败');
- }
- }
|