| 215 | } |
| 216 | |
| 217 | function StartExchange(account, product, num, attempt) { |
| 218 | const opts = { |
| 219 | url: 'https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange', |
| 220 | headers: { |
| 221 | "User-Agent": "comic-universal/3412 CFNetwork/1410.0.3 Darwin/22.6.0 os/ios model/iPhone 12 mobi_app/iphone_comic build/3412 osVer/16.6 network/2 channel/AppStore", |
| 222 | "Content-Type": "application/json", |
| 223 | "Cookie": account.cookie |
| 224 | }, |
| 225 | body: JSON.stringify({ |
| 226 | product_id: product.id, |
| 227 | product_num: num, |
| 228 | point: num * product.real_cost |
| 229 | }), |
| 230 | throwHttpErrors: false |
| 231 | }; |
| 232 | |
| 233 | $.debug(`Send Exchange request (attempt ${attempt + 1}):`, $.toStr(opts, null, null, 1)); |
| 234 | |
| 235 | return $.http.post(opts) |
| 236 | .then((resp) => { |
| 237 | $.debug(`Receive Exchange response (attempt ${attempt + 1}):`, $.toStr(resp, null, null, 1)); |
| 238 | const body = JSON.parse(resp.body?.startsWith('{') && resp.body || '{}'); |
| 239 | if (body.code == 0) { |
| 240 | return { success: true, message: '兑换成功' }; |
| 241 | } else { |
| 242 | return { success: false, message: body.msg || '未知错误' }; |
| 243 | } |
| 244 | }) |
| 245 | .catch((err) => { |
| 246 | $.error(`Exchange error (attempt ${attempt + 1}):`, err); |
| 247 | return { success: false, message: err.message || '请求失败' }; |
| 248 | }); |
| 249 | } |
| 250 | |
| 251 | function getTodayFlag() { |
| 252 | const now = new Date(); |