更新若干功能
This commit is contained in:
@@ -91,4 +91,32 @@ class WxMiniService
|
||||
$redis->set($app['app_id'], $result['access_token'], max(60, (int) ($result['expires_in'] ?? 7200) - 300));
|
||||
return (string) $result['access_token'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送订阅消息。模板字段必须与公众平台里的关键词一致,对不上微信会拒收。
|
||||
* 这里只尽力发送,失败不抛错,避免挡住收款/发货。
|
||||
*/
|
||||
public function sendSubscribe(string $openId, string $templateId, string $page, array $data): bool
|
||||
{
|
||||
if ($openId === '' || $templateId === '') {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
$token = $this->accessToken();
|
||||
$result = Http::asJson()->post(
|
||||
$this->baseUrl . 'cgi-bin/message/subscribe/send?access_token=' . $token,
|
||||
[
|
||||
'touser' => $openId,
|
||||
'template_id' => $templateId,
|
||||
'page' => $page,
|
||||
'data' => $data,
|
||||
'miniprogram_state' => 'formal',
|
||||
'lang' => 'zh_CN',
|
||||
]
|
||||
)->json();
|
||||
return empty($result['errcode']);
|
||||
} catch (\Throwable) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user