此方法需要用到vps或独立服务器,并且只有root用户才可以。
飞信api文件: 飞信API文件.zip(直接点击下载,也可以直接利用我空间的飞信api http://vps.cn00.net/getfetion.php?useid=150000000&password=0000000&sendid=0000&sendtext=0000)
文件解压后上传到php空间即可。我们需要提交的,包括手机号,飞信密码,所要发送人及发送的信息。利用上篇说道的,将用户名级密码保存在一个php文件中,也可以设置默认发送人及默认的发送信息。(这些也可以在api文件中直接设置)
//send.php
<title>飞信发送</title><?php
date_default_timezone_set('Asia/shanghai');//此句是用来消除时间差
$time=date("Y-m-d.H:i:s");
// 创建一个新cURL资源
$city = empty($_GET['city']) ? 'zhengzhou' : $_GET['city'];
$content = file_get_contents("http://www.google.com/ig/api?weather=$city&hl=zh-cn");
$content || die("No such city's data");
$content = mb_convert_encoding($content, 'UTF-8', 'GBK');
$xml = simplexml_load_string($content);
$date = $xml->weather->forecast_information->forecast_date->attributes();
$html = $date."\r\n";
$current = $xml->weather->current_conditions;
$condition = $current->condition->attributes();
$temp_c = $current->temp_c->attributes();
$humidity = $current->humidity->attributes();
$icon = $current->icon->attributes();
$wind = $current->wind_condition->attributes();
$condition && $condition = $xml->weather->forecast_conditions->condition->attributes();
$icon && $icon = $xml->weather->forecast_conditions->icon->attributes();
$html.= "当前: {$condition},{$temp_c}°C, {$humidity} {$wind}\r\n";
foreach($xml->weather->forecast_conditions as $forecast) {
$low = $forecast->low->attributes();
$high = $forecast->high->attributes();
$icon = $forecast->icon->attributes();
$condition = $forecast->condition->attributes();
$day_of_week = $forecast->day_of_week->attributes();
$html.= "{$day_of_week} : {$low}-{$high}°C, {$condition}\r\n";
}
$html=urlencode($html);
$p = empty($_GET['p']) ? '1500000000' : $_GET['p'];
$html = empty($_GET['t']) ? $html : $_GET['t'];
$ch = curl_init();
// 设置URL和相应的选项
curl_setopt($ch, CURLOPT_URL, "http://vps.cn00.net/getfetion.php?useid=150000000&password=0000000&sendid=".$p."&sendtext=".$html);
curl_setopt($ch, CURLOPT_HEADER, 0);
// 抓取URL并把它传递给浏览器
curl_exec($ch);
// 关闭cURL资源,并且释放系统资源
curl_close($ch);
?>
以上红色的是需要修改的地方,第一个为发送人,下面的两个分别是你自己的飞信帐号及密码,保存后上传到自己的空间,我提供的默认发送的是郑州的天气预报。。。
这样直接打开此页面,不加任何参数就会将天气信息发送到默认的收信人。
如果发送给其他人其他信息,可以向本页面用get方式传递参数。
链接为以下形式:
http://vps.cn00.net/send.php?p=收信人&t=发送信息&cite=城市
发送信息的就这一部分了。
以下为设置定时提醒
登陆服务器,输入命令 crontab -e
然后会出来一个vim的编辑窗口,直接写入以下内容:
20 10 29 11 * curl http://vps.cn00.net/s.php
以上各个数字分别对应 分,时,日,月,星期 *表示任何时刻,定时天气预报的话,就可以直接设置好时分,然后其他为*,其他内容可以参照上文实现。
关于linux定时任务的更多内容,可以自行百度,这里不做过多介绍。
相关文章
229. php模拟表单提交(可以包含汉字,空格等) (2011-11-30 10:53:58)
228. 也许并没有想象中那么难。。。 (2011-11-27 18:28:4)
211. 自制mp4的tv-out线 (2011-6-7 10:46:19)
209. 怎样充分利用教育网 (2011-5-4 22:35:2)
205. 云----是个好东西 (2010-12-24 22:36:51)
202. Matlab实验报告 (2010-10-20 8:16:22)
192. 让一切网络化~ (2010-8-3 9:40:27)
187. vps(虚拟服务器)挂QQ(桌面版+shell版) (2010-6-28 21:25:47)
186. 跨行转账免收手续费了!!! (2010-6-24 12:47:27)
177. 为什么国内免费空间行不通? (2010-5-24 8:21:47)
