快宝地址清洗,纠正错误地址、识别不完整地址、地址补全,并输出结构化地址数据的通用解决方案。广泛应用于快递行业,电商行业,ERP应用等。
快宝开放平台-地址清洗对接API:http://open.kuaidihelp.com/api/1019
一、对接前准备
注册快宝开放平台,获得开发者账号,查看如何注册。
二、对接联调
快宝开放平台支持多种语言的对接,可以到他们的官网去查看详情。
1.接口描述
接口支持的消息接收方式:HTTP POST
正式API地址:https://kop.kuaidihelp.com/api
返回结果,支持JSON格式。
2.代码示例
请求参数、响应参数具体详情可到官网查看,同时也支持很多种编程语言(Java,C#,Python,Curl,Node.js),下面是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"=>'curl -X POST 'https://kop.kuaidihelp.com/api' \ 12 -H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \ 13 -d 'app_id=123567890' \ 14 -d 'method=cloud.address.cleanse' \ 15 -d 'sign=a528b438fb781cf7b23602edca6cbee5' \ 16 -d 'ts=1519873995' \ 17 -d 'data={ 18 "multimode":true, 19 "address":"山东省烟台市烟台市峰哥;上海-上海-长宁;山东-东营-东营区;湖北-恩施土家族苗族自治州-恩施;新疆-和田-和田" 20 }'' 21 ]; 22 $bodys = http_build_query($bodys); 23 $url = $host; 24 $curl = curl_init(); 25 curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method); 26 curl_setopt($curl, CURLOPT_URL, $url); 27 curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 28 curl_setopt($curl, CURLOPT_FAILONERROR, false); 29 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); 30 curl_setopt($curl, CURLOPT_HEADER, true); 31 if (1 == strpos("$".$host, "https://")) 32 { 33 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); 34 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); 35 } 36 curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys); 37 var_dump(curl_exec($curl));
JSON格式的返回结果,如下:
1 { 2 "code":int0 3 "msg":string"success" 4 "uid":string"a6934adee62d8ba3430d4ac678dd5f46c7a79d6e" 5 "data":[ 6 0:{ 7 "province":string"山东省" 8 "province_code":string"370000" 9 "city":string"烟台市" 10 "city_code":string"370600" 11 "district":string"" 12 "district_code":string"" 13 "address":string"烟台市峰哥" 14 "res":int0 15 } 16 1:{ 17 "province":string"上海市" 18 "province_code":string"310000" 19 "city":string"上海市" 20 "city_code":string"310000" 21 "district":string"长宁区" 22 "district_code":string"310105" 23 "address":string"" 24 "res":int0 25 } 26 2:{ 27 "province":string"山东省" 28 "province_code":string"370000" 29 "city":string"东营市" 30 "city_code":string"370500" 31 "district":string"东营区" 32 "district_code":string"370502" 33 "address":string"东营区" 34 "res":int0 35 } 36 3:{ 37 "province":string"湖北省" 38 "province_code":string"420000" 39 "city":string"恩施土家族苗族自治州" 40 "city_code":string"422800" 41 "district":string"恩施市" 42 "district_code":string"422801" 43 "address":string"" 44 "res":int0 45 } 46 4:{ 47 "province":string"新疆维吾尔自治区" 48 "province_code":string"650000" 49 "city":string"和田地区" 50 "city_code":string"653200" 51 "district":string"和田市" 52 "district_code":string"653201" 53 "address":string"" 54 "res":int0 55 } 56 ] 57 }