EnterpriseWechatService.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\services\message\notice;
  12. use app\services\message\NoticeService;
  13. use app\jobs\notice\EnterpriseWechatJob;
  14. use think\facade\Log;
  15. /**
  16. * 企业微信发送消息
  17. * Created by PhpStorm.
  18. * User: xurongyao <763569752@qq.com>
  19. * Date: 2021/9/22 1:23 PM
  20. */
  21. class EnterpriseWechatService extends NoticeService
  22. {
  23. /**
  24. * 判断是否开启权限
  25. * @var bool
  26. */
  27. private $isopend = true;
  28. /**
  29. * 是否开启权限
  30. * @param string $mark
  31. * @return $this
  32. */
  33. public function isOpen(string $mark)
  34. {
  35. $this->isopend = $this->noticeInfo['is_ent_wechat'] == 1 && $this->noticeInfo['url'] !== '';
  36. return $this;
  37. }
  38. /**
  39. * 发送消息
  40. * @param $uid uid
  41. * @param array $data 模板内容
  42. */
  43. public function sendMsg($data)
  44. {
  45. try {
  46. if ($this->isopend) {
  47. $url = $this->noticeInfo['url'];
  48. $ent_wechat_text = $this->noticeInfo['ent_wechat_text'];
  49. EnterpriseWechatJob::dispatchDo('doJob', [$data, $url, $ent_wechat_text]);
  50. }
  51. } catch (\Exception $e) {
  52. Log::error($e->getMessage());
  53. return true;
  54. }
  55. }
  56. }