* @description 获取答案
(question)
| 336 | * @description 获取答案 |
| 337 | */ |
| 338 | async function getAnswer(question) { |
| 339 | // 数据 |
| 340 | const data = { |
| 341 | txt_name: md5(question), |
| 342 | password: '', |
| 343 | }; |
| 344 | try { |
| 345 | const params = new URLSearchParams(data); |
| 346 | // 请求 |
| 347 | const res = await fetch(API_CONFIG.answerSearch, { |
| 348 | method: 'POST', |
| 349 | mode: 'cors', |
| 350 | headers: { |
| 351 | 'Content-Type': 'application/x-www-form-urlencoded', |
| 352 | }, |
| 353 | body: params.toString(), |
| 354 | }); |
| 355 | // 请求成功 |
| 356 | if (res.ok) { |
| 357 | const result = await res.json(); |
| 358 | const { data, status } = result; |
| 359 | if (status !== 0) { |
| 360 | // 答案列表 |
| 361 | const answerList = JSON.parse(data.txt_content); |
| 362 | // 答案 |
| 363 | const answers = answerList[0].content.split(/[;\s]/); |
| 364 | return answers; |
| 365 | } |
| 366 | } |
| 367 | } |
| 368 | catch (error) { } |
| 369 | return []; |
| 370 | } |
| 371 | /** |
| 372 | * @description 保存答案 |
| 373 | */ |