| 69 | } |
| 70 | |
| 71 | async function getWxCode(appid, openid) { |
| 72 | if (!WX_AUTH) throw new Error("未配置 wx_auth"); |
| 73 | const { status, data } = await request({ |
| 74 | method: "POST", |
| 75 | url: `${WX_SERVER_URL}/wx/code`, |
| 76 | headers: { auth: WX_AUTH, "content-type": "application/json" }, |
| 77 | data: { appid, openid }, |
| 78 | }); |
| 79 | const code = data?.code || data?.data?.code || data?.phoneCode || data?.data?.phoneCode; |
| 80 | if (status !== 200 || !code) throw new Error(`获取code失败 HTTP ${status}: ${short(data)}`); |
| 81 | return code; |
| 82 | } |
| 83 | |
| 84 | class FeiheMom { |
| 85 | constructor(openid) { |