thinkphpapi

<?php
    header("Content-Type:text/html;charset=UTF-8");
    date_default_timezone_set("PRC");
    $showapi_appid = '4711';  //替换此值,在官网的"我的应用"中找到相关值
    $showapi_secret = '6c942094705c4a469d01114136e608e7';  //替换此值,在官网的"我的应用"中找到相关值
    $paramArr = array(
         'showapi_appid'=> $showapi_appid,
         'areaid'=> "",
         'area'=> "淄博",
         'needMoreDay'=> "",
         'needIndex'=> "",
         'needHourData'=> "",
         'need3HourForcast'=> "",
         'needAlarm'=> ""
         //添加其他参数
    );
     
    //创建参数(包括签名的处理)
    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."<br>\r\n";
         return $paraStr;
    }
     
    $param = createParam($paramArr,$showapi_secret);
    $url = 'http://route.showapi.com/9-2?'.$param; 
    
    $result = file_get_contents($url);
    
  
    $result = json_decode($result);
   
    var_dump($result);
    ?>

 

posted @ 2017-07-12 09:08  繁华似水  阅读(163)  评论(0编辑  收藏  举报