SendTemplateMessageJob.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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\jobs;
  12. use crmeb\interfaces\JobInterface;
  13. use think\facade\Log;
  14. use think\queue\Job;
  15. use crmeb\services\WechatTemplateService;
  16. use app\common\repositories\user\UserRepository;
  17. use crmeb\services\WechatTemplateMessageService;
  18. class SendTemplateMessageJob implements JobInterface
  19. {
  20. public function fire($job, $data)
  21. {
  22. $make = app()->make(WechatTemplateMessageService::class);
  23. try{
  24. $make->sendTemplate($data);
  25. }catch (\Exception $e){
  26. Log::info('公众号消息模板:' . $e->getMessage());
  27. }
  28. try{
  29. $make->subscribeSendTemplate($data);
  30. }catch (\Exception $e){
  31. Log::info('小程序消息模板:' . $e->getMessage());
  32. }
  33. $job->delete();
  34. }
  35. public function failed($data)
  36. {
  37. // TODO: Implement failed() method.
  38. }
  39. }