123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use App\libs\sms;
- define("YP_SMS_KEY", "fbdb5f2ddae13c2f4a592348bfe52137");
- define('YP_SMS_YHQ', '73a74eb72c42b765669acd8e94096b9f');
- define("YP_SMS_KEY_FAMLI",'995629e02beaaf47118b84ac19c4b5b9');
- define("YP_VOICE_URL", "http://voice.yunpian.com/v2/voice/send.json");
- define("YP_TPL_URL", "https://sms.yunpian.com/v2/sms/tpl_single_send.json");
- define("YP_TPL_ID", "3310818");
- class Monitor extends Command {
- protected $signature = 'Monitor';
- // protected $phone = '13161864516';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '监控template5分钟内点击量';
- public function handle() {
- set_time_limit(0);
- ini_set('memory_limit', '1024M');
- $this->monitor();
- }
- public function monitor() {
- #统计一定时间区间内的uv频率
- $startTime = strtotime(date('Y-m-d 09:00:00',time()));
- $endTime = strtotime(date('Y-m-d 17:00:00',time()));
- $currentTime = time();
- if($startTime > $currentTime ||
- $endTime < $currentTime ||
- (date('w',$currentTime)==6) ||
- (date('w',$currentTime) == 0)){
- return false;
- }
- $fiveMinuteBefore = date('Y-m-d H:i:s',strtotime('-5 minutes'));
- $pv = DB::table('templates_log')->where('create_time','<=',date('Y-m-d H:i:s',$currentTime))->where('create_time','>=',$fiveMinuteBefore)->count();
- if($pv <= 1){
- #发送验证码报警
- self::sendMsg('13161864516');
- self::sendMsg('18410900527');
- error_log(date('Y-m-d H:i:s',time()).' pv:'.$pv." \n ",3,"/log/seafood_log/script_success/".date('Y-m-d',time()).'Monitor.log');
- }
- }
- private static function init(){
- $ch = curl_init();
- /* 设置验证方式 */
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:text/plain;charset=utf-8',
- 'Content-Type:application/x-www-form-urlencoded', 'charset=utf-8'));
- /* 设置返回结果为流 */
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- /* 设置超时时间*/
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- /* 设置通信方式 */
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- return $ch;
- }
- public static function sendMsg($phone){
- $tpl_id = YP_TPL_ID;
- $ch=self::init();
- //$data=array('tpl_id' => $tpl_id,'text'=>$text,'apikey'=>YP_SMS_KEY,'mobile'=>$phone);
- $data = [
- 'apikey' => YP_SMS_KEY,
- 'mobile' => $phone,
- 'tpl_id' => $tpl_id,
- ];
- $json_data = self::tpl_send($ch,$data);
- //print_r($json_data); ******************************maybe影响验证码发出
- $array = json_decode($json_data,true);
- // echo '<pre>';print_r($array);
- curl_close($ch);
- return $array;
- }
- private static function tpl_send($ch,$data){
- curl_setopt ($ch, CURLOPT_URL, YP_TPL_URL);
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
- $result = curl_exec($ch);
- $error = curl_error($ch);
- self::checkErr($result,$error);
- return $result;
- }
- private static function checkErr($result,$error) {
- if($result === false)
- {
- echo 'Curl error: ' . $error;
- }
- // else
- // {
- // echo '操作完成没有任何错误';
- // }
- }
- }
|