+ -
当前位置:首页 → 问答吧 → 简单的发送天气预报短信的代码

简单的发送天气预报短信的代码

时间: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 编辑 ]

作者: snail000   发布时间: 2009-08-10

谢谢,我以前在寻找,今天路过就看到了。3Q

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

下载了,好人

作者: 西湖泉边   发布时间: 2009-08-10

热门下载

更多