zx/crmeb/services/template/storage/Subscribe.php

86 lines
2.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace crmeb\services\template\storage;
use app\common\repositories\system\notice\SystemNoticeConfigRepository;
use app\common\repositories\wechat\TemplateMessageRepository;
use crmeb\basic\BaseMessage;
use crmeb\services\MiniProgramService;
use think\facade\Log;
/**
* 订阅消息
* Class Subscribe
* @package crmeb\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)
{
$tempkey = app()->make(SystemNoticeConfigRepository::class)->getSearch(['const_key' => $templateId])->find();
return $tempkey['routine_tempid'] ?? '';
}
/**
* 发送订阅消息
* @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 || !$this->openId) {
return ; //$this->setError('Template ID does not exist');
}
try {
$res = MiniProgramService::create()->sendSubscribeTemlate($this->openId, $tempid, $data, $this->toUrl);
$this->clear();
return $res;
} catch (\Throwable $e) {
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.
}
}