<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 第三方登錄--微信篇 1、首先引入![](https://box.kancloud.cn/902e2820092c6530addc6b048947b81e_483x149.png) 2、使用auth方法![](https://box.kancloud.cn/0740e2d464d428455366f33cd71cbfaf_315x141.png) 3、配置![](https://box.kancloud.cn/8a528a919a2406a85f6cc7e639bf1300_575x136.png) 3 - 1 首頁需要到微信開放平臺去申請審核 https://open.weixin.qq.com/ ![](https://box.kancloud.cn/986dbc55b426e577fba8e35387116e13_1114x824.png) **注:如果需要ios 和 安卓 使用,請注意上圖 將ios和android應用都勾選上** 4、auth方法成功之后,使用getToken方法![](https://box.kancloud.cn/1c5987ee5a02bc2cc4eb8193eecbdc71_337x145.png) 5、在使用getToken方法成功后,使用getUserInfo方法![](https://box.kancloud.cn/f77451b0ffcb80eb6ad5fde84ff0f11a_442x161.png) > 將獲取到的用戶信息按需要邏輯處理 * * * * * 附上小編的項目代碼 小編的代碼有處理是否綁定的邏輯以及登錄等,大家只需參考wx登錄部分即可 **html部分** ~~~ <div class="aui-col-xs-2" style="text-align: center;" tapmode onclick="wxauth()"> <i class="iconfont icon-liaotian icon_bg2"></i> <div class="aui-grid-label" style="display:block;margin-top:10px;">微信</div> </div> ~~~ **js部分** ~~~ //微信登錄 function wxauth() { api.showProgress({ style: 'default', animationType: 'fade', title: '', text: '啟動中...', modal: false }); var wx = api.require('wx'); wx.auth({ apiKey: 'wx***********' }, function(ret, err) { api.hideProgress(); if (ret) { if (ret.status) { var code = ret.code; getToken(code); } else { api.toast({ msg: '錯誤', duration: 2000, location: 'middle' }); } } else { switch(err.code) { case -1: api.toast({ msg: '未知錯誤', duration: 2000, location: 'middle' }); break; case 1: api.toast({ msg: '用戶取消', duration: 2000, location: 'middle' }); break; case 2: api.toast({ msg: '用戶拒絕授權', duration: 2000, location: 'middle' }); break; case 3: api.toast({ msg: '當前設備未安裝微信客戶端', duration: 2000, location: 'middle' }); break; } } }); } ~~~ ~~~ /** * [getToken 獲取用戶token] * @param {[type]} code [授權成功后返回code 參數] * @return {[type]} [description] */ function getToken(code) { var wx = api.require('wx'); wx.getToken({ apiKey: '', apiSecret: '', code: code }, function(ret, err) { if (ret) { if (ret.status) { var accessToken=ret.accessToken; var dynamicToken=ret.dynamicToken; var openId=ret.openId; getUserInfo(accessToken,openId); } else { api.toast({ msg: '錯誤', duration: 2000, location: 'middle' }); } } else { switch(err.code) { case -1: api.toast({ msg: '未知錯誤', duration: 2000, location: 'middle' }); break; case 1: api.toast({ msg: 'apiKey值為空或非法', duration: 2000, location: 'middle' }); break; case 2: api.toast({ msg: 'apiSecret值為空或非法', duration: 2000, location: 'middle' }); break; case 3: api.toast({ msg: 'code值為空或非法', duration: 2000, location: 'middle' }); break; case 4: api.toast({ msg: '網絡超時', duration: 2000, location: 'middle' }); break; } } }); } ~~~ ~~~ /** * [getUserInfo 獲取用戶信息] * @param {[type]} accessToken [getToken 接口或 refreshToken 接口成功獲取的 accessToken 值] * @param {[type]} openId [getToken 接口或 refreshToken 接口成功獲取的 openId 值] */ function getUserInfo(accessToken,openId) { var wx = api.require('wx'); wx.getUserInfo({ accessToken: accessToken, openId: openId }, function(ret, err) { if (ret) { if (ret.status) { var openid=ret.openid, unionid = ret.unionid, nickname=ret.nickname, head_pic=ret.headimgurl, source='weixin'; api.ajax({ url: domainName + '/index.php?g=User&m=Api&a=thirdLogin', method: 'post', data: { values: { openid: openid, unionid: unionid, nickname: nickname, head_pic: head_pic, source: source } } }, function(ret, err) { if (ret) { 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: '未知錯誤', duration: 2000, location: 'middle' }); } }); } else { api.toast({ msg: '錯誤', duration: 2000, location: 'middle' }); } } else { switch(err.code) { case -1: api.toast({ msg: '未知錯誤', duration: 2000, location: 'middle' }); break; case 1: api.toast({ msg: 'accessToken 過期', duration: 2000, location: 'middle' }); break; case 2: api.toast({ msg: 'openId非法', duration: 2000, location: 'middle' }); break; case 3: api.toast({ msg: 'openId值為空', duration: 2000, location: 'middle' }); break; case 4: api.toast({ msg: 'accessToken值為空', duration: 2000, location: 'middle' }); break; case 5: api.toast({ msg: 'accessToken非法', duration: 2000, location: 'middle' }); break; case 6: api.toast({ msg: '網絡超時', duration: 2000, location: 'middle' }); break; } } }); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看