Model_logic_ding.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * 对接crm接口
  4. */
  5. class Model_logic_ding extends Lin_Model {
  6. function __construct(){
  7. parent::__construct();
  8. $this->load->_model("Model_logic_tools","logic_tools");
  9. $this->load->_model("Model_zzjobs","zzjobs");
  10. }
  11. public $key = "ly20250115@0911";
  12. //public $key = "Hello, World!";
  13. public function getKey(){
  14. return $this->key;
  15. }
  16. public $url = "https://1.wepolicy.cn/errorlog/ding";
  17. //public $url = "http://cerp.wepolicy.cn/errorlog/ding";
  18. public function sendToDing($error_msg){
  19. $data = [
  20. 'bs'=>$this->logic_tools->toolsjiami($this->key),
  21. 'content'=>$error_msg,
  22. ];
  23. $data = json_encode($data,JSON_UNESCAPED_UNICODE);
  24. $ch = curl_init($this->url);
  25. // 设置cURL选项
  26. $options = array(
  27. CURLOPT_SSL_VERIFYPEER=>false,
  28. CURLOPT_SSL_VERIFYHOST=>false,
  29. CURLOPT_RETURNTRANSFER => true,
  30. CURLOPT_POST => true,
  31. CURLOPT_POSTFIELDS => $data,
  32. CURLOPT_HTTPHEADER => [
  33. 'Content-Type: application/json'
  34. ],
  35. CURLOPT_ENCODING => "gzip,deflate"
  36. );
  37. // 应用这些选项到cURL会话
  38. curl_setopt_array($ch, $options);
  39. // 执行cURL会话并获取响应
  40. $response = curl_exec($ch);
  41. // 检查是否有错误发生
  42. if ($response === false) {
  43. $error = curl_error($ch);
  44. curl_close($ch);
  45. return [
  46. "code"=> -1,
  47. "msg"=> $error
  48. ];
  49. }
  50. // 关闭cURL会话
  51. curl_close($ch);
  52. }
  53. /**
  54. * 添加到执行队列上
  55. */
  56. public function addJobs($type,$params){
  57. $this->zzjobs->insert([
  58. 'status'=>0,
  59. 'quque'=>$type,
  60. 'payload'=>json_encode($params),
  61. 'do_interval'=>1,
  62. 'create_time'=>time(),
  63. ]);
  64. }
  65. }