快递物流评价接口API文档附demo.doc
-快递物流评价接口API文档附demo物流评价接口是面向电商、ERP系统商、仓储系统商等企业,提供评价物流,网点,快递员的渠道,并批量获取平均分的功能,平均分值可应用于快递公司推荐排序,综合选择,展示商家实力等场景。商家的评价分值将由接口汇总计算,统一传递到物流公司,指导物流公司提升效劳质量。该接口由快递鸟提供,分为评价接口和评分获取接口。一、物流评价投诉接口1.接口描述/说明通过此接口可对快递公司、网点、快递员进展评价或投诉。1仅支持Json格式。2请求指令1011。3每次请求不超过100条明细。4测试接口地址:testapi.kdniao.cc:8081/api/dist5联调通过后请更换为正式地址:6需在快递鸟申请接口秘钥2.请求系统级参数说明参数名称类型说明必须要求RequestDataString请求容需进展URL(utf-8)编码。请求容JSON格式,须和DataType一致。REBusinessIDString电商ID。RRequestTypeString请求指令类型:1011RDataSignString数据容签名RDataTypeString请求、返回数据类型:2-json;O3.应用级参数参数名称类型说明必须要求MemberIDString会员IDOEvaluateTypeInt评价类型(1-物流评价2-物流投诉)RE*pressNodeInt物流环节(1-揽件 2-派件)ROrderCodeString订单编号OLogisticCodeString物流单号RTargetE*pCodeString快递公司编码ROutletCodeString网点编码OCourierCodeString快递员编码OScoreE*pValueDouble快递公司分值COutletValueDouble快递网点分值CCourierValueDouble快递员分值CEvaluationTagString评价标签OContentsString容C备注:R-必填Required,O-可选Optional,C-报文中该参数在一定条件下可选Conditional4.返回参数定义参数名称类型说明必须要求EBusinessIDString电商用户IDRSuccessBool成功与否:true,falseRReasonString失败原因O5.JSON请求示请求例如 JSON "MemberID":"", "EvaluateType":1, "E*pressNode":1, "OrderCode":"", "LogisticCode":"12345678", "Target": "E*pCode":"YTO", "OutletCode":"0453", "CourierCode":"2001158001" , "Score": "E*pValue":5, "OutletValue":4.5, "CourierValue":4 , "EvaluationTag":"速度快,效劳好", "Content":"" 6.JSON返回例如返回例如 JSON "EBusinessID": "1261737", "Success": true 二、物流平均分获取接口1.接口描述/说明通过此接口可以获取各个快递公司的评价平均分。1仅支持Json格式。2请求指令1012。3测试接口地址:testapi.kdniao.cc:8081/api/dist4联调通过后请更换为正式地址:5需申请秘钥2.请求系统级参数说明参数名称类型说明必须要求RequestDataString请求容,JSON,须和DataType一致。REBusinessIDString电商ID。RRequestTypeString请求指令类型:1012RDataSignString数据容签名RDataTypeString请求、返回数据类型:2-json;R3.应用级参数参数名称类型说明必须要求MemberIDString会员IDOLogisticsTypeInt获取类型1-物流公司2-快递网点3-快递员RE*pCodeInt快递公司编码OOrderCodeString网点编码O备注:R-必填Required,O-可选Optional,C-报文中该参数在一定条件下可选Conditional4.返回参数定义参数名称类型说明必须要求EBusinessIDString电商用户IDRSuccessBool成功与否:true,falseRScoresE*pCodeString快递公司编码OE*pValueDouble快递公司分值OReasonString失败原因O5.JSON请求例如请求例如 JSON "MemberID":"123456", "LogisticsType":1, "E*pCode":"", "OutletCode":"" 6.JSON返回例如返回例如 JSON "EBusinessID": "1261737", "Success": true, "Scores": "E*pCode":"EMS", "E*pValue":"4.3" , "E*pCode":"YTO", "E*pValue":"4.5" , "E*pCode":"SF", "E*pValue":"4.4" 三、接口代码1.PHP语言<"php/电商IDdefined('EBusinessID') or define('EBusinessID', '请申请');/电商加密私钥,注意保管,不要泄漏defined('AppKey') or define('AppKey', '请申请');/请求url/测试地址defined('ReqURL') or define('ReqURL', 'testapi.kdniao.cc:8081/Ebusiness/EbusinessOrderHandle.asp*');/正式地址/defined('ReqURL') or define('ReqURL', 'api.kdniao.cc/Ebusiness/EbusinessOrderHandle.asp*'); /调用获取/-$logisticResult = getE*pEvaluateByJson();echo $logisticResult;/-/* * Json方式物流评价投诉 */function getE*pEvaluateByJson()$requestData="'MemberID': ''," + "'EvaluateType':1," + "'E*pressNode':1," + "'OrderCode':''," + "'LogisticCode':'12345678'," + "'Target':" + "" + "'E*pCode':'YTO','OutletCode':'0453','CourierCode':'8'," + "'Score':" + "" + "'E*pValue':5,'OutletValue':4.5,'CourierValue':4," + "'EvaluationTag':'速度快,效劳好'," + "'Content':''"$datas = array( 'EBusinessID' => EBusinessID, 'RequestType' => '1011', 'RequestData' => urlencode($requestData) , 'DataType' => '2', ); $datas'DataSign' = encrypt($requestData, AppKey);$result=sendPost(ReqURL, $datas);/根据公司业务处理返回的信息.return $result;/* * Json方式物流平均分获取 */function getE*pAverageByJson()$requestData='"MemberID":"123456","LogisticsType":1,"E*pCode":"","OutletCode":""'$datas = array( 'EBusinessID' => EBusinessID, 'RequestType' => '1012', 'RequestData' => urlencode($requestData) , 'DataType' => '2', ); $datas'DataSign' = encrypt($requestData, AppKey);$result=sendPost(ReqURL, $datas);/根据公司业务处理返回的信息.return $result;/* * post提交数据 * param string $url 请求Url * param array $datas 提交的数据 * return url响应返回的html */function sendPost($url, $datas) $temps = array(); foreach ($datas as $key => $value) $temps = sprintf('%s=%s', $key, $value); $post_data = implode('&', $temps); $url_info = parse_url($url);if(empty($url_info'port')$url_info'port'=80; $ header = "POST " . $url_info'path' . " /1.0rn" $ header.= "Host:" . $url_info'host' . "rn" $ header.= "Content-Type:application/*-form-urlencodedrn" $ header.= "Content-Length:" . strlen($post_data) . "rn" $ header.= "Connection:closernrn" $ header.= $post_data; $fd = fsockopen($url_info'host', $url_info'port'); fwrite($fd, $ header); $gets = ""$headerFlag = true;while (!feof($fd) if ($header = fgets($fd) && ($header = "rn" | $header = "n") break; while (!feof($fd) $gets.= fread($fd, 128); fclose($fd); return $gets;/* * 电商Sign签名生成 * param data 容 * param appkey Appkey * return DataSign签名 */function encrypt($data, $appkey) return urlencode(base64_encode(md5($data.$appkey);">2.NET语言using System;using System.Collections.Generic;using System.Linq;using System.Te*t;using System.Web;using System.Net;using System.IO;namespace KdGoldAPI public class KdApiSearchDemo /电商ID private string EBusinessID = "请申请" /电商加密私钥,注意保管,不要泄漏 private string AppKey = "请申请" /请求url /测试环境 private string ReqURL = "testapi.kdniao.cc:8081/Ebusiness/EbusinessOrderHandle.asp*" /正式环境 /private string ReqURL = "api.kdniao.cc/Ebusiness/EbusinessOrderHandle.asp*" / <summary> / Json方式物流评价投诉 / </summary> / <returns></returns> public string getE*pEvaluateByJson() string requestData = "'MemberID': ''," + "'EvaluateType':1," + "'E*pressNode':1," + "'OrderCode':''," + "'LogisticCode':'12345678'," + "'Target':" + "" + "'E*pCode':'YTO','OutletCode':'0453','CourierCode':'8'," + "'Score':" + "" + "'E*pValue':5,'OutletValue':4.5,'CourierValue':4," + "'EvaluationTag':'速度快,效劳好'," + "'Content':''" Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("RequestData", Utility.UrlEncode(requestData, Encoding.UTF8); param.Add("EBusinessID", EBusinessID); param.Add("RequestType", "1011"); string dataSign = encrypt(requestData, AppKey, "UTF-8"); param.Add("DataSign", Utility.UrlEncode(dataSign, Encoding.UTF8); param.Add("DataType", "2"); string result = sendPost(ReqURL, param); /根据公司业务处理返回的信息. return result; / <summary> / Json方式物流平均分获取 / </summary> / <returns></returns> public string getE*pAverageByJson() string requestData = '"MemberID":"123456","LogisticsType":1,"E*pCode":"","OutletCode":""' Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("RequestData", Utility.UrlEncode(requestData, Encoding.UTF8); param.Add("EBusinessID", EBusinessID); param.Add("RequestType", "1012"); string dataSign = encrypt(requestData, AppKey, "UTF-8"); param.Add("DataSign", Utility.UrlEncode(dataSign, Encoding.UTF8); param.Add("DataType", "2"); string result = sendPost(ReqURL, param); /根据公司业务处理返回的信息. return result; / <summary> / Post方式提交数据,返回网页的源代码 / </summary> / <param name="url">发送请求的 URL</param> / <param name="param">请求的参数集合</param> / <returns>远程资源的响应结果</returns> private string sendPost(string url, Dictionary<string, string> param) string result = "" StringBuilder postData = new StringBuilder(); if (param != null && param.Count > 0) foreach (var p in param) if (postData.Length > 0) postData.Append("&"); postData.Append(p.Key); postData.Append("="); postData.Append(p.Value); byte byteData = Encoding.GetEncoding("UTF-8").GetBytes(postData.ToString(); try WebRequest request = ( WebRequest)WebRequest.Create(url); request.ContentType = "application/*-form-urlencoded" request.Referer = url; request.Accept = "*/*" request.Timeout = 30 * 1000; request.UserAgent = "Mozilla/4.0 (patible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" request.Method = "POST" request.ContentLength = byteData.Length; Stream stream = request.GetRequestStream(); stream.Write(byteData, 0, byteData.Length); stream.Flush(); stream.Close(); WebResponse response = ( WebResponse)request.GetResponse(); Stream backStream = response.GetResponseStream(); StreamReader sr = new StreamReader(backStream, Encoding.GetEncoding("UTF-8"); result = sr.ReadToEnd(); sr.Close(); backStream.Close(); response.Close(); request.Abort(); catch (E*ception e*) result = e*.Message; return result; /<summary> /电商Sign签名 /</summary> /<param name="content">容</param> /<param name="keyValue">Appkey</param> /<param name="charset">URL编码 </param> /<returns>DataSign签名</returns> private string encrypt(String content, String keyValue, String charset) if (keyValue != null) return base64(MD5(content + keyValue, charset), charset); return base64(MD5(content, charset), charset); /<summary> / 字符串MD5加密 /</summary> /<param name="str">要加密的字符串</param> /<param name="charset">编码方式</param> /<returns>密文</returns> private string MD5(string str, string charset) byte buffer = System.Te*t.Encoding.GetEncoding(charset).GetBytes(str); /用charset编码将字符串转换成字节数组buffer try System.Security.Cryptography.MD5CryptoServiceProvider check; check = new System.Security.Cryptography.MD5CryptoServiceProvider(); /初始化一个MD5密码的实例 byte somme = check.puteHash(buffer); /计算该字节数组哈希表 string ret = "" foreach (byte a in somme) if (a < 16) ret += "0" + a.ToString("*"); else ret += a.ToString("*"); return ret.ToLower(); /转换成大写 catch throw; / <summary> / base64编码 / </summary> / <param name="str">容</param> / <param name="charset">编码方式</param> / <returns></returns> private string base64(String str, String charset) return Convert.ToBase64String(System.Te*t.Encoding.GetEncoding(charset).GetBytes(str); /将字节数组转换成字符串 . z.