MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / getWxCode

Function getWxCode

wxapp/aima.js:121–150  ·  view source on GitHub ↗
(account)

Source from the content-addressed store, hash-verified

119}
120
121async function getWxCode(account) {
122 const wxServerUrl = process.env.wx_server_url;
123 const wxAuth = process.env.wx_auth;
124 if (!wxServerUrl || !wxAuth) {
125 throw new Error("未配置 wx_server_url 或 wx_auth,无法获取code登录");
126 }
127
128 const res = await axios.post(
129 `${wxServerUrl.replace(/\/$/, "")}/wx/getuserinfo`,
130 {
131 appid: MINI_APPID,
132 openid: account,
133 },
134 {
135 headers: {
136 auth: wxAuth,
137 "content-type": "application/json",
138 },
139 timeout: 15000,
140 validateStatus: () => true,
141 }
142 );
143
144 const code = res.data?.code || res.data?.data?.code;
145 if (res.status !== 200 || !code) {
146 throw new Error(`获取code失败: HTTP ${res.status} ${JSON.stringify(res.data)}`);
147 }
148
149 return code;
150}
151
152async function loginByCode(account) {
153 $.log("🔐 正在获取code并登录...");

Callers 1

loginByCodeFunction · 0.70

Calls 1

postMethod · 0.45

Tested by

no test coverage detected