public function dy_pay($data){ $url = 'https://developer.toutiao.com/api/apps/ecpay/v1/create_order'; $postdata['app_id'] = '您的appid'; $postdata['out_order_no'] = $data['order_num'];//订单号 $postdata['total_amount'] = $data['all_price'];//支付金额 $postdata['subject'] = '中文'; $postdata['body'] = $data['body'];//备注 $postdata['valid_time'] = 86400;//订单有效时间 $postdata['cp_extra'] = urlencode(json_encode(['aaa'=>234,'bbb'=>'aaa'])); $postdata['notify_url'] = '回调地址; $postdata['thirdparty_id'] = ''; $postdata['disable_msg'] = 0; $postdata['msg_page'] = 'asger'; $postdata['store_uid'] = '1'; $postdata['sign'] = $this->sign($postdata);//获取签名 $res = $this->json_post($url, $postdata); print_r($res);} 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));} function json_post($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 'data is null'; } if (is_array($data)) { $data = json_encode($data,320); } 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; ', '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;}
|