1、引入
2、需要到腾讯开放平台 http://open.qq.com/ --此处需要QQ登录小编就不详细介绍了
大家只需要拿到APP ID即可 剩下的注册过程可以省略
3、使用login方法
4、使用getUserInfo方法
小编此处附上代码,大家参考QQ登录部分即可,其他处理逻辑可以忽略。
html部分
<div class="aui-col-xs-3" style="text-align: center;" tapmode onclick="QQauth()">
<i class="iconfont icon-qq icon_bg1"></i>
<div class="aui-grid-label" style="display:block;margin-top:10px;">QQ</div>
</div>
js部分
//QQ登录
function QQauth () {
api.showProgress({
style: "default",
animationType: "fade",
title: "",
text: "启动中...",
modal: false
});
var qq = api.require("qq");
qq.login(function(ret, err) {
var openId=ret.openId,
accessToken=ret.accessToken;
$api.setStorage("QqOpenId", openId);
//获取QQ用户信息
api.hideProgress();
qq.getUserInfo(function(ret, err) {
if (ret.status) {
//昵称 头像
var nickname=ret.info.nickname,
head_pic=ret.info.figureurl_qq_2,
openid = $api.getStorage("QqOpenId");
source="QQ";
//将QQ用户信息添加入三方表
api.ajax({
url: domainName + "/index.php?g=User&m=Api&a=thirdLogin",
method: "post",
data: {
values: {
openid: openId,
nickname: nickname,
head_pic: head_pic,
source: source
}
}
}, function(ret, err) {
if (ret.msg == "0") { //已经存在该用户信息
if (ret.binding_status == "1") { /*1:未绑定 2已绑定*/
//未绑定,到绑定页面
api.openWin({
name: "user_binding_win",
url: "./user_binding_win.html",
pageParam: {
openid: openid,
source: source
}
});
} else {
//已绑定,到首页页面
userInfoAll(openid,source);
api.openWin({
name: "index",
url: "../main.html"
});
}
} else if (ret.msg == "1"){ //添加用户信息成功
api.openWin({
name: "user_binding_win",
url: "./user_binding_win.html",
pageParam: {
openid: openid
}
});
} else if (ret.msg =="2"){
api.toast({
msg: "添加用户失败",
duration: 2000,
location: "bottom"
});
} else {
api.toast({
msg: "未知错误",
duration: 2000,
location: "bottom"
});
}
});
} else {
api.toast({
msg: err.msg,
duration: 2000,
location: "middle"
});
}
});
});
}