1.闪送接口文档 接入引导-对接流程 - 4:API索引
2.实际请求示例
/** * 订单计费 */ public function pre() { $order_id = input('id'); $base = [ 'clientId' => $this->client_id, 'shopId' => $this->shop_id, 'timestamp' => $this->getMsecTime(), ]; //组合闪送数据 $data = [ 'cityName' => '太原市',//城市名称(查询城市开通接口,存在后写死) 'appointType' => 0,//预约类型,0-立即单 'sender' => [ 'fromAddress' => '发送地址', 'fromSenderName' => '发送人', 'fromMobile' => '18611111111',//电话 'fromLatitude' => '37.8',//纬度 百度坐标系 'fromLongitude' => '112.5',//经度 ], 'receiverList' => [ 'orderNo' => $order_id,//本地订单号 'toAddress' => '收货地址', 'toLatitude' => '37.8', 'toLongitude' => '112.5', 'toReceiverName' => '收货人', 'toMobile' => '18622222222',//收货电话 'goodType' => '6',//6 = 餐饮,具体枚举查看文档 'weight' => '1',//重量,单位kg,向上取整 ], ];
//签名1-参数排除空
//签名2-排序 ksort($data); $base['data'] = json_encode($data, JSON_UNESCAPED_SLASHES);
//签名3,4-参数按规则顺序拼接,返回大写md5 $base['sign'] = $this->SignWithMd5($base); $url = '/openapi/merchants/v5/orderCalculate'; //成功请求["status" => 200,"msg" => null,"data" => array:14 [▶]] $res = $this->curl_post($url, $base); if (!isset($res['status'])) { return $this->response($this->error('', '请求错误,请联系管理员')); } if ($res['status'] != 200) { return $this->response($this->error('', $res['msg'])); } cache($order_id . 'ss_pre', $res['data'], 1500); } function signWithMd5($base) { $data_str = ''; if (isset($base['data']) && !empty($base['data'])) { $data_str = 'data' . $base['data']; } $str = $this->client_secret . 'clientId' . $this->client_id . $data_str . 'shopId' . $this->shop_id . 'timestamp' . $base['timestamp']; return strtoupper(md5($str)); } function getMsecTime() { // 获取当前时间的毫秒数 $milliseconds = round(microtime(true) * 1000); // 补足到十三位 return str_pad($milliseconds, 13, '0', STR_PAD_LEFT); } function curl_post($url, $post) { $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => $this->url . $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => http_build_query($post), )); $response = curl_exec($curl); curl_close($curl); return json_decode($response, true); }
标签:对接,id,tp5,base,str,curl,data,闪送,CURLOPT From: https://www.cnblogs.com/a540268158/p/18680849