API获取天气预报,以及使用飞信API,给好友发送短信
php代码
<?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; } ?>
登录后复制
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章
刺客信条阴影:贝壳谜语解决方案
3 周前
By DDD
Windows 11 KB5054979中的新功能以及如何解决更新问题
2 周前
By DDD
在哪里可以找到原子中的起重机控制钥匙卡
3 周前
By DDD
<🎜>:死铁路 - 如何完成所有挑战
4 周前
By DDD
Atomfall指南:项目位置,任务指南和技巧
4 周前
By DDD

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题
gmail邮箱登陆入口在哪里
7653
15


CakePHP 教程
1393
52


steam的账户名称是什么格式
91
11


win11激活密钥永久
73
19


NYT迷你填字游戏答案
37
110

