API获取天气预报,以及使用飞信API,给好友发送短信
2012-12-10 17:44
661 查看
<?php ########## # jiam 2012/12/5 # 1113160783@qq.com #自动发送飞信 #中间涉及到飞信接口 #天气预报API #以及城市代码 ########## #101180101是郑州城市代码 #101180301是新乡城市代码 $url='http://m.weather.com.cn/data/101180101.html'; $xinxiang='http://m.weather.com.cn/data/101180301.html'; $w=curl($url); $weather=json_decode($w); $weatherinfo=object_to_array($weather); $info=$weatherinfo['weatherinfo']; $str=$info['date_y'].','.$info['week'].'。'.$info['city'].'今天气温:'.$info['temp1'].',天气:'.$info['weather1'].'有'.$info['wind1'].',风力:'.$info['fx1'].',穿衣建议:'.$info['index_d'].$info['index48_d']; $feixin='http://wjima.a173.cnaaa4.com/feixin/str.php'; $postArray['userName']='手机号';//飞信账号 $postArray['password']='密码';//飞信密码 $postArray['content']=$str;//发送内容 $postArray['other']='接收方手机号';//接收方手机号,无此参数,默认给自己发送 $send=curl($feixin,$postArray); print_r($send);die(); function curl($url, $postFields = null) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FAILONERROR, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //https 请求 if(strlen($url) > 5 && strtolower(substr($url,0,5)) == "https" ) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } if (is_array($postFields) && 0 < count($postFields)) { $postBodyString = ""; $postMultipart = false; foreach ($postFields as $k => $v) { if("@" != substr($v, 0, 1))//判断是不是文件上传 { $postBodyString .= "$k=" . urlencode($v) . "&"; } else//文件上传用multipart/form-data,否则用www-form-urlencoded { $postMultipart = true; } } unset($k, $v); curl_setopt($ch, CURLOPT_POST, true); if ($postMultipart) { curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields); } else { curl_setopt($ch, CURLOPT_POSTFIELDS, substr($postBodyString,0,-1)); } } $reponse = curl_exec($ch); if (curl_errno($ch)) { throw new Exception(curl_error($ch),0); } else { $httpStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); if (200 !== $httpStatusCode) { throw new Exception($reponse,$httpStatusCode); } } curl_close($ch); return $reponse; } function object_to_array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; foreach ($_arr as $key => $val) { $val = (is_array($val) || is_object($val)) ? object_to_array($val) : $val; $arr[$key] = $val; } return $arr; } ?>
API获取天气预报,以及使用飞信API,给好友发送短信
加上计划任务,就可以持续每天自动发送天气预报给自己和亲人啦。。。
相关文章推荐
- PHP API获取天气预报,以及使用飞信API,给好友发送短信
- PHP API获取天气预报,以及使用飞信API,给好友发
- 使用Google Weather API获取天气预报,中文支持
- 使用PhP免费发送定时短信(用于天气预报、定时提醒、短信祝福等等)
- 使用飞信API 发送 短信
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- mark-使用volley以及百度定位获取天气
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供) .
- 飞信发送免费短信的api
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- 开源免费的天气预报接口API以及全国所有地区代码(国家气象局提供)
- linux 下使用短信 api 给自己发送手机短信
- 免费天气API,全国天气 JSON API接口,可以获取五天的天气预报
- 开源免费天气预报接口API以及全国所有地区代码!!
- 使用Google Weather API查询天气预报
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)
- 使用ASP发送飞信的免费短信
- 天气预报 api 小批量使用或者研究
- Ajax 通过城市名获取数据(全国天气预报API)
- 开源免费天气预报接口API以及全国所有地区代码!!(国家气象局提供)