| 59 | } |
| 60 | |
| 61 | async function getWxCode(appid, openid) { |
| 62 | if (!WX_AUTH) throw new Error("未配置 wx_auth"); |
| 63 | const { status, data } = await request({ |
| 64 | method: "POST", |
| 65 | url: `${WX_SERVER_URL}/wx/code`, |
| 66 | headers: { auth: WX_AUTH, "content-type": "application/json" }, |
| 67 | data: { appid, openid }, |
| 68 | }); |
| 69 | const code = data?.code || data?.data?.code || data?.phoneCode || data?.data?.phoneCode; |
| 70 | if (status !== 200 || !code) throw new Error(`获取code失败 HTTP ${status}: ${short(data)}`); |
| 71 | return code; |
| 72 | } |
| 73 | |
| 74 | class Tongcheng { |
| 75 | constructor(openid) { |