Skip to content

Commit cc841af

Browse files
committed
推送第三版,添加多用户支持
1 parent bfe927d commit cc841af

4 files changed

Lines changed: 256 additions & 18 deletions

File tree

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Umbrella
1+
# Umbrella
22
一个PHP的小程序,可以设置定时发送邮件提醒带伞
33

4+
当前版本:Ver.3,已实现的功能有:多用户,可选雨天单独推送
5+
46
https://console.heweather.com/ 申请好KEY后
57

6-
于config.php内填写合适内容即可享用本脚本
8+
于config.php与user.json内填写合适内容即可享用本脚本
79

810
# 简易使用说明:
911

@@ -17,9 +19,6 @@
1719
您需要按照实际需求填写
1820

1921
```
20-
$userid = "Nchyn"; //用户名
21-
$location = "shanghai"; //用户物理地址
22-
$usermail = "youremail@domain.com"; //用户邮箱
2322
$appname = "Nchyn's带伞提醒"; //应用名称
2423
$link = "http://weather.nchyn.com"; //应用主页
2524
$key = "your KEY";//和风天气KEY,请在api.hweather.com申请
@@ -40,9 +39,13 @@ $smtppass = "yourpassword"; //SMTP服务器的用户密码
4039
`$smtpserver`添加`ssl://`,
4140

4241
如:`$smtpserver = "smtp.ym.163.com";`
43-
## 4.运行umbrellaV2.php
42+
43+
## 4.编辑users.json
44+
### 注意检查
45+
46+
## 5.运行umbrellaV3.php
4447
您可以部署于WEB服务器或
45-
`php /home/umb/umbrellaV2.php`
48+
`php /home/umb/umbrellaV3.php`
4649
直接运行
4750
亦可设置crontab做定时任务
4851

UmbrellaV3.PHP

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
<meta http-equiv="content-type" content="text/html;charset=utf-8">
2+
<?php
3+
// +----------------------------------------------------------------------+
4+
// | PHP version 5 |
5+
// +----------------------------------------------------------------------+
6+
// | Copyright (c) 1997-2018 Nchyn |
7+
// +----------------------------------------------------------------------+
8+
// | Authors: Original Author <mail@nchyn.com> |
9+
// +----------------------------------------------------------------------+
10+
//
11+
//带伞提醒 Ver.3 多用户版
12+
require 'config.php';
13+
$userjson = file_get_contents("./users.json"); //获取用户json格式的数据
14+
$userarr = json_decode($userjson, TRUE); //对json格式的字符串进行编码
15+
$motd = "亦可赛艇!";
16+
foreach ($userarr['users'] as $userkey => $userval) { //遍历用户json生成城市字段
17+
$location = ($userval['location']);
18+
$usermail = ($userval['usermail']);
19+
$userid = ($userval['userid']);
20+
$usersunflag = ($userval['usersunflag']);
21+
echo ($usersunflag);
22+
$jsonadd = "https://free-api.heweather.com/s6/weather/forecast?location={$location}&key={$Hekey}"; //json地址
23+
$weatherjson = file_get_contents($jsonadd);
24+
$weatherarr = json_decode($weatherjson, TRUE);
25+
$usercity = ($weatherarr['HeWeather6']['0']['basic']['location']);
26+
$weathertime = ($weatherarr['HeWeather6']['0']['update']['loc']);
27+
foreach ($weatherarr['HeWeather6'][0]['daily_forecast'] as $weatherkey => $weatherval) { //确定城市后循环遍历天气数据
28+
$data[] = "日期:" . $weatherval['date'];
29+
$txt_d[] = "{$weatherval['cond_txt_d']}";
30+
$txt_n[] = "{$weatherval['cond_txt_n']}";
31+
$winds[] = "{$weatherval['wind_dir']}";
32+
$tmps[] = "{$weatherval['tmp_max']}~{$weatherval['tmp_min']}";
33+
}
34+
if ($txt_d[0] == $txt_n[0]) { //判断日间与夜间天气是否相同,并自然化语言
35+
$weather0 = $txt_d[0];
36+
} else {
37+
$weather0 = $txt_d[0] . "" . $txt_n[0];
38+
};
39+
if ($txt_d[1] == $txt_n[1]) {
40+
$weather1 = $txt_n[1];
41+
} else {
42+
$weather1 = $txt_d[1] . "" . $txt_n[1];
43+
};
44+
if ($txt_d[2] == $txt_n[2]) {
45+
$weather2 = $txt_n[2];
46+
} else {
47+
$weather2 = $txt_d[2] . "" . $txt_n[2];
48+
};
49+
if (strstr($weather0, "")) {
50+
$tips = "需要带伞"; //带伞通知
51+
$subject = "今天会下雨哦"; //邮件主题
52+
53+
} else {
54+
$tips = "不需要带伞";
55+
$subject = "今天是个好天气☆~";
56+
}
57+
$weather0 = $weather0 . "," . $winds[0] . "," . $tmps[0]; //整合天气数据
58+
$weather1 = $weather1 . "," . $winds[1] . "," . $tmps[1];
59+
$weather2 = $weather2 . "," . $winds[2] . "," . $tmps[2];
60+
//邮件部分
61+
$mailstr = <<<LABELSS
62+
<style type="text/css">
63+
img {
64+
max-width: 100%;
65+
}
66+
body {
67+
-webkit-font-smoothing: antialiased;
68+
-webkit-text-size-adjust: none;
69+
width: 100% !important;
70+
71+
line-height: 1.6em;
72+
}
73+
body {
74+
background-color: #f6f6f6;
75+
}
76+
@media only screen and (max-width: 640px) {
77+
body {
78+
padding: 0 !important;
79+
}
80+
h1 {
81+
font-weight: 800 !important;
82+
margin: 20px 0 5px !important;
83+
}
84+
h2 {
85+
font-weight: 800 !important;
86+
margin: 20px 0 5px !important;
87+
}
88+
h3 {
89+
font-weight: 800 !important;
90+
margin: 20px 0 5px !important;
91+
}
92+
h4 {
93+
font-weight: 800 !important;
94+
margin: 20px 0 5px !important;
95+
}
96+
h1 {
97+
font-size: 22px !important;
98+
}
99+
h2 {
100+
font-size: 18px !important;
101+
}
102+
h3 {
103+
font-size: 16px !important;
104+
}
105+
.container {
106+
padding: 0 !important;
107+
width: 100% !important;
108+
}
109+
.content {
110+
padding: 0 !important;
111+
}
112+
.content-wrap {
113+
padding: 10px !important;
114+
}
115+
.invoice {
116+
width: 100% !important;
117+
}
118+
}
119+
</style>
120+
121+
<table class="body-wrap" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; background-color: #f6f6f6; margin: 0;" bgcolor="#f6f6f6">
122+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
123+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
124+
<td class="container" width="600" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; display: block !important; max-width: 600px !important; clear: both !important; margin: 0 auto;" valign="top">
125+
<div class="content" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; max-width: 600px; display: block; margin: 0 auto; padding: 20px;">
126+
<table class="main" width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; border-radius: 3px; background-color: #fff; margin: 0; border: 1px solid #e9e9e9;" bgcolor="#fff">
127+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
128+
<td class="content-wrap aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 20px;" align="center" valign="top">
129+
<table width="100%" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
130+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
131+
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
132+
<h1 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 32px; color: #000; line-height: 1.2em; font-weight: 500; text-align: center; margin: 40px 0 0;" align="center"></h1>
133+
</td>
134+
</tr>
135+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
136+
<td class="content-block" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 0 0 20px;" valign="top">
137+
<h2 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 24px; color: #000; line-height: 1.2em; font-weight: 400; text-align: center; margin: 40px 0 0;" align="center">{$subject}</h2>
138+
<h4 class="aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,'Lucida Grande',sans-serif; box-sizing: border-box; font-size: 24px; color: #000; line-height: 1.2em; font-weight: 400; text-align: center; margin: 40px 0 0;" align="center">{$usercity}</h4>
139+
</td>
140+
</tr>
141+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
142+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">
143+
<table class="invoice" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; text-align: left; width: 80%; margin: 40px auto;">
144+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
145+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">Hi,{$userid}<br style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">收件邮箱:<br style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">{$usermail}<br style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">预报生成时间(今天指这一天):<br style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">{$weathertime}</td>
146+
</tr>
147+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
148+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">
149+
<table class="invoice-items" cellpadding="0" cellspacing="0" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; margin: 0;">
150+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
151+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">今天的天气是:</td>
152+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather0}</td>
153+
</tr>
154+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
155+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top"> 明天的天气是:</td>
156+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather1}</td>
157+
</tr>
158+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
159+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">后天的天气是:</td>
160+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$weather2}</td>
161+
</tr>
162+
163+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
164+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" valign="top">是否需要带伞?</td>
165+
<td class="alignright" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: right; border-top-width: 1px; border-top-color: #eee; border-top-style: solid; margin: 0; padding: 5px 0;" align="right" valign="top">{$tips}</td>
166+
</tr>
167+
168+
169+
</tbody></table>
170+
</td>
171+
</tr>
172+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
173+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0; padding: 5px 0;" valign="top">{$motd}</td>
174+
</tr>
175+
176+
</tbody></table>
177+
</td>
178+
</tr>
179+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
180+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top">
181+
<a href="" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; color: #348eda; text-decoration: underline; margin: 0;"></a>
182+
</td>
183+
</tr>
184+
<tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
185+
<td class="content-block aligncenter" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; text-align: center; margin: 0; padding: 0 0 20px;" align="center" valign="top"><a href="{$link}">{$appname}</a></td>
186+
</tr>
187+
</tbody></table>
188+
</td>
189+
</tr>
190+
</tbody></table>
191+
<div class="footer" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; width: 100%; clear: both; color: #999; margin: 0; padding: 20px;">
192+
<table width="100%" style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
193+
<tbody><tr style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; margin: 0;">
194+
</tr>
195+
</tbody></table>
196+
</div>
197+
</div>
198+
</td>
199+
<td style="font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; vertical-align: top; margin: 0;" valign="top"></td>
200+
</tr>
201+
</tbody></table>
202+
LABELSS;
203+
if (strstr($weather0, "")) { //判断天气情况,发送邮件
204+
$mailto = $usermail; //收件人
205+
$body = $mailstr; //邮件内容
206+
sendmailto($mailto, $subject, $body);
207+
} else {
208+
if ($usersunflag == 'true') {
209+
$mailto = $usermail;
210+
$body = $mailstr;
211+
sendmailto($mailto, $subject, $body);
212+
}
213+
};
214+
$data = ""; //初始化天气数据
215+
$txt_d = "";
216+
$txt_n = "";
217+
$winds = "";
218+
$tmps = "";
219+
//print_r($mailstr);//web预览邮件样式
220+
}
221+
?>
222+
223+

0 commit comments

Comments
 (0)