12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- Page({
- dever: getApp().dever,
- data: {
- //判断小程序的API,回调,参数,组件等是否在当前版本可用。
- canIUse: wx.canIUse('button.open-type.getUserInfo')
- },
- onLoad: function (options) {
- // 查看是否授权
- wx.getSetting({
- success(res) {
- if (res.authSetting['scope.userInfo']) {
- // 已经授权,可以直接调用 getUserInfo 获取头像昵称
- wx.getUserInfo({
- success: function (res) {
- console.log(res.userInfo)
- }
- })
- }
- }
- })
- },
- //微信授权回调
- bindGetUserInfo: function (e) {
- var that = this;
- if (e.detail.userInfo) {
- console.log(e.detail.userInfo);
- wx.login({
- success: function (res) {
- if (res.code) {
- that.doLogin(res.code);
- } else {
- console.log(res.errMsg);
- }
- }
- })
- } else {
- console.log("拒绝了授权");
- }
- },
- doLogin: function(wxCode){
- var that = this;
- this.dever.request("/wxLogin", {code: wxCode}, {
- success: function (data, res) {
- that.dever.goBack();
- }
- }, "POST");
- }
- })
|