时间:2021-07-01 10:21:17 帮助过:8人阅读
代码如下:
/**
* 飞信通知天气预报
* 2009-4-23
*/
//禁止执行时间限制
set_time_limit (0);
//设置MB编码
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,"");
$return = substr($wf,$star,1000);
$end2=strpos($return,"");
$return = strip_tags(substr($return,0,$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($city['name']);
if (!empty($info)){
if (is_array($tel[$city['id']])&&count($tel[$city['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[$city['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日")." ".$city['name']." ".$qInfo);
@file_get_contents($url);
}
}
}else{
foreach($tel[$city['id']] as $val){
$url="http://sms.api.bz/fetion.php?username=".$Fetion['user']."&password=".$Fetion['pass']."&sendto=".$val."&message=".urlencode("天气预报,明天".date("Y年m月d日")." ".$city['name']." ".$info);
@file_get_contents($url);
}
}
}
}
}
}
?>
代码如下:
//飞信账号设置
$Fetion['user']='自己的飞信账号手机号';
$Fetion['pass']='登录飞信密码';
代码如下:
//设置天气预报城市
$citys[]=array('id'=>'bj','name'=>'北京');
代码如下:
//北京手机号
$tel['bj'][]='137XXXXXXX';
$tel['bj'][]='137XXXXXXX';
以上就介绍了免费天气预报短信 php结合飞信 免费天气预报短信,包括了免费天气预报短信方面的内容,希望对PHP教程有兴趣的朋友有所帮助。