直接上代码
<?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 //添加其他参数 ); //创建参数(包括签名的处理) 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/1377-1?'.$param; echo "请求的url:".$url."<br>\r\n"; $result = file_get_contents($url); echo "返回的json数据:<br>\r\n"; print $result.'<br>\r\n'; $result = json_decode($result); echo "<br>\r\n取出showapi_res_code的值:<br>\r\n"; print_r($result->showapi_res_code); echo "<br>\r\n"; ?> { "showapi_res_code": 0, "showapi_res_error": "", "showapi_res_body": { "ret_code": 0, "list": [ { "1920*1080": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_1920*1080.jpg", "720x1280": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_720x1280.jpg", "800x600": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_800x600.jpg", "pic": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_1920x1080.jpg", "640x480": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_640x480.jpg", "240x320": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_240x320.jpg", "country": "法国", "city": "霞慕尼山谷", "content": "在法国的霞慕尼山谷的上空,这种发光的阴霾看起来像仙境幻想,但它确实是怪异天气的产物。当下面的温度比上面的空气温度低的时候,会发生这样的反转,看起来像一片云的海洋。在这个特殊的云层下面是冬季运动爱好者的游乐场。霞慕尼是法国最古老的滑雪胜地之一。", "title": "一只白鹳和幼鸟在阿连特茹西南部和维森蒂娜海岸自然公园内筑巢,葡萄牙 (© Marco Bustos/Solent News/REX/Shutterstock)", "320x240": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_320x240.jpg", "subtitle": "法国,霞慕尼山谷", "1024x768": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_1024x768.jpg", "400x240": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_400x240.jpg", "day": "20170831", "1280x768": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_1280x768.jpg", "480x800": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_480x800.jpg", "800x480": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_800x480.jpg", "1366x768": "http://www.bing.com/az/hprichbg/rb/StorkCliffs_ZH-CN11006532238_1366x768.jpg" }, { "1920*1080": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_1920*1080.jpg", "720x1280": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_720x1280.jpg", "800x600": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_800x600.jpg", "pic": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_1920x1080.jpg", "640x480": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_640x480.jpg", "240x320": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_240x320.jpg", "country": "", "city": "", "content": "这群金色无齿鲹与海洋中最大的鱼——鲸鲨一起在鸟头湾悠闲的遨游。金色无齿鲹经常与温和的巨人鲸鲨一起游泳,它们能清除一些鲸鲨的残羹剩饭,甚至可以保护鲸鲨免受捕食者的伤害。与大多数鲨鱼不同,鲸鲨是一种以浮游生物为食的滤食动物。我们可以在赤道附近的温暖水域里找到它们。", "title": "法国霞慕尼山谷上空的云海 (© Masterfile)", "320x240": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_320x240.jpg", "subtitle": "奇妙的旅程", "1024x768": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_1024x768.jpg", "400x240": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_400x240.jpg", "day": "20170830", "1280x768": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_1280x768.jpg", "480x800": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_480x800.jpg", "800x480": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_800x480.jpg", "1366x768": "http://www.bing.com/az/hprichbg/rb/ChamonixClouds_ZH-CN7700889231_1366x768.jpg" }, { "1920*1080": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_1920*1080.jpg", "720x1280": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_720x1280.jpg", "800x600": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_800x600.jpg", "pic": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_1920x1080.jpg", "640x480": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_640x480.jpg", "240x320": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_240x320.jpg", "country": "", "city": "", "content": "时间的流逝在俄勒冈州中部的彩绘山丘上留下了它的痕迹,这是约翰时代化石床国家纪念碑的一部分。色彩斑斓的灰土讲述了一个大约3000万年前的一个时代的故事,当时该地区是一个富饶的洪水平原,有马、骆驼、甚至犀牛等动物。它们的化石残骸都可以在这里找到,吸引了古生物学家和大量的游客。", "title": "一群金色无齿鲹与一条鲸鲨遨游在鸟头湾中,印度尼西亚 (© Pete Oxford/Minden Pictures)", "320x240": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_320x240.jpg", "subtitle": "彩绘山丘", "1024x768": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_1024x768.jpg", "400x240": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_400x240.jpg", "day": "20170829", "1280x768": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_1280x768.jpg", "480x800": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_480x800.jpg", "800x480": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_800x480.jpg", "1366x768": "http://www.bing.com/az/hprichbg/rb/GoldenTrevally_ZH-CN8976794546_1366x768.jpg" }, { "1920*1080": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_1920*1080.jpg", "720x1280": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_720x1280.jpg", "800x600": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_800x600.jpg", "pic": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_1920x1080.jpg", "640x480": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_640x480.jpg", "240x320": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_240x320.jpg", "country": "英国", "city": "巴特莱克矿场遗址", "content": "巴特莱克矿场位于英格兰西南部,它是英国“锡海岸”的一部分,曾经是一处海底矿井,地下深处有隧道,矿工们在这里可以采集到锡、砷和铜。1895年采矿被中断,但悬崖作为康沃尔郡和西德文郡矿区的一部分被保护了起来,并成为教科文组织公认的世界遗产。", "title": "俄勒冈州内的“彩绘山丘”,美国 (© David Henderson/plainpicture)", "320x240": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_320x240.jpg", "subtitle": "英国,巴特莱克矿场遗址", "1024x768": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_1024x768.jpg", "400x240": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_400x240.jpg", "day": "20170828", "1280x768": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_1280x768.jpg", "480x800": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_480x800.jpg", "800x480": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_800x480.jpg", "1366x768": "http://www.bing.com/az/hprichbg/rb/OregonPainted_ZH-CN8553728911_1366x768.jpg" }, { "1920*1080": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_1920*1080.jpg", "720x1280": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_720x1280.jpg", "800x600": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_800x600.jpg", "pic": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_1920x1080.jpg", "640x480": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_640x480.jpg", "240x320": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_240x320.jpg", "country": "", "city": "", "content": "杉叶藻是一种水生植物,它们生长在广阔的高海拔地域范围内,从北美的湿地到青藏高原的高海拔地区,这种多年生草本植物栖息在浅水和泥中。杉叶藻还有入药的效用,在草药中,杉叶藻有时用来治疗伤口。它们的长相也是超级让人赏心悦目的杉叶形状。", "title": "康沃尔郡内的巴特莱克矿场, 英国 (© Robert Harding/Masterfile)", "320x240": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_320x240.jpg", "subtitle": "杉叶藻", "1024x768": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_1024x768.jpg", "400x240": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_400x240.jpg", "day": "20170827", "1280x768": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_1280x768.jpg", "480x800": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_480x800.jpg", "800x480": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_800x480.jpg", "1366x768": "http://www.bing.com/az/hprichbg/rb/BotallackCornwall_ZH-CN11396172846_1366x768.jpg" } ], "msg": "提建议加群:2702237" } }