admin 发表于 2019-1-21 15:47:27

用聚合数据API(苏州实时公交API)快速写出小程序

利用聚合数据API快速写出小程序,过程简单。1、申请小程序账号2、进入开发3、调用API。比如“苏州实时公交”小程序,选择的是苏州实时公交API。 苏州实时公交API文档:https://www.juhe.cn/docs/api/id/31https://images2015.cnblogs.com/blog/909818/201701/909818-20170110141537572-1061339349.gif如下,是“苏州实时公交”小程序调用代码:https://common.cnblogs.com/images/copycode.gif
var url = "https://apis.juhe.cn/szbusline/bus";    //为了您的密钥安全,建议使用服务端代码中转请求,事例代码可参考 https://code.juhe.cn/    var apiKey = "yourKey";    //输入自己的key    Page({      data: {      inputValue: '',      restation: [],      condition: true      },      //获取输入框的值      bindInput: function(e) {      var that = this;      that.setData({          inputValue: e.detail.value      });      },    //点击搜索按钮调用的函数      search:function(e){      var that = this;      //数据加载完成之前,显示加载中提示框      wx.showToast({          title: '加载中。。。',          icon: 'loading',          duration: 10000      });      //输入框没有输入的判断      if(that.data.inputValue == ''){            wx.hideToast();            return;      }      //发起请求,注意 wx.request发起的是 HTTPS 请求      wx.request({          url: url + "?station=" + that.data.inputValue + "&key=" + apiKey,          data: {},          header: {            'content-type': 'application/json'          },          success: function(res) {            var data = res.data;            //将数据从逻辑层发送到视图层,同时改变对应的 this.data 的值            that.setData({            restation: data.result,            condition: false            });            //数据加载成功后隐藏加载中弹框            wx.hideToast();          }      })      }    })https://common.cnblogs.com/images/copycode.gif



4、完整源码下载提供“苏州实时公交”小程序的完整源码下载,可以通过完整的源码,更好的学习如何通过调用聚合API,快速实现编写小程序。下载“苏州实时公交”小程序代码:https://juheimg.oss-cn-hangzhou.aliyuncs.com/www/activity/wx/juhewx.zip
页: [1]
查看完整版本: 用聚合数据API(苏州实时公交API)快速写出小程序