Small program authorization for less than the openid for the first time, after the need to recompile to earn,
The code is as follows:
This is authorized the code:
Wx. GetSetting ({
Success: the function (res) {
If (res) authSetting [' scope. The userInfo ']) {
Wx. GetUserInfo ({
Success: the function (res) {
That the setData ({
AvatarUrl: res. The userInfo. AvatarUrl,
The userInfo: res. The userInfo
}),
//the user has been authorized, do not need to display authorization page, so there's no need to change the value of isHide
//according to your own requirements are other operations add
//I am here is in after the success of the user authorization, call WeChat wx. Login interface to access code
Wx. Login ({
Success: res=& gt; {
//to get to the user's code: after res. Code
//the console. The log (" user code: "+ res. Code).
That the setData ({
Code: res. Code
}),
//request for openid
Wx. Request ({
Url: app. GlobalData. Url + '/appInterface getOpenid. Do? Code='+ res. Code,
//url: app. GlobalData. Url + '/appInterface getOpenid. Do,
Method: 'GET',
//data: {
//code: res. Code
//},
Header: {
'the content-type' : 'application/json'
},
Success: the function (ares) {
//sets the openid to all page can access
App. GlobalData. Openid=ares. Data. Obj
//the default request registered members
//wx. Request ({
//url: app. GlobalData. Url + '/appInterface/addUser. Do,
//data: {
//userOpenid: ares. Data. Obj,
//userNick: that data. The userInfo. NickName,
//userHadimag: that data. The userInfo. AvatarUrl
//},
//method: "POST",
//header: {
//'the content-type:' application/x - WWW - form - urlencoded '
//},
//success: function (bres) {
//}
//})
}
})
//authorization success to jump to the home page
Wx. ReLaunch ({
Url: '/pages/login/login'
})
}
});
}
});
} else {
//the user is not authorized
//change isHide value, showing authorization page
That the setData ({
IsHide: true
});
}
}
});
This is the first authorized go code:
BindGetUserInfo: function (e) {
If (e.d etail. The userInfo) {
//the user according to the authorized button allows
var that=this;
//to the user's information, and print to the console see
The console. The log (" user information is as follows: ");
The console. The log (e.d etail. The userInfo);
//after the success of the authorization, by changing the isHide value, to achieve page displayed, hide the authorization page
That the setData ({
IsHide: false
});
Wx. GetUserInfo ({
Success: the function (res) {
That the setData ({
AvatarUrl: res. The userInfo. AvatarUrl,
The userInfo: res. The userInfo
}),
//the user has been authorized, do not need to display authorization page, so there's no need to change the value of isHide
//according to your own requirements are other operations add
//I am here is in after the success of the user authorization, call WeChat wx. Login interface to access code
Wx. Login ({
Success: res=& gt; {
//to get to the user's code: after res. Code
The console. The log (" user code: "+ res. Code).
Wx. Request ({
Url: app. GlobalData. Url + '/appInterface getOpenid. Do? Code='+ res. Code,
//url: app. GlobalData. Url + '/appInterface getOpenid. Do,
Method: 'GET',
//data: {
//code: res. Code
//},
Header: {
'the content-type' : 'application/json'
},
Success: the function (ares) {
//sets the openid to all page can access
App. GlobalData. Openid=ares. Data. Obj
//the default request registered members
//wx. Request ({
//url: app. GlobalData. Url + '/appInterface/addUser. Do,
//data: {
//userOpenid: ares. Data. Obj,
//userNick: that data. The userInfo. NickName,
//userHadimag: that data. The userInfo. AvatarUrl
//},
//method: "POST",
//header: {
//'the content-type:' application/x - WWW - form - urlencoded '
//},
//success: function (bres) {
//}
//})
}
})
Wx. ReLaunch ({
Url: '/pages/login/login'
})
}
});
}
});
} else {
//the user press the reject button
Wx. ShowModal ({
Title: 'warning',
Content: 'you click to authorize, will not be able to enter the small program, and then enter please!!! '
ShowCancel: false,
ConfirmText: 'return authorization,
Success: the function (res) {
//the user is not authorized, do not need to change the value of isHide
If (res. Confirm) {
The console. The log (' users to click on the "return authorization");
}
}
});
}
},