微信小程序开发微信小程序开发者微信小程序开发

基于玩安卓开放api的微信小程序

2018-12-07  本文已影响3人  Yun丶Lei

玩Android-小程序版

关注wanandroid有些时日了,一直以来也是鸿洋大神的粉丝,一直都有用他开放的api此前是使用kotlin完成了一个版本【wanandroid】,这次我们使用微信小程序完成一个版本。

没有申请公众号并且小程序只支持https所以不能发体验,仅作为交流之用,希望大家看的开心、玩的愉快~

简介

开发工具:小程序开发工具1.02.1811290---下载地址
调试基础版本:2.4.1

项目截图

1
2
3

部分功能解析

1、网络请求

加入ES6 Promise 封装网络请求,同时处理登录时候的cookie保存,并持久化

let request = (url, data, type) => new Promise((resolve, reject) => {
  wx.request({
    url: 'http://www.wanandroid.com' + url,
    data: data,
    method: type, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    header: {
      'content-type': 'application/x-www-form-urlencoded', // 默认值
      "cookie": wx.getStorageSync("cookie")
    },
    success: function(res) {
      // success
      if (res.data.errorCode === 0) {
        if (url == interfaces.INTERFACE_USER_LOGIN){
          wx.setStorageSync("cookie", res.header['Set-Cookie'])
        }
        resolve(res.data);
      } else {
        reject(res.data)
      }
    },
    fail: function(err) {
      // fail
      reject(err)
    },
    complete: function() {
      // complete
    }
  })
})

这样处理回调的时候就可以很简单的如下处理:

import api from "../../api/api.js";
api.IPostCollect(id)
  .then(res => {
    //success
  })
  .catch(e => {
    //fail
  })

版本信息

TODO

v1.0.0

TKS

License

Copyright 2018 YunLei

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

项目地址

https://github.com/leiyun1993/wanandroid-mini希望各位看官不吝Star~~~

上一篇 下一篇

猜你喜欢

热点阅读