$url = 'http://japi.zto.cn/traceInterfaceNewTraces';
$company_id = 'your_companyid';
$key = 'your_key';
// 注意这里的 $data 里必须都是字符串,如果有array的话要先json_encode
$data = array('data' => '["728350000001"]', 'company_id' => $company_id,
              'msg_type'=>'NEW_TRACES');
$str_to_digest = "";
foreach ($data as $k=>$v) {
  $str_to_digest =$str_to_digest.$k."=".$v."&";
}
$str_to_digest = substr($str_to_digest, 0, -1).$key;
$data_digest = base64_encode(md5($str_to_digest,TRUE));

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded; charset=utf-8\r\n".
        "x-companyid: ".$company_id."\r\n".
        "x-datadigest: ".$data_digest."\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);

$context  = stream_context_create($options);
// file_get_contents性能不好,请自行优化
$result = file_get_contents($url, false, $context);
echo $result;

results matching ""

    No results matching ""