ToolController.php
7.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 老猫 <thinkcmf@126.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use think\log;
use think\config;
use think\Db;
class ToolController extends HomeBaseController
{
public function isMixTime($begintime1,$endtime1,$begintime2,$endtime2)
{
$status = $begintime2 - $begintime1;
if($status>0){
$status2 = $begintime2 - $endtime1;
if($status2>=0){
return true;
}else{
return false;
}
}else{
$status2 = $begintime1 - $endtime2;
if($status2>=0){
return true;
}else{
return false;
}
}
}
public function get_relax_time()
{
$day = $this->request->param('day');
$uid = $this->request->param('uid');
if(!$day){
$day = date('Y-m-d');
}
$res = Db::name('yuyue')->where(['yuyue_day'=>$day,'teach_id'=>$uid])->select()->toArray();
$all_arr = [];
for($t = 6;$t<=18;$t++){
$all_arr[]=$t;
}
$arr = [];
for($i = 0;$i<count($res);$i++){
$begin = $res[$i]["yuyue_begin"];
$end = $res[$i]["yuyue_end"];
for($j= $begin;$j<$end;$j++){
$arr[]=$j;
}
}
$ok_arr = [];
for($q = 0;$q< count($all_arr);$q++){
if(in_array($all_arr[$q],$arr)){
$ok_arr[] = "no";
}else{
$ok_arr[] = "yes";
}
}
if ($ok_arr){
return json(['code'=>'1','msg'=>'获取成功','data'=>json_encode($ok_arr,true)]);
}else{
return json(['code'=>'0','msg'=>'获取失败']);
}
}
public function get_sms_code()
{
$mobile = $this->request->param('mobile');
if(!$mobile){
return json(['code'=>'0','msg'=>'请输入手机号码']);
}
$code = rand(111111,999999);
$msg = $code.'(悠乐驾验证码),30分钟内有效,请妥善保管您的验证码,以免账号被盗用。【悠乐驾】';
$data = array(
'content' => $msg,
'mobile' => $mobile,
'productid' => '676767',
'xh' => ''
);
$return = send_sms($data);
$ret=explode(',',$return);
if ($ret[0]=='1'){
cmf_verification_code_log($mobile, $code);
return json(['code'=>'1','msg'=>'验证码已经发送成功']);
}else{
$info=date('Y-m-d H:i:s')." 短信发送失败 error:".$return;
Log::write($info,'ERROR');
return json(['code'=>'0','msg'=>'短信发送失败']);
}
}
public function get_sms_code_p($mobile,$msg)
{
if(!$mobile) {
return json(['code' => '0', 'msg' => '请输入手机号码']);
}
$data = array(
'content' => $msg,
'mobile' => $mobile,
'productid' => '887361',
'xh' => ''
);
send_sms($data);
}
public function get_acctok(){
require_once VENDOR_PATH . 'wxjssdk/jssdk.php';
//微信分享接口调用
$jssdk = new \JSSDK(config::get("WECHAT_APPID"), config::get("WECHAT_APPSECRET"));
$signPackage = $jssdk->GetSignPackage();
$AccessToken = $jssdk->getAccessToken();
return $AccessToken;
}
/**
* 发送post请求
* @param string $url
* @param string $param
* @return ArrayObject|mixed
*/
function request_post($url = '', $param = '')
{
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch); //运行curl
curl_close($ch);
return $data;
}
/**
* 发送get请求
* @param string $url
* @return bool|mixed
*/
function request_get($url = '')
{
if (empty($url)) {
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
// 发送模板消息
public function wxtemsg_send($param=null)
{
$access_token = $this->get_acctok();
$template = array(
'touser' => $param['touser'],
'template_id' => $param['template_id'],
'url' => $param['url'],
'topcolor' => $param['topcolor'],
'data' => $param['data']
);
$json_template = json_encode($template);
$post_url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $access_token;
$dataRes = $this->request_post($post_url, urldecode($json_template));
// 记录请求日志
file_put_contents('./logs/send_template.log', 'time='.date("Y-m-d H:i:s").'req='.json_encode($template, JSON_UNESCAPED_UNICODE).'res='.$dataRes."\n", FILE_APPEND);
$res= json_decode($dataRes);
// if ($res->errcode == 42001 || $res->errcode == 40001) {
// $this->appid = C('WECHAT_APPID');
// $this->secrect = C('WECHAT_APPSECRET');
// $jssdk = new JSSDK($this->appid, $this->secrect);
// $this->accessToken = $jssdk->getAccessToken(true);
// }
return $res;
}
public function aa(){
// 模板参数
$param = [
'touser' => 'oEjC41YHyrNMyfnP1C5_vjh-C7bc',
'topcolor' => '#7B68EE',
'url' => 'http://dm161xueche.qnbug.cn',
'template_id' => 'kmRG7k7OOLd3m5a3sTvvMknbIySIifBtptFPxs3lgUo',
'data' => array(
'first' => array('value' => '学车预约成功'),
'keyword1' => array('value' => date('Y-m-d'),'color'=>'#333366'),
'keyword2' => array('value' => '科目二学车','color'=>'#0099FF'),
'keyword3' => array('value' => '小虎哥', 'color'=>'#0099FF'),
'keyword4' => array('value' => '025-66046652'),
'keyword5' => array('value' => 'qnbug', 'color'=>'#0099FF')
)
];
$res = $this->wxtemsg_send($param);
dump($res);
}
}