|
|
@@ -3,7 +3,6 @@
|
|
|
namespace App\Http\Controllers\Api\v1;
|
|
|
|
|
|
use App\Http\Controllers\Api\webApp;
|
|
|
-use App\Services\DyrPayService;
|
|
|
use App\Services\PaymentService;
|
|
|
use App\Services\RedisService;
|
|
|
|
|
|
@@ -69,62 +68,6 @@ class NotifyController extends webApp
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 支付回调
|
|
|
- * @param int $productId 产品
|
|
|
- * @return array|false|\Psr\Http\Message\ResponseInterface
|
|
|
- */
|
|
|
- public function payCallback($productId)
|
|
|
- {
|
|
|
- $date = date('Y-m-d H:i:s');
|
|
|
- $result = isset($_POST)? $_POST : request()->post();
|
|
|
- $key = isset($result['out_trade_num'])?$result['out_trade_num'] : date('YmdHis') . '_' . rand(1000, 9999);
|
|
|
- $channel = 'dryPay';
|
|
|
- if (empty($result)) {
|
|
|
- $result = file_get_contents('php://input');
|
|
|
- $result = $result ? json_decode($result, true) : [];
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- $sign = isset($result['sign'])?$result['sign']:'';
|
|
|
- unset($result['sign']);//删除掉sign字段
|
|
|
- $checkSign = DyrPayService::make()->makeSign($result, 2);
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:result_".$key, ['all' => request()->all(), 'sign'=>$sign,'checkSign'=>$checkSign, 'product_id' => $productId, 'result' => $result], 7200);
|
|
|
- if($sign != $checkSign){
|
|
|
- if (env('APP_DEBUG')) {
|
|
|
- logger()->channel($channel)->error("【{$date} 支付回调】签名错误:" . json_encode([ 'product_id' => $productId,'data' => $result], 256));
|
|
|
- }
|
|
|
-
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:sign_" . $key, ['all' => request()->all(), 'product_id' => $productId, 'result' => $result], 7200);
|
|
|
- return response('failed');
|
|
|
- }
|
|
|
-
|
|
|
- // 验签和重组参数
|
|
|
- $data = $result;
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:data_" . $key, ['all' => request()->all(),'product_id' => $productId, 'result' => $result], 7200);
|
|
|
- if (env('APP_DEBUG')) {
|
|
|
- logger()->channel($channel)->info("【{$date} 支付回调】验证结果:" . json_encode(['data' => $data,'product_id' => $productId],256));
|
|
|
- }
|
|
|
-
|
|
|
- // 回调处理
|
|
|
- if ($result = PaymentService::make()->catchPayNotify($productId, $data)) {
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:success_" . $key, ['msg'=>PaymentService::make()->getError(),'all' => request()->all(), 'product_id' => $productId, 'data' => $data,'result'=>$result], 7200);
|
|
|
- logger()->channel($channel)->info("【{$date} 支付回调】回调成功:" . json_encode(['data' => $data,'product_id' => $productId],256));
|
|
|
- return response('success');
|
|
|
- } else {
|
|
|
- $msg = PaymentService::make()->getError();
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:failed_" . $key, ['msg'=>$msg,'all' => request()->all(), 'product_id' => $productId, 'data' => $data], 7200);
|
|
|
- logger()->channel($channel)->info("【{$date} 支付回调】回调失败:" . json_encode(['data' => $data,'product_id' => $productId, 'error' => lang($msg)], 256));
|
|
|
- return message($msg ? $msg : 2635, false);
|
|
|
- }
|
|
|
- } catch (\Exception $exception) {
|
|
|
- RedisService::set("caches:payments:payNotify_{$productId}:error_" . $key, ['all' => request()->all(), 'product_id' => $productId, 'error' => $exception->getMessage(), 'data' => $result], 7200);
|
|
|
- logger()->channel($channel)->error("【{$date} 支付回调】回调错误:" . json_encode(['data' => $result,'product_id' => $productId, 'error' => $exception->getMessage()], 256));
|
|
|
- return message(2635, false, ['error' => $exception->getMessage()]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 退款回调
|
|
|
* @param string $scene 场景,refund-退款
|
|
|
* @param int $payType 支付方式:10-微信,20-支付宝
|