更新若干功能
Some checks failed
Tests / PHP 8.2 (push) Has been cancelled
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled

This commit is contained in:
2026-08-20 19:16:49 +08:00
parent 72bc6502eb
commit 4ddf5e3c5f
48 changed files with 1908 additions and 18 deletions

View File

@@ -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;
}
}
}