MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / loginByWxCode

Method loginByWxCode

wxapp/dasenlin.js:188–225  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

186 }
187
188 async loginByWxCode() {
189 try {
190 const code = await this.getLoginCode();
191 const result = await axios.request({
192 method: "POST",
193 url: `${CRM_BASE}/member-center/entrance/registryByWeiXinCode`,
194 headers: this.getHeaders(),
195 data: {
196 code,
197 storeNo: "",
198 },
199 timeout: 20000,
200 validateStatus: () => true,
201 });
202 if (result.status !== 200) throw new Error(`HTTP ${result.status}: ${JSON.stringify(result.data)}`);
203 const body = result.data;
204 if (!isSuccess(body)) throw new Error(getMessage(body));
205 const data = body.data || {};
206 this.token = data.token || "";
207 const crm = data.crmMemberInfo || {};
208 const third = data.miniUserThirdVo || {};
209 this.userInfo = {
210 id: data.id || crm.id || "",
211 name: crm.name || crm.nickName || data.nickName || "",
212 phone: crm.phone || crm.mobile || data.phone || data.mobile || "",
213 mobile: crm.mobile || crm.phone || data.mobile || data.phone || "",
214 tier: crm.tier || data.tier || "",
215 point: crm.point || data.point || "",
216 openId: third.openId || "",
217 unionId: third.unionId || "",
218 };
219 if (!this.token) throw new Error(`登录响应未返回token: ${JSON.stringify(body)}`);
220 this.saveCachedToken();
221 $.log(`账号[${this.index}] 登录成功${this.userInfo.phone ? `: ${maskPhone(this.userInfo.phone)}` : ""}`);
222 } catch (e) {
223 $.log(`账号[${this.index}] 登录失败: ${e.message || e}`);
224 }
225 }
226
227 async checkToken() {
228 try {

Callers 1

runMethod · 0.95

Calls 8

getLoginCodeMethod · 0.95
getHeadersMethod · 0.95
saveCachedTokenMethod · 0.95
getMessageFunction · 0.85
isSuccessFunction · 0.70
maskPhoneFunction · 0.70
requestMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected