RoutineTemplateService.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 crmeb\services;
  12. use app\common\repositories\wechat\WechatUserRepository;
  13. use crmeb\services\template\Template;
  14. /**
  15. * Class WechatTemplateService
  16. * @package crmeb\services
  17. * @author xaboy
  18. * @day 2020-04-20
  19. */
  20. class RoutineTemplateService
  21. {
  22. /**
  23. * 发送模板消息
  24. * @param string $tempCode
  25. * @param int $uid 用户uid
  26. * @param array $data 模板内容
  27. * @param string $link 跳转链接
  28. * @return bool
  29. */
  30. public function sendTemplate(string $tempCode, $uid, array $data, string $link = '')
  31. {
  32. try {
  33. $openid = app()->make(WechatUserRepository::class)->idByOpenId((int)$uid);
  34. if (!$openid) return true;
  35. $template = new Template('subscribe');
  36. return $template->to($openid)->url($link)->send($tempCode, $data);
  37. } catch (\Exception $e) {
  38. return true;
  39. }
  40. }
  41. }