EnterpriseWechatJob.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs\notice;
  12. use crmeb\basic\BaseJobs;
  13. use crmeb\services\HttpService;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. class EnterpriseWechatJob extends BaseJobs
  17. {
  18. use QueueTrait;
  19. /**
  20. * 给企业微信群发送消息
  21. */
  22. public function doJob($data, $url, $ent_wechat_text)
  23. {
  24. try {
  25. $str = $ent_wechat_text;
  26. foreach ($data as $key => $item) {
  27. $str = str_replace('{' . $key . '}', $item, $str);
  28. }
  29. $s = explode('\n', $str);
  30. $d = '';
  31. foreach ($s as $item) {
  32. $d .= $item . "\n>";
  33. }
  34. $d = substr($d, 0, strlen($d) - 2);
  35. $datas = [
  36. 'msgtype' => 'markdown',
  37. 'markdown' => ['content' => $d]
  38. ];
  39. HttpService::postRequest($url, json_encode($datas));
  40. return true;
  41. } catch (\Throwable $e) {
  42. Log::error('发送企业群消息失败,失败原因:' . $e->getMessage());
  43. }
  44. }
  45. }