| 143 | } |
| 144 | |
| 145 | async login() { |
| 146 | if (this.token) { |
| 147 | $.log(`账号[${this.index}] 使用变量token: ${maskToken(this.token)}`); |
| 148 | return; |
| 149 | } |
| 150 | if (!this.account.openid) throw new Error("未配置 openid 或 token"); |
| 151 | |
| 152 | const code = await getWxCode(this.account.openid); |
| 153 | const res = await this.api(MAIN_HOST, "auth_wechatMini_authByCode", { code }, true); |
| 154 | const data = res.result || res.data || {}; |
| 155 | if (!data.token) throw new Error(`登录失败: ${short(res)}`); |
| 156 | |
| 157 | this.token = data.token; |
| 158 | this.openId = data.openId || this.openId; |
| 159 | this.user = data; |
| 160 | $.log( |
| 161 | `登录:成功 userId=${data.userId || "未知"} 手机=${maskPhone(data.mobile || "") || "未知"} openId=${data.openId || "未知"}` |
| 162 | ); |
| 163 | } |
| 164 | |
| 165 | async queryPoints() { |
| 166 | const res = await this.api(MEMBER_HOST, "member/getMemberPoints", {}, true); |