PHP
发布时间:2019-11-18 发布网站:大佬教程 code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php结合飞信 免费天气预报短信,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
开始教你怎么弄
一、需要有一个php环境。为了图省事下载APMServ软件快速搭建php环境
二、下载天气预报短信通知php程序点<A href="http://xiazai.jb51.cc/200905/yuanma/WeatherForecast.rar">这里下载代码
三、修改php程序配置
用记事本打开WeatherForecast.php文件
<div class="codetitle"><a style="cursOR: pointer" data="60310" class="copybut" id="copybut60310" onclick="doCopy('code60310')"> 代码如下:
<div class="codebody" id="code60310">
<?
/*
飞信通知天气预报
2009-4-23
/ //禁止执行时间限制
set_time_limit (0
); //设置MB编码 @H_886_1
@mb_internal_encoding("GB2312"
); /*
采集新浪天气预报信息
@param
String $city城市名称
@return unknown
/
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=\"blk-s3\">"
); $return = substr($wf,$star,1000
); $end2=strpos($return,""
); $return =
Strip_tags(substr($return,$end2)
); //过滤
$return = str_
replace("","",$return
); $return = str_
replace(" ",$return
); $return = str_
replace("\t",$return
); $return = str_
replace("\n",$return
); $return = str_
replace("℃","度",$return
); $return = str_
replace("≤",$return
); $return = trim(str_
replace("\r",",$return),"
); $return = str_
replace("~","-",$return
); $return = str_
replace(":",":",$return
); //返回值
return $return;
} //
飞信账号设置
$Fetion['user']='';
$Fetion['pass']=''; //设置天气预报城市
$citys[]=array('id'=>'bj','name'=>'北京'
); $citys[]=array('id'=>'sy','name'=>'沈阳'
); //北京手机号
$tel['bj'][]='137XXXXXXX';
$tel['bj'][]='137XXXXXXX';
//沈阳手机号
$tel['sy'][]='138XXXXXXXX';
$tel['sy'][]='137XXXXXXX';
if (is_array($citys)&&count($citys)>0)
{ //遍历城市
foreach($citys as $city)
{ //获取采集信息
$info=getWF($cit
Y['name']
); if (!empty($info))
{ if (is_array($tel[$cit
Y['id']])&&count($tel[$cit
Y['id']])>0)
{ //大信息量处理
if (mb_strlen($info)>171)
{ $sum=ceil(mb_strlen($info)/168)-1;
for($i
=0;$i<=$sum;$i++)
{ $starj=168*$i;
$qInfo=mb_substr($info,$starj,168
); $n=$i+1;
foreach($tel[$cit
Y['id']] as $val)
{ $url="
http://sms.api.bz/fetion.php?username=".$Fetion['user']."&password=".$Fetion['pass']."&sendto=".$val."&message=".urlencode("天气预报[".$n."],"."明天".date("Y年m月d日")." ".$cit
Y['name']." ".$qInfo
); @file_get_contents($url
); }
}
}else
{ foreach($tel[$cit
Y['id']] as $val)
{ $url="
http://sms.api.bz/fetion.php?username=".$Fetion['user']."&password=".$Fetion['pass']."&sendto=".$val."&message=".urlencode("天气预报,明天".date("Y年m月d日")." ".$cit
Y['name']." ".$info
); @file_get_contents($url
); }
}
}
}
}
}
?>