获取百世汇通快递单号接口(PHP demo)
msgId是唯一值,一般传时间戳,如果发送同一个msgId,则获取到的面单号为同一个,跟顺丰的区别就是,顺丰如果发送同一个订单号,会返回重复下单,百世的话就是返回同一个面单号
PHP Code复制内容到剪贴板
- /*
- * 根据参数获取快递单号,并输出所有数据
- * 入参(必选):
- sendMan 寄件人姓名
- sendManPhone 寄件人电话
- sendManAddress 寄件人地址
- sendProvince 寄件省
- sendCity 寄件市
- sendCounty 寄件区县
- receiveMan 收件人姓名
- receiveManPhone 收件人电话
- receiveManAddress 收件人地址
- receiveProvince 收件省
- receiveCity 收件市
- receiveCounty 收件区县
- digest 签名
- parternID 商家ID
- parternKey
- * 入参(可选):
- sendPostcode 寄件邮编
- receivePostcode 收件邮编
- txLogisticID 客户订单号
- itemName 品名
- itemWeight 重量
- itemCount 数量
- */
- //==================================================================
- //功能: 获取百世汇通面单号
- //输入参数: 上面注释部分 (必选)
- //==================================================================
- //
- //百世汇通的商家ID和密钥测试帐号
- private $parternID = 'TESTJSON';
- private $parternKey = '12345';
- private $BESTurl = 'http://183.129.172.49/ems/api/process';
- function getBESTExpressNo($post){
- //转换参数形式
- foreach ($post as $kp=>$p) {
- $$kp = $p;
- };
- if($func){
- unset($post['func']);
- }
- if($msgId){
- $msgId = $msgId;
- unset($post['msgId']);
- }
- else{
- $msgId = time();
- }
- $arr=array(
- "deliveryConfirm"=>false,
- "EDIPrintDetailList"=> [$post]
- );
- $bizData = json_encode($arr);
- $digest = $bizData.$this->parternKey;
- $digest = base64_encode(md5($digest,true));
- $res = [
- 'bizData' => $bizData,
- 'digest' => $digest,
- 'msgId' => $msgId,
- 'parternID' => $this->parternID,
- 'serviceType'=> 'BillPrintRequest',
- ];
- // print_r($res);
- $data = $this->post($this->BESTurl,$res);
- if(!$data){
- return Message(400,'error','获取超时,请重试','');
- }
- $res = [
- 'msgId'=> strval($msgId),
- 'BestDetail' => $data
- ];
- return Message(200,'success','',$res);
- }
- // PHP POST请求url
- public static function post($url, $data){//file_get_content
- $postdata = http_build_query(
- $data
- );
- $opts = array('http' =>
- array(
- 'method' => 'POST',
- 'header' => 'Content-type: application/x-www-form-urlencoded',
- 'content' => $postdata
- )
- );
- $context = stream_context_create($opts);
- $result = file_get_contents($url, false, $context);
- return $result;
- }