getTemplateCode($templateId); if (!$templateId) { return $this->setError('Template number does not exist'); } $tempid = Db::name('template_message')->where(['tempkey' => $templateId, 'status' => 1, 'type' => 1])->value('tempid'); if (!$tempid) { return $this->setError('Template ID does not exist'); } if (!$this->openId) { return $this->setError('Openid does not exist'); } try { $res = WechatService::sendTemplate($this->openId, $tempid, $data, $this->toUrl, $this->color); $this->clear(); return $res; } catch (\Exception $e) { $this->isLog() && Log::error('发送给openid为:' . $this->openId . '微信模板消息失败,模板id为:' . $tempid . ';错误原因为:' . $e->getMessage()); return $this->setError($e->getMessage()); } } /** * 获取所有模板 * @return \EasyWeChat\Support\Collection|mixed */ public function list() { return WechatService::noticeService()->getPrivateTemplates(); } /** * 添加模板消息 * @param string $shortId * @return \EasyWeChat\Support\Collection|mixed */ public function add(string $shortId) { return WechatService::noticeService()->addTemplate($shortId); } /** * 删除模板消息 * @param string $templateId * @return \EasyWeChat\Support\Collection|mixed */ public function delete(string $templateId) { return WechatService::noticeService()->deletePrivateTemplate($templateId); } }