// 支付
public function ttpay($data)
{
$url = 'https://developer.toutiao.com/api/apps/ecpay/v1/create_order';
$params['app_id'] = '你的小程序appid';
$params['out_order_no'] = (string)$data['no'];
$params['total_amount'] = (int)$data['amount'] * 100;
$params['subject'] = 'subject';
$params['body'] = 'body';
$params['valid_time'] = 3600;
$params['sign'] = $this->ttsign($params);
$http = $this->httpPost($url, $params);
return json_decode($http,true);
}
//curl
public function httpPost($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
if (!$data) return false;
if (is_array($data)) {
$data = json_encode($data);
}
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length:' . strlen($data),
'Cache-Control: no-cache',
'Pragma: no-cache'
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
// 签名
public function ttsign($params)
{
$rList = array();
foreach ($params as $k => $v) {
if ($k == "other_settle_params" || $k == "app_id" || $k == "sign" || $k == "thirdparty_id")
continue;
$value = trim(strval($v));
$len = strlen($value);
if ($len > 1 && substr($value, 0, 1) == "\"" && substr($value, $len, $len - 1) == "\"")
$value = substr($value, 1, $len - 1);
$value = trim($value);
if ($value == "" || $value == "null")
continue;
array_push($rList, $value);
}
array_push($rList, "fregSFjXnAaSZmc02UGxLJWeDv9AX02F7YFxpji9");
sort($rList, 2);
return md5(implode('&', $rList));
}
//ps: 请求 ttpay() 方法, 抖音文档真垃圾,返回错误参数不明确,各位踩坑的码友注意传递参数类型
//前端代码
tt.pay({
orderInfo: {
order_id: "6819903302604491021",
order_token:
"CgsIARCABRgBIAQoARJOCkx+WgXqCUIwTel2V3siEGZ0++poigIM+SMMxtMx798Vj0ZYzoTYBqeNslodUC9X5KAOHkR1YbSBz6I6pXATh5faIGy7R72A9vwm0OczGgA=",
},
service: 5,
success(res) {
if (res.code == 0) {
// 支付成功处理逻辑,只有res.code=0时,才表示支付成功
// 但是最终状态要以商户后端结果为准
}
},
fail(res) {
// 调起收银台失败处理逻辑
},
});
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。