noticeUtil.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace common\components;
  3. //通知系统
  4. use Yii;
  5. use yii\helpers\Json;
  6. use linslin\yii2\curl;
  7. class noticeUtil
  8. {
  9. public static function push($message,$mobile_list = [])
  10. {
  11. $url = "https://oapi.dingtalk.com/robot/send?access_token=0856d031e07890f1902496747a0576a49c3df51dcf1e16427168cce12892bedb";
  12. $data = [
  13. 'msgtype' => 'text',
  14. 'text' => ['content' => '【花卉宝】'.$message]
  15. ];
  16. if(!empty($mobile_list)){
  17. $mobile_list = is_array($mobile_list) == false ? [(string)$mobile_list] : $mobile_list;
  18. $data['at']['atMobiles'] = $mobile_list;
  19. }
  20. $data_string = json_encode($data);
  21. self::request($url, $data_string);
  22. }
  23. public static function request($remote_server, $post_string)
  24. {
  25. $ch = curl_init();
  26. curl_setopt($ch, CURLOPT_URL, $remote_server);
  27. curl_setopt($ch, CURLOPT_POST, 1);
  28. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  29. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json;charset=utf-8'));
  30. curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
  31. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  32. // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
  33. // curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
  34. // curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
  35. $data = curl_exec($ch);
  36. curl_close($ch);
  37. return $data;
  38. }
  39. }