采集新闻
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>\r\n";<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>\r\n";<br>
$result = file_get_contents($url);<br>
echo "返回的json数据:<br>\r\n";<br>
print $result.'<br>\r\n';<br>
$result = json_decode($result);<br>
echo "<br>\r\n取出showapi_res_code的值:<br>\r\n";<br>
print_r($result->showapi_res_code);<br>
echo "<br>\r\n";<br>
?>