Model_logic_ding.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. }
  10. public $key = "ly20250115@0911";
  11. //public $key = "Hello, World!";
  12. public function getKey(){
  13. return $this->key;
  14. }
  15. public $url = "https://1.wepolicy.cn/errorlog/ding";
  16. //public $url = "http://cerp.wepolicy.cn/errorlog/ding";
  17. public function sendToDing($error_msg){
  18. $data = [
  19. 'bs'=>$this->logic_tools->toolsjiami($this->key),
  20. 'content'=>$error_msg,
  21. ];
  22. $data = json_encode($data,JSON_UNESCAPED_UNICODE);
  23. $ch = curl_init($this->url);
  24. // 设置cURL选项
  25. $options = array(
  26. CURLOPT_SSL_VERIFYPEER=>false,
  27. CURLOPT_SSL_VERIFYHOST=>false,
  28. CURLOPT_RETURNTRANSFER => true,
  29. CURLOPT_POST => true,
  30. CURLOPT_POSTFIELDS => $data,
  31. CURLOPT_HTTPHEADER => [
  32. 'Content-Type: application/json'
  33. ],
  34. CURLOPT_ENCODING => "gzip,deflate"
  35. );
  36. // 应用这些选项到cURL会话
  37. curl_setopt_array($ch, $options);
  38. // 执行cURL会话并获取响应
  39. $response = curl_exec($ch);
  40. // 检查是否有错误发生
  41. if ($response === false) {
  42. $error = curl_error($ch);
  43. curl_close($ch);
  44. return [
  45. "code"=> -1,
  46. "msg"=> $error
  47. ];
  48. }
  49. // 关闭cURL会话
  50. curl_close($ch);
  51. }
  52. }