|
@@ -0,0 +1,109 @@
|
|
1
|
+<?php namespace App\Console\Commands;
|
|
2
|
+
|
|
3
|
+use Illuminate\Console\Command;
|
|
4
|
+use Illuminate\Support\Facades\DB;
|
|
5
|
+use App\libs\sms;
|
|
6
|
+define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
|
|
7
|
+define('YP_SMS_YHQ', '73a74eb72c42b765669acd8e94096b9f');
|
|
8
|
+define("YP_SMS_KEY_FAMLI",'995629e02beaaf47118b84ac19c4b5b9');
|
|
9
|
+define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
|
|
10
|
+define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
|
|
11
|
+define("YP_TPL_ID", "3310818");
|
|
12
|
+
|
|
13
|
+class Monitor extends Command {
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+ protected $signature = 'Monitor';
|
|
17
|
+ protected $phone = '13161864516';
|
|
18
|
+
|
|
19
|
+ /**
|
|
20
|
+ * The console command description.
|
|
21
|
+ *
|
|
22
|
+ * @var string
|
|
23
|
+ */
|
|
24
|
+ protected $description = '监控template5分钟内点击量';
|
|
25
|
+
|
|
26
|
+ public function handle() {
|
|
27
|
+ set_time_limit(0);
|
|
28
|
+ ini_set('memory_limit', '1024M');
|
|
29
|
+ $this->monitor();
|
|
30
|
+ }
|
|
31
|
+
|
|
32
|
+ public function monitor() {
|
|
33
|
+ #统计一定时间区间内的uv频率
|
|
34
|
+ $startTime = strtotime(date('Y-m-d 08:00:00',time()));
|
|
35
|
+ $endTime = strtotime(date('Y-m-d 19:00:00',time()));
|
|
36
|
+ $currentTime = time();
|
|
37
|
+
|
|
38
|
+ if($startTime > $currentTime || $endTime < $currentTime){
|
|
39
|
+ return false;
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ $fiveMinuteBefore = date('Y-m-d H:i:s',strtotime('-5 minutes'));
|
|
43
|
+
|
|
44
|
+ $uv = DB::table('templates_log')->where('create_time','<=',date('Y-m-d H:i:s',$currentTime))->where('create_time','>=',$fiveMinuteBefore)->count();
|
|
45
|
+
|
|
46
|
+ if($uv < 10){
|
|
47
|
+ #发送验证码报警
|
|
48
|
+ $res = self::sendMsg($this->phone);
|
|
49
|
+ print_r($res);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ private static function init(){
|
|
55
|
+ $ch = curl_init();
|
|
56
|
+ /* 设置验证方式 */
|
|
57
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
|
|
58
|
+ 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
|
|
59
|
+ /* 设置返回结果为流 */
|
|
60
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
61
|
+
|
|
62
|
+ /* 设置超时时间*/
|
|
63
|
+ curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
|
64
|
+
|
|
65
|
+ /* 设置通信方式 */
|
|
66
|
+ curl_setopt($ch, CURLOPT_POST, 1);
|
|
67
|
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
68
|
+ return $ch;
|
|
69
|
+
|
|
70
|
+ }
|
|
71
|
+
|
|
72
|
+ public static function sendMsg($phone){
|
|
73
|
+
|
|
74
|
+ $tpl_id = YP_TPL_ID;
|
|
75
|
+ $ch=self::init();
|
|
76
|
+ //$data=array('tpl_id' => $tpl_id,'text'=>$text,'apikey'=>YP_SMS_KEY,'mobile'=>$phone);
|
|
77
|
+ $data = [
|
|
78
|
+ 'apikey' => YP_SMS_KEY,
|
|
79
|
+ 'mobile' => $phone,
|
|
80
|
+ 'tpl_id' => $tpl_id,
|
|
81
|
+ ];
|
|
82
|
+ $json_data = self::tpl_send($ch,$data);
|
|
83
|
+ //print_r($json_data); ******************************maybe影响验证码发出
|
|
84
|
+ $array = json_decode($json_data,true);
|
|
85
|
+ // echo '<pre>';print_r($array);
|
|
86
|
+ curl_close($ch);
|
|
87
|
+ return $array;
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ private static function tpl_send($ch,$data){
|
|
91
|
+ curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL);
|
|
92
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
93
|
+ $result = curl_exec($ch);
|
|
94
|
+ $error = curl_error($ch);
|
|
95
|
+ self::checkErr($result,$error);
|
|
96
|
+ return $result;
|
|
97
|
+ }
|
|
98
|
+
|
|
99
|
+ private static function checkErr($result,$error) {
|
|
100
|
+ if($result === false)
|
|
101
|
+ {
|
|
102
|
+ echo 'Curl error: ' . $error;
|
|
103
|
+ }
|
|
104
|
+// else
|
|
105
|
+// {
|
|
106
|
+// echo '操作完成没有任何错误';
|
|
107
|
+// }
|
|
108
|
+ }
|
|
109
|
+}
|