直接上代码
createOrder($outOrderNo, $totalAmount, $subject, $body, $validTimestamp, $notifyUrl);
dd($response);
}
/**
* @param Request $request
* @return \think\response\Json
*/
public function notify(Request $request): \think\response\Json
{
$notify = $request->param();
if ($notify['msg_signature'] !== $this->signature($notify, $this->token)) {
Log::record('回调验证错误');
} else {
//获取订单信息
$order = json_decode($notify['msg'], true);
//处理订单
}
$data = ['err_no' => '0', 'err_tips' => 'success'];
return json($data);
}
/**
* @param $outOrderNo
* @param $totalAmount
* @param $subject
* @param $body
* @param $validTimestamp
* @param $notifyUrl
* @return array|string
*/
private function CreateOrder($outOrderNo, $totalAmount, $subject, $body, $validTimestamp, $notifyUrl)
{
$params = [
'app_id' => $this->appId,
'out_order_no' => $outOrderNo,
'total_amount' => $totalAmount,
'subject' => $subject,
'body' => $body,
'valid_time' => $validTimestamp,
'notify_url' => $notifyUrl,
//'cp_extra' => $cpExtra,
//'thirdparty_id' => $thirdPartyId,
//'disable_msg' => $disableMsg,
//'msg_page' => $msgPage,
//'store_uid' => $storeUid
];
$params = array_filter($params);
$params['sign'] = $this->signature($params, $this->salt);
//var_dump($params);die;
return $this->post(
'https://developer.toutiao.com/api/apps/ecpay/v1/create_order',
$params
);
}
/**
* payment api signature
* @param array $body
* @param string $secret
* @return string
*/
public static function signature(array $body, string $secret): string
{
$filtered = [];
foreach ($body as $key => $value) {
if (in_array($key, ['sign', 'app_id', 'thirdparty_id'])) {
continue;
}
$filtered[] =
is_string($value)
? trim($value)
: $value;
}
$filtered[] = trim($secret);
sort($filtered, SORT_STRING);
return md5(trim(implode('&', $filtered)));
}
/**
* post request
* @param string $uri
* @param array $params
* @param array $headers
* @return string
*/
private function post(string $uri, array $params = [], array $headers = []): array
{
$headers[] = 'Content-type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$output = curl_exec($ch);
curl_close($ch);
return json_decode($output, true);
}
}
index方法成功返回
下方示例
{
"order_id": "6819903302604491021",
"order_token": "CgsIARCABRgBIAQoARJOCkx+WgXqCUIwTel2V3siEGZ0++poigIM+SMMxtMx798Vj0ZYzoTYBqeNslodUC9X5KAOHkR1YbSBz6I6pXATh5faIGy7R72A9vwm0OczGgA="
}
前端调起tt.pay拉起字节收银台,就行
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。