123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- App({
- globalData: {
- showAnimation: true,
- id: null,
- name: null,
- },
- onLaunch(options) {
- console.log(options, "onLaunch");
- // if (wx.getStorageSync('openId')) {
- // wx.request({
- // url: 'http://info.windd.cn:8080/test/applet/isExist',
- // method: "GET",
- // data: {
- // appletsId: wx.getStorageSync('openId')
- // },
- // success: (res) => {
- // console.log(res, "000000000000000000");
- // if (res.data.code == 0) {
- // wx.switchTab({
- // url: '/pages/index/index',
- // })
- // }
- // }
- // })
- // } else {
- // }
- // wx.login({
- // success: res => {
- // // 获取到用户的 code 之后:res.code
- // console.log("用户的code:" + res.code);
- // const appid = "wx1c015df104db7030"
- // const secret = "d1956c1b5d3601657c98b0dc80a006f7"
- // let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
- // wx.request({
- // // 自行补上自己的 APPID 和 SECRET
- // url: url,
- // success: res => {
- // // 获取到用户的 openid
- // console.log("用户的openid:" + res.data.openid);
- // wx.setStorageSync('openId', res.data.openid)
- // wx.request({
- // url: 'http://info.windd.cn:8080/test/applet/isExist',
- // method: "GET",
- // data: {
- // appletsId: wx.getStorageSync('openId')
- // },
- // success: (res) => {
- // console.log(res, "apppppppppppppppppppppppppp");
- // if (res.data.code == 0) {
- // if(res.data.data){
- // wx.setStorageSync('user', 'user');
- // }
- // }
- // }
- // })
- // }
- // });
- // }
- // });
- },
- onShow(options) {
- // Do something when show.
- },
- onHide() {
- // Do something when hide.
- },
- onError(msg) {
- console.log(msg)
- },
- getAuthKey: function () {
- var that = this;
- return new Promise(function (resolve, reject) {
- // 调用登录接口
- wx.login({
- success: function (res) {
- if (res.code) {
- console.log("用户的code:" + res.code);
- const appid = "wx1c015df104db7030"
- const secret = "d1956c1b5d3601657c98b0dc80a006f7"
- let url = 'https://api.weixin.qq.com/sns/jscode2session?appid=' + appid + '&secret=' + secret + '&js_code=' + res.code + '&grant_type=authorization_code';
- wx.request({
- // 自行补上自己的 APPID 和 SECRET
- url: url,
- success: res => {
- // 获取到用户的 openid
- console.log("用户的openid:" + res.data.openid);
- wx.setStorageSync('openId', res.data.openid)
- wx.request({
- url: 'http://10.16.4.7:7001/applet/isExist',
- method: "GET",
- data: {
- appletsId: wx.getStorageSync('openId')
- },
- success: (res) => {
- console.log(res, "apppppppppppppppppppppppppp");
- if (res.data.code == 0) {
- if (res.data.data) {
- wx.setStorageSync('user', 'user');
- }
- resolve(res);
- }
- }
- })
- }
- });
- } else {
- console.log('获取用户登录态失败!' + res.errMsg);
- var res = {
- status: 300,
- data: '错误'
- }
- reject('error');
- }
- }
- })
- });
- },
- })
|