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