WechatTemplate.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\adminapi\controller\v1\application\wechat;
  12. use app\adminapi\controller\AuthController;
  13. use app\jobs\notice\SyncMessageJob;
  14. use app\services\message\SystemNotificationServices;
  15. use crmeb\exceptions\AdminException;
  16. use crmeb\services\app\WechatService;
  17. use think\facade\App;
  18. /**
  19. * 微信模板消息
  20. * Class WechatTemplate
  21. * @package app\adminapi\controller\v1\application\wechat
  22. */
  23. class WechatTemplate extends AuthController
  24. {
  25. /**
  26. * 构造方法
  27. * WechatTemplate constructor.
  28. * @param App $app
  29. * @param SystemNotificationServices $services
  30. */
  31. public function __construct(App $app, SystemNotificationServices $services)
  32. {
  33. parent::__construct($app);
  34. $this->services = $services;
  35. }
  36. /**
  37. * 同步微信模版消息
  38. * @return mixed
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function syncSubscribe()
  44. {
  45. if (!sys_config('wechat_appid') || !sys_config('wechat_appsecret')) {
  46. throw new AdminException(400248);
  47. }
  48. $tempIds = $this->services->getTempId('wechat');
  49. foreach ($tempIds as $v) {
  50. WechatService::deleleTemplate($v);
  51. }
  52. $tempKeys = $this->services->getTempKey('wechat');
  53. foreach ($tempKeys as $key => $content) {
  54. SyncMessageJob::dispatch('SyncWechat', [$key, $content['wechat_content']]);
  55. }
  56. return app('json')->success(100038);
  57. }
  58. }