apiCloud授权绑定第三方账号,微信、QQ、微博。
生活随笔
收集整理的這篇文章主要介紹了
apiCloud授权绑定第三方账号,微信、QQ、微博。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.檢測軟件是否安裝
2.授權獲取code
3.獲取token,openid等
4.獲取頭像昵稱
var wx,qq,weibo; var loginParam={}; apiready = function () {fix_status_bar();var user = $api.getStorage('user');var customerId = user.customer_id;var memberId = user.member_id;// 獲取第三方綁定信息api.ajax({url: BASE_REQUEST_URL+'/Customer/GetExternal',method: 'post',data: {values: {customerId: customerId,memberId: memberId}}}, function(json, err) {if (json.result) {var interText = doT.template($("#info_tmpl").text());$("#info_area").html(interText(json.info));} else {var toast = new auiToast();toast.fail({title: json.msg,duration: 2000});}});}function initWxBind() {wx = api.require('wx');wx.isInstalled(function(ret, err) {if (!ret.installed) {alert('當前設備未安裝微信客戶端');} else {wx.auth(function(ret, err) {if (ret.status) {wx.getToken({code: ret.code}, function(ret, err) {if (ret.status) {api.showProgress({style: 'default',animationType: 'fade',title: '授權成功',text: '綁定處理中...',modal: true});var provideName="wx_" + BASE_APP_TYPE;//臨時存儲openId,與accessToken后面綁定賬號時用到(綁定用完需要清理掉)loginParam.provideName=provideName;loginParam.openId=ret.openId;loginParam.accessToken=ret.accessToken;loginParam.refreshToken=ret.dynamicToken;$api.setStorage('loginParam', loginParam);//獲取wx頭像,昵稱wx.getUserInfo({accessToken: ret.accessToken,openId: ret.openId}, function(ret, err) {if (ret.status) {// 綁定成功var loginParam=$api.getStorage('loginParam');loginParam.nickName=ret.nickname;loginParam.avatar=ret.headimgurl;$api.setStorage('loginParam', loginParam);// 實現綁定動作bindAccount(function (res) {if (res == true) {// 發送頁面刷新事件var toast = new auiToast();toast.success({title: "綁定成功",duration: 2000});setTimeout("location.reload()", 2000);}});api.hideProgress();}});} else {alert(JSON.stringify(err))}});} else {var toast = new auiToast();toast.fail({title: "微信授權綁定失敗",duration: 1500});}});}}); }function initQQBind() {qq = api.require('qq');qq.login(function(ret, err) {if (ret.status) {api.showProgress({style: 'default',animationType: 'fade',title: '授權成功',text: '綁定處理中...',modal: true});var provideName="qq_" + BASE_APP_TYPE;loginParam.provideName=provideName;loginParam.openId=ret.openId;loginParam.accessToken=ret.accessToken;$api.setStorage('loginParam', loginParam);//獲取qq頭像,昵稱qq.getUserInfo(function(ret, err) {if (ret.status) {// 綁定成功var loginParam=$api.getStorage('loginParam');loginParam.nickName=ret.info.nickname;loginParam.avatar=ret.info.figureurl_qq_2;$api.setStorage('loginParam', loginParam);//實現綁定動作bindAccount(function (res) {if (res == true) {// 發送頁面刷新事件var toast = new auiToast();toast.success({title: "綁定成功",duration: 2000});setTimeout("location.reload()", 2000);}});api.hideProgress();}});} else {var toast = new auiToast();toast.fail({title: "授權失敗",duration: 1500});}}); }function initWbBind() {weibo = api.require('weibo');weibo.auth(function(ret, err) {//alert(JSON.stringify(ret));if (ret.status) {api.showProgress({style: 'default',animationType: 'fade',title: '授權成功',text: '綁定處理中...',modal: true});var provideName="wb_" + BASE_APP_TYPE;//臨時存儲openId,與accessToken后面綁定賬號時用到(綁定用完需要清理掉)loginParam.provideName=provideName;loginParam.openId=ret.userId;loginParam.accessToken=ret.token;$api.setStorage('loginParam', loginParam);//獲取微博頭像,昵稱weibo.getUserInfo(function(ret,err){if (ret.status) {// 綁定成功var loginParam=$api.getStorage('loginParam');loginParam.nickName=ret.userInfo.screen_name;loginParam.avatar=ret.userInfo.avatar_large;$api.setStorage('loginParam', loginParam);// 實現綁定動作bindAccount(function (res) {if (res == true) {// 發送頁面刷新事件var toast = new auiToast();toast.success({title: "綁定成功",duration: 2000});setTimeout("location.reload()", 2000);}});api.hideProgress();}});}else {var toast = new auiToast();toast.fail({title: "授權失敗",duration: 1500});}}); }// 解除綁定 function removeAuth(externalId) {var user = $api.getStorage('user');var customerId = user.customer_id;// 獲取第三方綁定信息api.ajax({url: BASE_REQUEST_URL+'/Customer/RemoveAuthentication',method: 'post',data: {values: {customerId: customerId,externalId:externalId}}}, function(json, err) {if (json.result) {var toast = new auiToast();toast.success({title: '解綁成功',duration: 2000});setTimeout("location.reload();", 2000);} else {var toast = new auiToast();toast.fail({title: json.msg,duration: 2000});}});}function bindAccount(callback) {var loginParam = $api.getStorage('loginParam');var user = $api.getStorage('user');api.ajax({url: BASE_REQUEST_URL + '/Customer/AssociateAccountWithExistCustomer',method: 'post',data: {values: {provideName: loginParam.provideName,openId: loginParam.openId,accessToken: loginParam.accessToken,refreshToken: loginParam.refreshToken,userName: user.login_name,nickName: loginParam.nickName,avatar: loginParam.avatar,}}}, function(ret, err) {if (ret.status == 1) {callback(true);}callback(false);}); }function showAction() {var dialogBox = api.require('dialogBox');dialogBox.actionMenu ({tapClose: true, // 點擊關閉rect:{h: 150},texts:{cancel: '取消'},items:[{text: '綁定微信',icon: 'widget://image/share_wx.png'},{text: '綁定QQ',icon: 'widget://image/share_qq.png'},{text: '綁定微博',icon: 'widget://image/share_wb.png'},],styles:{bg:'#FFF',column: 3,itemText: {color: '#000',size: 12,marginT:8},itemIcon:{size:50},cancel:{bg: 'fs://icon.png',color:'#000',h: 44 ,size: 14}}}, function(ret){if (ret.index == '0') { // 微信initWxBind();dialogBox.close();}if (ret.index == '1') { // QQinitQQBind();dialogBox.close();}if (ret.index == '2') { // 微博initWbBind();dialogBox.close();}if (ret.eventType == 'cancel') {dialogBox.close();}}); }確保已經有這些數據申請,申請要些時日。
<feature name="wx"> <param name="urlScheme" value="wx65fbcf8b5a4765cc"/> <param name="apiKey" value="wx65fbcf8b5a4765cc"/> <param name="apiSecret" value="6f9e7a1cb328745de623263c18773368"/> </feature> <feature name="qq"> <param name="urlScheme" value="tencent1105688283"/> <param name="apiKey" value="1105688283"/> </feature> <feature name="weibo"> <param name="urlScheme" value="wb3537030359"/> <param name="apiKey" value="3537030359"/> <param name="registUrl" value="http://www.diandodo.com"/> </feature>總結
以上是生活随笔為你收集整理的apiCloud授权绑定第三方账号,微信、QQ、微博。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 该信谁?跳槽究竟是涨工资还是毁一生
- 下一篇: Outlook Express邮件客户端