qq登陆返回的都是用户的基本信息。要怎么获取openid呢
7***@qq.com
- 发布:2018-01-29 12:49
- 更新:2018-09-28 17:04
- 阅读:2425
qq登陆怎么获取openid
分类:HBuilder
7***@qq.com (作者)
已解决
auth.login(function() {
auth.getUserInfo(function(authResult) {
var name = auth.userInfo.nickname || auth.userInfo.name;
app.createState(name, function() {
console.log(JSON.stringify(authResult));
var openid = authResult.target.authResult.openid;
var data = {
openid : openid,
};
loginUser_thirdpart(data);
});
}, function(e) {
plus.nativeUI.toast("获取用户信息失败:" + e.message);
});
waiting.close();
}, function(e) {
waiting.close();
plus.nativeUI.toast("登录认证失败:" + e.message);
});
请问是在哪里加入这一段啊,小白一个,不太懂,急需啊·。·
这是我的代码
mui.init({
swipeBack:true //启用右滑关闭功能
});
mui.plusReady(function() {
plus.oauth.getServices(function(services) {
auths = services;
}, function(e) {
alert("获取登录服务列表失败:" + e.message + " - " + e.code);
});
})
document.getElementById('weixin').addEventListener('tap',function() {
console.log("微信");
authLogin('weixin');
});
document.getElementById('qq').addEventListener('tap',function() {
console.log("QQ");
authLogin('qq');
});
// 登录操作
function authLogin(type) {
var s;
for (var i = 0; i < auths.length; i++) {
if (auths[i].id == type) {
s = auths[i];
break;
}
}
if (!s.authResult) {
s.login(function(e) {
mui.toast("登录认证成功!");
authUserInfo(type);
$('.login').hide();
}, function(e) {
mui.toast("登录认证失败!");
});
} else {
mui.toast("已经登录认证!");
}
}
//注销
function authLogout() {
for (var i in auths) {
var s = auths[i];
if (s.authResult) {
s.logout(function(e) {
console.log("注销登录认证成功!");
}, function(e) {
console.log("注销登录认证失败!");
});
}
}
}
// 微信登录认证信息
function authUserInfo(type) {
var s;
for (var i = 0; i < auths.length; i++) {
if (auths[i].id == type) {
s = auths[i];
break;
}
}
if (!s.authResult) {
mui.toast("未授权登录!");
} else {
auth.login(function() {
auth.getUserInfo(function(authResult) {
var name = auth.userInfo.nickname || auth.userInfo.name;
app.createState(name, function() {
console.log(JSON.stringify(authResult));
var openid = authResult.target.authResult.openid;
var data = {
openid : openid,
};
loginUser_thirdpart(data);
});
}, function(e) {
plus.nativeUI.toast("获取用户信息失败:" + e.message);
});
waiting.close();
}, function(e) {
waiting.close();
plus.nativeUI.toast("登录认证失败:" + e.message);
});
}
}