新增订阅消息队列+短信发送队列
This commit is contained in:
@@ -218,9 +218,8 @@ class Wechat
|
||||
}
|
||||
}
|
||||
|
||||
// 获取分享二维码
|
||||
|
||||
/**
|
||||
* 获取分享二维码
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -258,4 +257,83 @@ class Wechat
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前账号下订阅消息个人模版列表
|
||||
* @return array|string
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
*/
|
||||
public function getTemplate(): array|string
|
||||
{
|
||||
try {
|
||||
$this->createApp($this->config['app_id'], $this->config['secret']);
|
||||
|
||||
$client = $this->createClient($this->config['app_id'], $this->config['secret']);
|
||||
|
||||
$options = [];
|
||||
$response = $client->get('wxaapi/newtmpl/gettemplate', $options);
|
||||
if ($response->isFailed()) {
|
||||
// 出错了,处理异常
|
||||
$result = $response->toArray();
|
||||
if(empty($result)){
|
||||
// 返回值为空
|
||||
return [];
|
||||
}
|
||||
if (isset($result['errcode'])){
|
||||
throw new BusinessException();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
return $response->getContent(false);
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送订阅消息
|
||||
* @throws NotFoundExceptionInterface
|
||||
* @throws RedirectionExceptionInterface
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws DecodingExceptionInterface
|
||||
* @throws ClientExceptionInterface
|
||||
* @throws TransportExceptionInterface
|
||||
* @throws ServerExceptionInterface
|
||||
*/
|
||||
public function sendSubscribeMessage(array $options): array|string
|
||||
{
|
||||
try {
|
||||
$this->createApp($this->config['app_id'], $this->config['secret']);
|
||||
|
||||
$client = $this->createClient($this->config['app_id'], $this->config['secret']);
|
||||
|
||||
$response = $client->postJson('cgi-bin/message/subscribe/send', $options);
|
||||
|
||||
if ($response->isFailed()) {
|
||||
// 出错了,处理异常
|
||||
$result = $response->toArray();
|
||||
if(empty($result)){
|
||||
// 返回值为空
|
||||
throw new BusinessException("返回值为空");
|
||||
}
|
||||
if (isset($result['errcode'])){
|
||||
if ($result['errcode'] == 43101){
|
||||
throw new BusinessException("用户拒绝接收消息");
|
||||
}
|
||||
throw new BusinessException($result['errmsg']);
|
||||
}
|
||||
throw new BusinessException();
|
||||
}
|
||||
|
||||
return $response->getContent(false);
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException($e->getMessage(), HttpEnumCode::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user