微信小程序-基金查询服务

时间:2024-03-07 19:16:44

基金小程序

全量基金公司列表

演示

接口1-获取全量基金公司列表数据

请求代码

//仅列举部分代码
	wx.request({
      url: "http://fund.eastmoney.com/js/jjjz_gs.js",
      data: {
      },
      method: \'GET\', 
      header: {
        "Content-Type": "application/json"
      },
      success: (res) => {
        if(200 == res.statusCode) {
          var cpList = JSON.parse(res.data.split(\'=\')[1].replace("op:","").replace(\'{\',\'\').replace(\'}\',\'\'));
          this.setData({
            companyList : cpList,
            updateTime: res.header[\'Last-Modified\']
          });
        } else {
          console.error(res.errMsg);
        }
        wx.stopPullDownRefresh();
      },
      fail: function() {
      }
    })

全量基金列表

演示

接口2-获取全量基金列表

请求代码

wx.request({
      url: "http://fund.eastmoney.com/js/fundcode_search.js",
      data: {
      },
      method: \'GET\', 
      header: {
        "Content-Type": "application/json"
      },
      success: (res) => {
        if(200 == res.statusCode) {
          let cpList = res.data.split(\'= \')[1].replace("[[","[").replace("]];","]");
          this.setData({
            allList: cpList,
            updateTime: res.header[\'Last-Modified\'],
          });
          this.setDateSize();
        } else {
          console.error(res.errMsg);
        }
      },
      fail: function() {
      }
    })
	
	
	setDateSize: function() {
    //初始化变量
    let cpList = this.data.allList;
    let page = this.data.page;
    let initSize = this.data.initSize;
    //数据格式转换
    let cppList = "";
    for(let i = (page-1)*initSize;i<page*initSize;i++) {
      if(undefined == cpList.split(",[")[i]) {
        break;
      }
      cppList += cpList.split(",[")[i];
    }
    //判断是否为尾页
    if("" == cppList || null == cppList || undefined == cppList) {
      Toast.fail("已经是最后一页啦~");
      let nextPage = this.data.page - 1;
      this.setData({
        page: nextPage
      })
      return;
    }
    if(1 != page) cppList = "[[" + cppList;
    else cppList = "[" + cppList;
    cppList += "]";
    cppList = cppList.replaceAll("]\"","],[\"");
    //转为json对象
    cpList = JSON.parse(cppList);
    this.setData({
      jList: cpList
    })
  }

我的关注列表

演示

接口3-获取基金估值信息

jsonpgz({"fundcode":"161725","name":"招商中证白酒指数(LOF)","jzrq":"2021-03-11","dwjz":"1.2119","gsz":"1.2167","gszzl":"0.40","gztime":"2021-03-12 15:00"});
应答参数 说明
fundcode 基金代码
name 基金名称
jzrq 净值日期
dwjz 当日净值
gsz 估算净值
gszzl 估算涨跌百分比
gztime 估值时间

请求代码

wx.request({
        url: url,
        method: \'GET\', 
        success: (res) => {
          if(200 == res.statusCode) {
            let objStr = res.data.replaceAll("jsonpgz({","{").replaceAll("});", "}");
            objStr = JSON.parse(objStr);
            this.setData({
              name: objStr.name,
              jzrq: objStr.jzrq,
	          dwjz: objStr.dwjz,
              gsz: objStr.gsz,
              gszzl: objStr.gszzl,
              gztime: objStr.gztime,
            })
          } else {
            console.error(res.errMsg);
          }
        },
        fail: function() {
        }
})

基金实时估值

演示

接口4-获取基金详情信息(含近几年趋势数据)

接口5-基金当日实时估值走势图

图片地址: http://j4.dfcfw.com/charts/pic6/161725.png
在线预览:
image