http://baofeng.laphp
//md5簽名方式--非簡單簽名
<?php
header("Content-Type:text/html;charset=UTF-8");
date_default_timezone_set("PRC");
$showapi_appid = 'xxxxxx'; //替換此值,在官網的"個人應用"中找到相關值
$showapi_secret = 'xxxxxxxxx'; //替換此值,在官網的"個人應用"中找到相關值
$paramArr = array(
'showapi_appid'=> $showapi_appid,
'url'=> "http://www.baidu.com"
//添加其餘參數
);
//建立參數(包括簽名的處理)
function createParam ($paramArr,$showapi_secret) {
$paraStr = "";
$signStr = "";
ksort($paramArr);
foreach ($paramArr as $key => $val) {
if ($key != '' && $val != '') {
$signStr .= $key.$val;
$paraStr .= $key.'='.urlencode($val).'&';
}
}
$signStr .= $showapi_secret;//排好序的參數加上secret,進行md5
$sign = strtolower(md5($signStr));
$paraStr .= 'showapi_sign='.$sign;//將md5後的值做爲參數,便於服務器的效驗
echo "排好序的參數:".$signStr."\r\n";
return $paraStr;
}
$param = createParam($paramArr,$showapi_secret);
$url = 'http://route.showapi.com/1728-1?'.$param;
echo "請求的url:".$url."\r\n";
$result = file_get_contents($url);
echo "返回的json數據:\r\n";
print $result.'\r\n';
$result = json_decode($result);
echo "\r\n取出showapi_res_code的值:\r\n";
print_r($result->showapi_res_code);
echo "\r\n";
?>