fix: 修复 腾讯股票代码接口编码错误

This commit is contained in:
zhangxiangliang 2020-08-03 02:36:20 +08:00
parent f17a9bc71e
commit 23603be65c

View File

@ -5,6 +5,7 @@ import TencentExchangeTransform from "@stocks/tencent/transforms/exchange";
// Utils // Utils
import fetch from "@utils/fetch"; import fetch from "@utils/fetch";
import iconv from "@utils/iconv";
// Types // Types
import Stock from "types/stock"; import Stock from "types/stock";
@ -29,9 +30,9 @@ class Tencent extends Base {
// 数据获取 // 数据获取
const url = `https://qt.gtimg.cn/q=${transform}`; const url = `https://qt.gtimg.cn/q=${transform}`;
const res = await fetch.get(url); const res = await fetch.get(url).responseType('blob');
const body = res.text; const body = iconv.decode(res.body, "gbk");
const rows = body.split(";\n"); const rows = body.split(";\n");
const row = rows[0]; const row = rows[0];
@ -52,9 +53,9 @@ class Tencent extends Base {
// 数据获取 // 数据获取
const url = `https://qt.gtimg.cn/q=${transforms.join(',')}`; const url = `https://qt.gtimg.cn/q=${transforms.join(',')}`;
const res = await fetch.get(url); const res = await fetch.get(url).responseType('blob');
const body = res.text; const body = iconv.decode(res.body, "gbk");
const rows = body.split(";\n"); const rows = body.split(";\n");
return codes.map((code, index) => { return codes.map((code, index) => {