1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace ln\services\template\storage;
- use app\common\repositories\wechat\TemplateMessageRepository;
- use ln\basic\BaseMessage;
- use ln\services\MiniProgramService;
- use think\facade\Log;
- /**
- * 订阅消息
- * Class Subscribe
- * @package ln\services\template\storage
- */
- class Subscribe extends BaseMessage
- {
- protected function initialize(array $config)
- {
- parent::initialize($config); // TODO: Change the autogenerated stub
- }
- /**
- * @param string $templateId
- * @return mixed
- */
- public function getTempId(string $templateId)
- {
- return app()->make(TemplateMessageRepository::class)->getTempId($templateId, 0);
- }
- /**
- * 发送订阅消息
- * @param string $templateId
- * @param array $data
- * @return bool|\EasyWeChat\Support\Collection|mixed|null
- */
- public function send(string $templateId, array $data = [])
- {
- $templateId = $this->getTemplateCode($templateId);
- if (!$templateId) {
- return ; //$this->setError('Template number does not exist');
- }
- $tempid = $this->getTempId($templateId);
- if (!$tempid) {
- return ; //$this->setError('Template ID does not exist');
- }
- if (!$this->openId) {
- return ; //$this->setError('Openid does not exist');
- }
- try {
- $res = MiniProgramService::create()->sendSubscribeTemlate($this->openId, $tempid, $data, $this->toUrl);
- $this->clear();
- return $res;
- } catch (\Throwable $e) {
- $this->isLog() && Log::error('发送给openid为:' . $this->openId . '小程序订阅消息失败,模板id为:' . $tempid . ';错误原因为:' . $e->getMessage());
- return $this->setError($e->getMessage());
- }
- }
- public function delete(string $templateId)
- {
- // TODO: Implement delete() method.
- }
- public function add(string $shortId)
- {
- // TODO: Implement add() method.
- }
- public function list()
- {
- // TODO: Implement list() method.
- }
- }
|