| 108 | } |
| 109 | |
| 110 | async function getWxCode(openid) { |
| 111 | if (!WX_AUTH) throw new Error("未配置 wx_auth,无法从 wx_server 获取 code"); |
| 112 | const { status, data } = await request({ |
| 113 | method: "POST", |
| 114 | url: `${WX_SERVER_URL}/wx/code`, |
| 115 | headers: { auth: WX_AUTH, "content-type": "application/json" }, |
| 116 | data: { appid: APP.appid, openid }, |
| 117 | }); |
| 118 | const code = data?.data?.code || data?.code; |
| 119 | if (status !== 200 || !code) throw new Error(`获取code失败 HTTP ${status}: ${short(data)}`); |
| 120 | return code; |
| 121 | } |
| 122 | |
| 123 | function loginSign({ appId, sessionId = "-1", openId, userId, postBody }) { |
| 124 | const reqId = md5(`${Math.random()} ${Date.now()}`); |