简单的发送天气预报短信的代码
时间:2009-08-10
来源:互联网
<?
//weather.php
/************调用方法**************/
//weather.php?id=城市编号&m=接收手机号
//城市编号可以通过weathercn网站查询,以后有时间再做查询接口
//接收手机号必须是服务手机号的飞信好友,可以不开通飞信
/************调用方法**************/
/*********服务方配置设置************/
$sernum = 138********;//服务手机号,需要开通飞信
$serpwd = '***********';//服务手机号飞信密码
/*********服务方配置设置************/
/***********抓取数据***************/
$url='http://www.weathercn.com/tqyb/detail.jsp?sta_id='.$_GET['id'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$code = iconv(\"GB2312\",\"UTF-8\",curl_exec ($ch));//编码转码
/***********抓取数据***************/
/***********过滤数据***************/
preg_match('|国内天气预报-(.*?)</title>|',$code,$city);
preg_match_all('|width=155.*<strong>(.*?)</strong>|',$code,$date);//$date[1][0] $date[1][1]
preg_match_all('|width=72>(.*?)</td>|',$code,$cweat);//$cweat[1][0] $cweat[1][1]
preg_match_all('|<img alt=\"(.*?)\"|',$cweat[1][0],$weatheraa);//$weatheraa[1][n]
preg_match_all('|<img alt=\"(.*?)\"|',$cweat[1][1],$weatherbb);//$weatherbb[1][n]
preg_match_all('|width=89.*<strong>(.*?)</strong>|',$code,$temp);//$temp[1][0] $temp[1][1]
$tempa=str_replace(\"℃\",\"度\",$temp[1][0]);
$tempa=str_replace(\"~\",\"到\",$tempa);
$tempa=str_replace(\"-\",\"零下\",$tempa);
$tempb=str_replace(\"℃\",\"度\",$temp[1][1]);
$tempb=str_replace(\"~\",\"到\",$tempb);
$tempb=str_replace(\"-\",\"零下\",$tempb);
preg_match_all('|width=116>([\s\S]*?)</TD>|',$code,$cwind);//$cwind[1][0] $cwind[1][1]
preg_match_all('|<img alt=\"(.*?)\".*width=\"27\" height=\"30\">|',$cwind[1][0],$windaa);//$windaa[1][n]
preg_match_all('|<img alt=\"(.*?)\".*width=\"27\" height=\"30\">|',$cwind[1][1],$windbb);//$windbb[1][n]
$datea=$date[1][0];
$dateb=$date[1][1];
if(count($windaa[1])==1)
$winda=$windaa[1][0];
else
{
$winda=$windaa[1][0];
for($i=1;$i<count($windaa[1]);$i++)
$winda.='转'.$windaa[1][$i];
}
if(count($windbb[1])==1)
$windb=$windbb[1][0];
else
{
$windb=$windbb[1][0];
for($i=1;$i<count($windbb[1]);$i++)
$windb.='转'.$windbb[1][$i];
}
if(count($weatheraa[1])==1)
$weathera=$weatheraa[1][0];
else
{
$weathera=$weatheraa[1][0];
for($i=1;$i<count($weatheraa[1]);$i++)
$weathera.='转'.$weatheraa[1][$i];
}
if(count($weatherbb[1])==1)
$weatherb=$weatherbb[1][0];
else
{
$weatherb=$weatherbb[1][0];
for($i=1;$i<count($weatherbb[1]);$i++)
$weatherb.='转'.$weatherbb[1][$i];
}
if($winda=='')
$winda='无风';
if($windb=='')
$windb='无风';
/***********过滤数据***************/
/***********整理数据***************/
$tq=$city[1].':'.$datea.','.$weathera.','.$tempa.','.$winda.'。'.$dateb.','.$weatherb.','.$tempb.','.$windb.'。[1989s 测试版]';
/***********整理数据***************/
/***********发送短信***************/
include \"class_fetion.php\";//见附件或可以到[email protected]下载,密码snailsend
$fetion = new fetion($sernum, $serpwd);
$fetion->init() or die(\"fetion init failure!\n\");
$fetion->sent_sms('tel:'.$_GET['m'], $tq);
/***********发送短信***************/
?>
[ 本帖最后由 snail000 于 2009-8-10 23:38 编辑 ]
//weather.php
/************调用方法**************/
//weather.php?id=城市编号&m=接收手机号
//城市编号可以通过weathercn网站查询,以后有时间再做查询接口
//接收手机号必须是服务手机号的飞信好友,可以不开通飞信
/************调用方法**************/
/*********服务方配置设置************/
$sernum = 138********;//服务手机号,需要开通飞信
$serpwd = '***********';//服务手机号飞信密码
/*********服务方配置设置************/
/***********抓取数据***************/
$url='http://www.weathercn.com/tqyb/detail.jsp?sta_id='.$_GET['id'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$code = iconv(\"GB2312\",\"UTF-8\",curl_exec ($ch));//编码转码
/***********抓取数据***************/
/***********过滤数据***************/
preg_match('|国内天气预报-(.*?)</title>|',$code,$city);
preg_match_all('|width=155.*<strong>(.*?)</strong>|',$code,$date);//$date[1][0] $date[1][1]
preg_match_all('|width=72>(.*?)</td>|',$code,$cweat);//$cweat[1][0] $cweat[1][1]
preg_match_all('|<img alt=\"(.*?)\"|',$cweat[1][0],$weatheraa);//$weatheraa[1][n]
preg_match_all('|<img alt=\"(.*?)\"|',$cweat[1][1],$weatherbb);//$weatherbb[1][n]
preg_match_all('|width=89.*<strong>(.*?)</strong>|',$code,$temp);//$temp[1][0] $temp[1][1]
$tempa=str_replace(\"℃\",\"度\",$temp[1][0]);
$tempa=str_replace(\"~\",\"到\",$tempa);
$tempa=str_replace(\"-\",\"零下\",$tempa);
$tempb=str_replace(\"℃\",\"度\",$temp[1][1]);
$tempb=str_replace(\"~\",\"到\",$tempb);
$tempb=str_replace(\"-\",\"零下\",$tempb);
preg_match_all('|width=116>([\s\S]*?)</TD>|',$code,$cwind);//$cwind[1][0] $cwind[1][1]
preg_match_all('|<img alt=\"(.*?)\".*width=\"27\" height=\"30\">|',$cwind[1][0],$windaa);//$windaa[1][n]
preg_match_all('|<img alt=\"(.*?)\".*width=\"27\" height=\"30\">|',$cwind[1][1],$windbb);//$windbb[1][n]
$datea=$date[1][0];
$dateb=$date[1][1];
if(count($windaa[1])==1)
$winda=$windaa[1][0];
else
{
$winda=$windaa[1][0];
for($i=1;$i<count($windaa[1]);$i++)
$winda.='转'.$windaa[1][$i];
}
if(count($windbb[1])==1)
$windb=$windbb[1][0];
else
{
$windb=$windbb[1][0];
for($i=1;$i<count($windbb[1]);$i++)
$windb.='转'.$windbb[1][$i];
}
if(count($weatheraa[1])==1)
$weathera=$weatheraa[1][0];
else
{
$weathera=$weatheraa[1][0];
for($i=1;$i<count($weatheraa[1]);$i++)
$weathera.='转'.$weatheraa[1][$i];
}
if(count($weatherbb[1])==1)
$weatherb=$weatherbb[1][0];
else
{
$weatherb=$weatherbb[1][0];
for($i=1;$i<count($weatherbb[1]);$i++)
$weatherb.='转'.$weatherbb[1][$i];
}
if($winda=='')
$winda='无风';
if($windb=='')
$windb='无风';
/***********过滤数据***************/
/***********整理数据***************/
$tq=$city[1].':'.$datea.','.$weathera.','.$tempa.','.$winda.'。'.$dateb.','.$weatherb.','.$tempb.','.$windb.'。[1989s 测试版]';
/***********整理数据***************/
/***********发送短信***************/
include \"class_fetion.php\";//见附件或可以到[email protected]下载,密码snailsend
$fetion = new fetion($sernum, $serpwd);
$fetion->init() or die(\"fetion init failure!\n\");
$fetion->sent_sms('tel:'.$_GET['m'], $tq);
/***********发送短信***************/
?>
[ 本帖最后由 snail000 于 2009-8-10 23:38 编辑 ]
作者: snail000 发布时间: 2009-08-10


作者: 孤星泪 发布时间: 2009-08-10

作者: 西湖泉边 发布时间: 2009-08-10
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28