基于PHP的对接免费电子面单接口平台的案例-快宝开放平台
一、电子面单对接平台
电子面单对接平台分为两类:
1 .各大快递公司自有的电子面单接口开放平台:对接起来麻烦,需要每个快递公司分别调试接口,费时费力。
2 .第三方快递开放平台:如快宝开放平台(http://open.kuaidihelp.com/home),快宝电子面单接口,一次性对接国内主流快递品牌,接口屏蔽各大快递公司接口的差异性,轻松帮你申请电子面单。
二、开通流程
1 .快递公司电子面单:
a.和多家快递公司申请账号
b.分别进行接口对接
c.电子面单服务用户向快递网点申请开通及确认合作细节
2 .快宝电子面单
a.打开快宝开放平台(http://open.kuaidihelp.com/home),注册,获取到专门的开发者账号及APIkey
b.联系快递品牌网点,并在网点处申请快递大客户账号
c.将您的应用对接快宝开放平台,完成电子面单相关接口的技术联调
三、对接联调
快宝开放平台支持多种语言的对接,可以到他们的官网去查看详情。
1.接口描述
接口支持的消息接收方式:HTTP POST
正式API地址:https://kop.kuaidihelp.com/api
测试API地址:https://kop.kuaidihelp.com/test
返回结果,支持JSON格式。
2.代码示例
请求参数、响应参数具体详情可到官网查看,同时也支持很多种编程语言(Java,C#等),下面是PHP代码请求示例:
1 $host = "https://kop.kuaidihelp.com/api"; 2 $method = "POST"; 3 $headers = array(); 4 //根据API的要求,定义相对应的Content-Type 5 array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8"); 6 $querys = ""; 7 $bodys = [ 8 "app_id"=>'你的app_id', 9 "sign"=>"签名", 10 "ts"=>'时间戳', 11 "data"=>'{ 12 "customer_name":"kuaibao888", 13 "customer_password":"1234567890", 14 "order_id":"KB101100111011232", 15 "trade_name":"智能手机", 16 "custom_value":"预留信息", 17 "shipper_type":"ZTO", 18 "pay_type":"1", 19 "weight":"1.23", 20 "remark":"小心轻放", 21 "sender":{ 22 "company":"南山区深圳软件产业基地", 23 "name":"张飞鸿", 24 "tel":"", 25 "mobile":"18688888888", 26 "post_code":"200083", 27 "province":"广东省", 28 "city":"深圳市", 29 "district":"南山区", 30 "address":"深圳软件产业基地" 31 }, 32 "recipient":{ 33 "company":"宝芝林贸易", 34 "name":"王三姨", 35 "tel":"95127777", 36 "mobile":"13666666666", 37 "post_code":"215000", 38 "province":"江苏省", 39 "city":"苏州市", 40 "district":"沧浪区", 41 "address":"人民路沧浪亭街31号宝芝林贸易有限公司" 42 }, 43 "commodities":[ 44 { 45 "name":"iphone5s", 46 "goods_no":"", 47 "quantity":"", 48 "price":"388188", 49 "weight":"", 50 "description":"", 51 "volume":"" 52 }, 53 { 54 "name":"iphone6s", 55 "goods_no":"12345456", 56 "quantity":"2", 57 "price":"5888.00", 58 "weight":"0.23", 59 "description":"最新款", 60 "volume":"0.23" 61 } 62 ] 63 }' 64 ]; 65 $bodys = http_build_query($bodys); 66 $url = $host; 67 $curl = curl_init(); 68 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 69 curl_setopt($curl, CURLOPT_URL, $url); 70 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 71 curl_setopt($curl, CURLOPT_FAILONERROR, false); 72 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 73 curl_setopt($curl, CURLOPT_HEADER, true); 74 if (1 == strpos("$".$host, "https://")) 75 { 76 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 77 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 78 } 79 curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); 80 var_dump(curl_exec($curl));