ZsyAlert.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Libs\AliSMS;
  4. use GuzzleHttp\Client;
  5. use Illuminate\Console\Command;
  6. class ZsyAlert extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'zsyalert';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return mixed
  33. */
  34. public function handle()
  35. {
  36. $this->start();
  37. }
  38. private function start(){
  39. $check_status = $this->check();
  40. if(!$check_status){
  41. $this->sendAndSave();
  42. }
  43. }
  44. public function getRes(){
  45. $c = \GuzzleHttp\Cookie\CookieJar::fromArray(['web_user_auth'=>'eyJpdiI6IjU4V1lLMTQ0N2hSWGhLY0RMNTlJa1E9PSIsInZhbHVlIjoiVUVhbnFJVk9EcFVtQit1SFwvd2NjMmc9PSIsIm1hYyI6ImQyZjc2ODVhZTNlZmJhZjk3NzNhNmQ4YjQ0OWVmY2U1ZTA0ZjRhZTMxYWFmM2JiNDUyMWVmNzM5NjE5ZWM4YWMifQ%3D%3D'],'site20qv9n7g2qgkzyxw.leyuee.com');
  46. $client = new client(['timeout'=>5,'cookies'=>$c]);
  47. $url = "https://site20qv9n7g2qgkzyxw.leyuee.com/";
  48. try{
  49. $result = $client->request('get',$url)->getBody()->getContents();
  50. return $result;
  51. }catch (\Exception $e){
  52. \Log::info($e);
  53. }
  54. return null;
  55. }
  56. function parseHtml($html){
  57. $xml = new \DOMDocument();
  58. try{
  59. $xml->loadHTML($html);
  60. }catch (Exception $e){
  61. }
  62. $status = $xml->getElementsByTagName('script')->item(6)->nodeValue;
  63. $options = str_ireplace(['window.options = ',';'],'',$status);
  64. $res = json_decode($options,true);
  65. if($res){
  66. return true;
  67. }
  68. return false;
  69. }
  70. function check(){
  71. $res = $this->getRes();
  72. if(!$res){
  73. sleep(2);
  74. $res = $this->getRes();
  75. }
  76. if(!$res) return false;
  77. $status = $this->parseHtml($res);
  78. if($status){
  79. return true;
  80. }
  81. return false;
  82. }
  83. function sendAndSave(){
  84. $file = '/tmp/wangduyun/last.txt';
  85. $last = file_get_contents($file);
  86. //不发
  87. if($last && (time()-$last)<=1800 ){
  88. return false;
  89. }
  90. $phones = ['18668029091','15868100210','18668420256','15158009976','13858057394'];
  91. //$phones = ['18668029091'];
  92. $record = '/tmp/wangduyun/'.date('Y-m-d').'.txt';
  93. foreach($phones as $phone){
  94. $sta = AliSMS::send($phone,'site_remind',['site_name'=>'网读云H5']);
  95. file_put_contents($record,'['.date('Y-m-d H:i:s').'] send:'.$phone.' status is '.$sta."\r\n",FILE_APPEND);
  96. }
  97. file_put_contents($file,time());
  98. }
  99. }