德邦快递的接入,关键也是组合数据,提交并处理响应数据,流程和顺丰差不多,工具类比较简单,官方SDK指给出了JAVA的demo,对于PHP来说的话就有点难度了,博主研究这个代码也是研究了半个小时之久的,最后终于调通了,也算是有很大的收获了!
header("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
$uri="http://dpsanbox.deppon.com/sandbox-web/standard-order/queryPriceTime.action";
$data["logisticCompanyID"]="DEPPON";
$data["originalsStreet"]="河北省-石家庄市-桥西区";
$data["originalsaddress"]="河北省-衡水市-武强县";
$data["sendDateTime"]=date("Y-m-d H:i:s");
$data["totalVolume"]="0.001";
$data["totalWeight"]="2";
$param=json_encode($data);
$dd["params"]=$param;
$dd["timestamp"]=getMillisecond();//**官方的时间戳是13位的而php一般都是11位的所以需要进行处理一下**
$dd["digest"]=base64_encode(md5($param.'APPKEY'.$dd['timestamp']));
$dd["companyCode"]="对接的code值";
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $uri );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, http_build_query($dd) );
$return = curl_exec ( $ch );
curl_close ( $ch );
echo $return;
/*
*php生成13位的时间戳
*/
function getMillisecond() {
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f',(floatval($t1)+floatval($t2))*1000);
}
网友评论