小程序快递查询

写的是查顺丰的,别人家的快递也一样。
百度的apistore封了,聚合数据的api也可以用,不过有次数限制,最后选了快递100,非常感谢lilydedbb提供的api!
另外,一直报错域名不合法,我在这里卡了很久,需要在设置里把网站的域名添加进request名单里,然后在开发工具里刷新。且一个月只能添加三次域名,无形中又限制了开发的次数。
//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    motto: 'Hello World',
    userInfo: {},
    expressNu:null,
    expressInfo:null
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  btnClick : function(){
    //console.log(this.data.expressNu)
    var thispage = this;
    app.getExpressInfo(this.data.expressNu,function(data){
        console.log(data)
        thispage.setData({expressInfo:data})
    });
  },
  input : function(e){
    this.setData({expressNu:e.detail.value})
  },
  onLoad: function () {
    console.log('onLoad')
    var that = this
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})

<!--index.wxml-->
<view class="container">
  <input placeholder="请输入运单号" bindinput="input" />
  <button type="primary"  bindtap="btnClick"> 查询 </button>


  <scroll-view scroll-y="true" style="height: 200px;" >
      <view wx:for="{{expressInfo.data}}">
          {{item.context}} 【 {{item.ftime}}】\n
      </view>
   </scroll-view>

</view>

/**index.wxss**/
input{
  border: 1px solid red;
  width: 90%;
  margin: 5%;
  padding: 5px;
}

//app.js
App({
  onLaunch: function () {
    //调用API从本地缓存中获取数据
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
  },
  getUserInfo:function(cb){
    var that = this
    if(this.globalData.userInfo){
      typeof cb == "function" && cb(this.globalData.userInfo)
    }else{
      //调用登录接口
      wx.login({
        success: function () {
          wx.getUserInfo({
            success: function (res) {
              that.globalData.userInfo = res.userInfo
              typeof cb == "function" && cb(that.globalData.userInfo)
            }
          })
        }
      })
    }
  },

 getExpressInfo:function(nu,cb){
   wx.request({
     url: 'https://www.kuaidi100.com/query',
     data:{
      'type':'shunfeng',
      'postid':nu
     },
      success: function(res) {
       // console.log(res.data)
       cb(res.data)
      }
    })

 },


  globalData:{
    userInfo:null
  }
})



  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值