标签:uniapp ch res value thinkphp curl data order 头条
后端
后端php,按官方来处理就行
/**
* @name: 头条小程序 支付
* @param {*}
* @return {*}
*/
public function pay_order_toutiao(Order $Order)
{
$param = $this->request->param();
if (empty($param['order_id'])) {
$this->error('订单不存在');
}
$order_info = $Order->where('id', $param['order_id'])->find();
$url = 'https://developer.toutiao.com/api/apps/ecpay/v1/create_order';
$http = is_https() ? 'https' : 'http';
$pay_data = [
"app_id" => env('toutiao.appid', ''),
"out_order_no" => $order_info['order_sn'], // 自己的订单号
"total_amount" => $order_info['money'] * 100,
"subject" => "这里是名称",
"body" => ''一些内容,
"valid_time" => 1800, // 过期时间
"cp_extra" => "abcdefgh", // 这里是自定义字段
"notify_url" => $http . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER["SERVER_PORT"] . "/api/test/Bytedance/notify", // 回调地址
"disable_msg" => 0,
"msg_page" => "pages/index/index"
];
$sign_res = $this->sign($pay_data);
$pay_data['sign'] = $sign_res; // 注意些这里,需要填写自己的SALT
$res = $this->curl_post($url, json_encode($pay_data));
$res_info = [];
if ($res['err_no'] == 0) {
$res_info['order_id'] = $res['data']['order_id'];
$res_info['order_token'] = $res['data']['order_token'];
$this->success('下单成功', $res_info);
} else {
$this->error($res['err_no'], $res['data']);
}
}
function sign($map)
{
$rList = array();
foreach ($map 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, "这里填写自己的SALT");
sort($rList, 2);
return md5(implode('&', $rList));
}
public function curl_post($url, $data = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
));
// POST数据
curl_setopt($ch, CURLOPT_POST, 1);
// 把post的变量加上
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
前端
标签:uniapp,ch,res,value,thinkphp,curl,data,order,头条
来源: https://www.cnblogs.com/twoknives/p/15488080.html
本站声明:
1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。