|
@@ -5,45 +5,87 @@ Page({
|
|
|
canIUse: wx.canIUse('button.open-type.getUserInfo')
|
|
|
},
|
|
|
onLoad: function (options) {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ bindGetUserInfo: function (e) {
|
|
|
+ var that = this;
|
|
|
+ if (e.detail.userInfo) {
|
|
|
+ that.wxLogin();
|
|
|
+ } else {
|
|
|
+ that.dever.log("用户拒绝授权");
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ checkAuth: function(){
|
|
|
+ var that = this;
|
|
|
|
|
|
wx.getSetting({
|
|
|
+
|
|
|
+ withCredentials: true,
|
|
|
success(res) {
|
|
|
if (res.authSetting['scope.userInfo']) {
|
|
|
|
|
|
wx.getUserInfo({
|
|
|
success: function (res) {
|
|
|
- console.log(res.userInfo)
|
|
|
+ that.updateUserInfo(res);
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
-
|
|
|
- bindGetUserInfo: function (e) {
|
|
|
+
|
|
|
+
|
|
|
+ wxLogin: function(){
|
|
|
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);
|
|
|
+ wx.login({
|
|
|
+ success: function (res) {
|
|
|
+ if (res.code) {
|
|
|
+ that.dever.request("passport.applet.bind"
|
|
|
+ ,{
|
|
|
+ json: 1,
|
|
|
+ code: res.code
|
|
|
}
|
|
|
+ ,{
|
|
|
+ success: function (data, res) {
|
|
|
+ that.dever.saveLoginInfo(data);
|
|
|
+ that.checkAuth();
|
|
|
+ that.dever.goBack();
|
|
|
+ },
|
|
|
+ fail: function(res){
|
|
|
+ that.dever.log('wx.login', JSON.stringify(res));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ that.dever.log('wx.login', res.errMsg);
|
|
|
}
|
|
|
- })
|
|
|
- } else {
|
|
|
- console.log("拒绝了授权");
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
},
|
|
|
- doLogin: function(wxCode){
|
|
|
+
|
|
|
+
|
|
|
+ updateUserInfo: function (wxObj){
|
|
|
var that = this;
|
|
|
- this.dever.request("/wxLogin", {code: wxCode}, {
|
|
|
- success: function (data, res) {
|
|
|
- that.dever.goBack();
|
|
|
+ var userInfo = wxObj.userInfo;
|
|
|
+ var loginInfo = that.dever.getLoginInfo();
|
|
|
+ that.request('passport.applet.update'
|
|
|
+ ,{
|
|
|
+ nickname: userInfo.nickName,
|
|
|
+ avatarurl: userInfo.avatarUrl,
|
|
|
+ iv: wxObj.iv,
|
|
|
+ encryptedData: wxObj.encryptedData,
|
|
|
+ vid: loginInfo.vid,
|
|
|
+ uid: loginInfo.uid,
|
|
|
+ signature: loginInfo.signature
|
|
|
+ }
|
|
|
+ ,{
|
|
|
+ success: function(data, res){
|
|
|
+ that.derver.log('applet.update', '用户信息更新成功~');
|
|
|
}
|
|
|
- }, "POST");
|
|
|
+ }, 'POST');
|
|
|
}
|
|
|
|
|
|
})
|