标签:
公司业务需要对接了一次圆通速递物流查询接口 API 值为yto.Marketing.WaybillTrace
圆通要求用post方式传参数,所以简单写了如下一个例子:
调用:$this->do_post_request("http://58.32.246.70:8088/MarketingInterface/","物流单号");
方法:
public function do_post_request($url,$od_logi_no)
{
$thistime = date(‘Y-m-d H:i:s‘,time()); //当前时间,圆通要求时间格式2014-01-01 24:59:59
$sign= strtoupper(md5("秘钥app_key(app_key值)formatjsonmethodyto.Marketing.WaybillTracetimestamp".$thistime."user_id(用户id)v1.0"));//MD5加密的标识
$data = array (
‘sign‘ => $sign,
‘app_key‘ => ‘app_key值‘,
‘format‘ => ‘json‘,
‘method‘ => ‘yto.Marketing.WaybillTrace‘,
‘timestamp‘ => date(‘Y-m-d H:i:s‘,time()),
‘user_id‘ => ‘用户id‘,
‘v‘ => ‘1.0‘,
‘param‘ => ‘[{"Number":"物流单号"}]‘,
);
$data = http_build_query($data); //生成 URL-encode 之后的请求字符串
$opts = array ( ‘http‘ => array ( ‘method‘ => ‘POST‘, ‘header‘=> ‘Content-type:application/x-www-form-urlencodedrn‘ . ‘Content-Length:‘ . strlen($data) .‘rn‘, ‘content‘ => $data) );
$context = stream_context_create($opts);
$html = file_get_contents($url, false, $context); //获取接口请求的json数值
return $html;
}
圆通速递物流接口yto.Marketing.WaybillTrace查询
标签:
原文地址:http://blog.csdn.net/wangdaxu332/article/details/42873723