TemplateJob.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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;
  12. use app\services\message\SystemNotificationServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\services\CacheService;
  15. use crmeb\services\template\Template;
  16. use crmeb\traits\QueueTrait;
  17. use think\facade\Log;
  18. use think\facade\Route;
  19. /**
  20. * Class TemplateJob
  21. * @package app\jobs
  22. */
  23. class TemplateJob extends BaseJobs
  24. {
  25. use QueueTrait;
  26. /**
  27. * @param $type
  28. * @param $openid
  29. * @param $tempCode
  30. * @param $data
  31. * @param $link
  32. * @param $color
  33. * @return bool|mixed
  34. */
  35. public function doJob($type, $openid, $tempId, $data, $link, $color)
  36. {
  37. try {
  38. if (!$openid) return true;
  39. $template = new Template($type ?: 'wechat');
  40. $template->to($openid);
  41. if ($color) {
  42. $template->color($color);
  43. }
  44. if ($link) {
  45. switch ($type) {
  46. case 'wechat':
  47. $link = sys_config('site_url') . Route::buildUrl($link)->suffix('')->domain(false)->build();
  48. break;
  49. default:
  50. break;
  51. }
  52. $template->url($link);
  53. }
  54. return $template->send($tempId, $data);
  55. } catch (\Exception $e) {
  56. Log::error($e->getMessage());
  57. return true;
  58. }
  59. }
  60. }