收集新聞
https://www.showapi.com/api/lookPoint/1071//md5簽名方式--非簡單簽章<br>
<?php <br />
header("Content-Type:text/html;charset=UTF-8");<br>
date_default_timezone_set("PRC");<br>
$showapi_appid = 'xxxxxx'; //替換此值,在官網的"我的應用"中找到相關值<br>
$showapi_secret = 'xxxxxxxxx'; //替換此值,在官網的"我的應用"中找到相關值 <br>
$paramArr = array(<br>
'showapi_appid'=> $showapi_appid<br>
//新增其他參數<br>
);<br>
<br>
//建立參數(包含簽章的處理)<br>
function createParam ($paramArr,$showapi_secret) {<br>
$paraStr = "";<br>
$signStr = "";<br>
ksort($paramArr);<br>
foreach ($paramArr as $key => $val) {<br>
if ($key != '' && $val != '') {<br>
$signStr .= $key.$val;<br>
$paraStr .= $key.'='.urlencode($val).'&';<br>
}<br>
}<br>
$signStr .= $showapi_secret;//排好序的參數加上secret,進行md5<br>
$sign = strtolower(md5($signStr));<br>
$paraStr .= 'showapi_sign='.$sign;//將md5後的數值作為參數,方便伺服器的效驗<br>
echo "排好序的參數:".$signStr."<br>rn";<br>
return $paraStr;<br>
}<br>
<br>
$param = createParam($paramArr,$showapi_secret);<br>
$url = 'http://route.showapi.com/1071-1?'.$param; <br>
echo "請求的url:".$url."<br>rn";<br>
$result = file_get_contents($url);<br>
echo "傳回的json資料:<br>rn";<br>
print $result.'<br>rn';<br>
$result = json_decode($result);<br>
echo "<br>rn取出showapi_res_code的值:<br>rn";<br>
print_r($result->showapi_res_code);<br>
echo "<br>rn";<br>
?>