利用飞信api免费发送天气预报
作者:寒川 发布于:2010-4-15 10:13 Thursday 分类:网页编程
<?/**
* 飞信通知天气预报
* 2009-4-23
*/
//禁止执行时间限制
set_time_limit (0);
$ad=" [广告招商]";//定义广告
function getWF($city)
{
if(empty($city)) return "";
$wf=@file_get_contents('http://php.weather.sina.com.cn/search.php?city='.urlencode($city).'&f=1&dpc=1');
if (empty($wf))
{
return "";
}
//截取相关信息
$return = "";
$star=strpos($wf,"<div class=\"info-area\">");
$return = substr($wf,$star,1000);
$end2=strpos($return,"<!-- box end-->");
$return = strip_tags(substr($return,0,$end2));
//过滤
$return=mb_convert_encoding($return, "UTF-8", "GBK");//将GBK转换UTF-8编码,否则出现乱码
$return = str_replace(" ","",$return); //过滤换空格符
$return = str_replace("\t"," ",$return);//过滤制表符
$return = str_replace("\n"," ",$return); //过滤换行符
$return = trim(str_replace("\r"," ",$return),",");//过滤回车符
$return = str_replace("℃","度",$return); //防止某些手机无此符号
$return = str_replace("~","-",$return);//同上
$return = str_replace("≤","小于",$return);//同上
$return = str_replace(":",":",$return); //同上
$return = str_replace("风力:"," 风力",$return);//同上
$return = preg_replace("/(\s+)/",' ',$return);//多个空格替换为一个空格
return $return;
}
$user='135****509';//手机号码
$pass='***';//飞信密码
//设置天气预报城市
$citys[]=array('id'=>'cd','name'=>'成都');//可类似设置多个
//手机号
$tel['cd'][]='135****509';//可类似设置多个
if (is_array($citys)&&count($citys)>0)
//遍历城市
foreach($citys as $city)
{
//获取采集信息
$info=getWF($city['name']);
$info="天气预报:".$city['name']." ".$info.$ad;
if (!empty($info)){
if (is_array($tel[$city['id']])&&count($tel[$city['id']])>0){
//发送
foreach($tel[$city['id']] as $val)//循环发送
{
$url="http://weather.huikon.cn/api.php?mobile_no=".$user."&pwd=".$pass."&to=".$val."&msg=".urlencode($info);//飞信API地址
@file_get_contents($url);
//echo $info.$val;
}
}
}
}
}
//自动关闭脚本
echo <<<EOT
<script language=javascript>
window.opener=null
window.open("","_self")
window.close();
</script>
EOT;
?>
评论:
韩世界15680180146
2010-06-16 16:13
2010-06-16 16:13
第一部分
@echo off
::条件判断,按条件调用飞信机器人给不同的人发送天气预报和提醒事项
if "%date:~-3%"=="星期六" goto zmpd
if "%date:~-3%"=="星期日" goto zmpd
::工作日天气预报发送时间--------------------------------------------if "%time:~0,2%"==" 9" goto tqfs
if "%time:~0,2%"=="14" goto tqfs
if "%time:~0,2%"=="20" goto tqfs
goto tc
:zmpd
::周末天气预报发送时间---------------------------------------------
if "%time:~0,2%"=="11" goto tqfs
if "%time:~0,2%"=="20" goto tqfs
goto tc
@echo off
::条件判断,按条件调用飞信机器人给不同的人发送天气预报和提醒事项
if "%date:~-3%"=="星期六" goto zmpd
if "%date:~-3%"=="星期日" goto zmpd
::工作日天气预报发送时间--------------------------------------------if "%time:~0,2%"==" 9" goto tqfs
if "%time:~0,2%"=="14" goto tqfs
if "%time:~0,2%"=="20" goto tqfs
goto tc
:zmpd
::周末天气预报发送时间---------------------------------------------
if "%time:~0,2%"=="11" goto tqfs
if "%time:~0,2%"=="20" goto tqfs
goto tc
日志分类
最近日志
随机日志
最新评论
- CCC certification
对这块还真是不... - 那风筝
happy new year ! - Roy
你好, 交换个链... - 太阳城娱乐网
说实话,对钛白... - 卡特&&艾弗森
不错啊!!,过段... - 奇遇
沙发 - 寒川
@Mr.邱℡:现在可... - Mr.邱℡
曾经加过,失效... - 寒川
@欧盛网络:链接... - 欧盛网络
换个链接好不?...
日志档案
- 2011年11月(2)
- 2011年9月(1)
- 2011年8月(2)
- 2011年7月(2)
- 2011年5月(1)
- 2011年3月(3)
- 2011年2月(2)
- 2010年12月(1)
- 2010年11月(2)
- 2010年10月(3)
- 2010年9月(9)
- 2010年8月(8)
- 2010年7月(13)
- 2010年6月(18)
- 2010年5月(24)
- 2010年4月(10)
- 2010年3月(14)
- 2010年2月(6)
- 2010年1月(7)
- 2009年11月(2)
- 2009年10月(3)
- 2009年9月(3)
- 2009年8月(8)
- 2009年7月(15)
- 2009年6月(14)
- 2009年4月(2)
- 2008年12月(1)
- 2008年6月(1)
- 2008年5月(10)
- 2008年4月(9)
- 2008年3月(5)
- 2008年2月(2)
- 2008年1月(5)
- 2007年12月(4)
- 2006年9月(6)
- 2006年7月(1)



2010-06-16 16:14