()
| 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 { |
no test coverage detected