|
@@ -3,6 +3,8 @@
|
|
namespace App\Helper;
|
|
namespace App\Helper;
|
|
|
|
|
|
use App\Helper\Bytedance\ByteDanceAPI;
|
|
use App\Helper\Bytedance\ByteDanceAPI;
|
|
|
|
+use App\Models\Pay;
|
|
|
|
+use Carbon\Carbon;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
|
|
|
@@ -219,52 +221,80 @@ class ByteDance
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * @param array $body
|
|
|
|
- * @param string $secret
|
|
|
|
|
|
+ * @param array $data
|
|
* @return string
|
|
* @return string
|
|
*/
|
|
*/
|
|
- public function getNotifySign(array $body, string $secret)
|
|
|
|
|
|
+ public function getNotifySign(array $data)
|
|
{
|
|
{
|
|
$filtered = [];
|
|
$filtered = [];
|
|
- foreach ($body as $key => $value) {
|
|
|
|
|
|
+ foreach ($data as $key => $value) {
|
|
if (in_array($key, ['msg_signature', 'type'])) {
|
|
if (in_array($key, ['msg_signature', 'type'])) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
+ $value = trim(strval($value));
|
|
|
|
+ $len = strlen($value);
|
|
|
|
+ if ($len > 1 && substr($value, 0, 1) == "\"" && substr($value, $len, $len - 1) == "\"")
|
|
|
|
+ $value = substr($value, 1, $len - 1);
|
|
$filtered[] =
|
|
$filtered[] =
|
|
is_string($value)
|
|
is_string($value)
|
|
? trim($value)
|
|
? trim($value)
|
|
: $value;
|
|
: $value;
|
|
}
|
|
}
|
|
- $filtered[] = trim($secret);
|
|
|
|
|
|
+ $filtered[] = trim($this->token);
|
|
sort($filtered, SORT_STRING);
|
|
sort($filtered, SORT_STRING);
|
|
- $filtered = trim(implode('', $filtered));
|
|
|
|
-
|
|
|
|
- return sha1($filtered);
|
|
|
|
|
|
+ return sha1(trim(implode('', $filtered)));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * @param \Closure $closure
|
|
* @return \Illuminate\Http\JsonResponse
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
+ * @throws \Exception
|
|
*/
|
|
*/
|
|
- public function notify()
|
|
|
|
|
|
+ public function payNotify(\Closure $closure)
|
|
{
|
|
{
|
|
- $notify = \request()->all();
|
|
|
|
|
|
+ call_user_func($closure, $this->getNoticeData());
|
|
|
|
|
|
- \Log::info('抖音支付回调==>'.json_encode($notify,JSON_UNESCAPED_SLASHES));
|
|
|
|
- if ($notify['msg_signature'] !== $this->getNotifySign($notify, $this->appId)) {
|
|
|
|
|
|
+ return response()->json($data);
|
|
|
|
+
|
|
|
|
+ if ($notify['msg_signature'] !== $this->getNotifySign($notify)) {
|
|
\Log::error('回调验证错误');
|
|
\Log::error('回调验证错误');
|
|
|
|
+ $data = [
|
|
|
|
+ 'err_no' => 1,
|
|
|
|
+ 'err_tips' => 'fail'
|
|
|
|
+ ];
|
|
} else {
|
|
} else {
|
|
- //获取订单信息
|
|
|
|
$order = json_decode($notify['msg'], true);
|
|
$order = json_decode($notify['msg'], true);
|
|
//处理订单
|
|
//处理订单
|
|
- $data = ['order_sn' => $order['cp_orderno']];
|
|
|
|
|
|
+ $payId = $order['cp_orderno'];
|
|
|
|
+
|
|
|
|
+ $pay = Pay::find($payId);
|
|
|
|
+ $pay->pay_type = $order['way'];
|
|
|
|
+ $pay->serial_number = $order['channel_no'];
|
|
|
|
+ $pay->status = $order['status'] == 'SUCCESS';
|
|
|
|
+ $pay->pay_dt = Carbon::now()->toDateString();
|
|
|
|
+ $pay->save();
|
|
|
|
|
|
|
|
|
|
- \Log::info('抖音担保支付效验成功');
|
|
|
|
|
|
+ $data = [
|
|
|
|
+ 'err_no' => 0,
|
|
|
|
+ 'err_tips' => 'success'
|
|
|
|
+ ];
|
|
}
|
|
}
|
|
- $data = [
|
|
|
|
- 'err_no' => 0,
|
|
|
|
- 'err_tips' => 'success'
|
|
|
|
- ];
|
|
|
|
return response()->json($data);
|
|
return response()->json($data);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ private function getNoticeData()
|
|
|
|
+ {
|
|
|
|
+ $notify = \request()->all();
|
|
|
|
+ $notify = '{"msg":"{\"appid\":\"tt5b312d8cc40f46b701\",\"cp_orderno\":\"10022082800824490007\",\"cp_extra\":\"\",\"way\":\"2\",\"channel_no\":\"2022082822001477591433078541\",\"channel_gateway_no\":\"\",\"payment_order_no\":\"PCP2022082822540531221069106962\",\"out_channel_order_no\":\"2022082822001477591433078541\",\"total_amount\":1,\"status\":\"SUCCESS\",\"seller_uid\":\"71227862181355706950\",\"extra\":\"\",\"item_id\":\"\",\"paid_at\":1661698458,\"message\":\"\",\"order_id\":\"7136939355201063205\",\"trade_item_list\":null,\"ec_pay_trade_no\":\"NEP2022082822540409483061846962\"}","msg_signature":"804a60e48936b14a739230cef21fe6204427732e","nonce":"78","timestamp":"1661698459","type":"payment"}';
|
|
|
|
+ //获取订单信息
|
|
|
|
+ $notify = json_decode($notify,true);
|
|
|
|
+ \Log::info('抖音支付回调==>'.json_encode($notify,JSON_UNESCAPED_SLASHES));
|
|
|
|
+
|
|
|
|
+ if($notify['msg_signature'] !== $this->getNotifySign($notify)){
|
|
|
|
+ throw new \Exception('签名验证错误');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return json_decode($notify['msg'], true);
|
|
|
|
+ }
|
|
}
|
|
}
|