feat(auth): 运行环境(生产/开发)+ 小程序码版本(体验版trial/正式版release)可配

- PINEAGENTS_ENV=prod|dev 判定运行环境; /auth/status 回显 env + wxacode_env 以便确认
- PINEAGENTS_WXACODE_ENV=release|trial|develop 决定小程序码指向(默认 prod→release, dev→trial=体验版)
- get_wxacode 用该 env_version(支持体验版测试)
This commit is contained in:
Pine
2026-08-26 12:21:30 +08:00
parent f697fdad37
commit fa06678e92
4 changed files with 22 additions and 2 deletions
+5 -2
View File
@@ -147,17 +147,20 @@ async def _wx_access_token() -> str:
return token
async def get_wxacode(scene: str, page: str = "pages/scan-login/index") -> bytes:
async def get_wxacode(scene: str, page: str = "pages/scan-login/index", env_version: str | None = None) -> bytes:
"""生成小程序码(wxacode)图片,扫码自动打开小程序指定页面并携带 scene。
env_versionrelease(正式版) | trial(体验版) | develop(开发版),默认取 config.WECHAT_WXACODE_ENV
(随 APP_ENVprod→releasedev→trial,可显式 PINEAGENTS_WXACODE_ENV 覆盖)。
scene 限 32 字符(本服务用短 token)。返回 PNG 字节。
"""
token = await _wx_access_token()
env = env_version or config.WECHAT_WXACODE_ENV
try:
async with httpx.AsyncClient(timeout=15) as client:
resp = await client.post(
_WX_ACODE_URL.format(token=token),
json={"scene": scene, "page": page, "check_path": False, "env_version": "release"},
json={"scene": scene, "page": page, "check_path": False, "env_version": env},
)
except Exception as exc: # noqa: BLE001
raise WechatError(f"wechat getwxacodeunlimit failed: {exc}") from exc