小程序校验机制

openid与token放入缓存中

wx.login({
      success (res) {
        console.log(res.code)
        if (res.code) {
          wx.request({
            url: '',
            data:{code:res.code},
            header:{
            //从缓存中获取token
              'token': wx.getStorageSync('token')
            },
            succ
            success(res){
              console.log(res)
              //把openid与token放入缓存中
              wx.setStorageSync('openid', res.data.openid)
              wx.setStorageSync('token', res.data.token)
            }
          })
        } else {
          console.log('登录失败!' + res.errMsg)
        }
      }
    })

轮播图

<view class="page-section page-section-spacing swiper">
      <swiper indicator-dots="true"
        autoplay="true" interval="2000" duration="500">
        <block wx:for="{{img}}">
          <swiper-item>
            <image src="{{item.image}}"></image>
          </swiper-item>
        </block>
      </swiper>
    </view>

获取之前存的token

wx.request({
      url: 'http://www.tp.com/admin/logins/slideshow',
      header:{
        'token':wx.getStorageSync('token')
      },
      success (res) {
        a.setData({img:res.data.data})
      }
    })
public function slideshow()
    {
        //获取请求header中的token
        $token = $_SERVER['HTTP_TOKEN'];
        if($this->checkToken($token)){//调用本类方法
            $data = file::select()->toArray();
            return json(['data'=>$data,'msg'=>'','code'=>0]);
        }
    }

中间件的位置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值