<ul id="g60s4"><pre id="g60s4"></pre></ul>
<strong id="g60s4"><nav id="g60s4"></nav></strong>
<ul id="g60s4"></ul>
  • <tr id="g60s4"></tr>
  • 
    
  • 或者
    問答詳情頁頂部banner圖
    您的位置:首頁 >開發(fā) > 移動應(yīng)用 > 微信開發(fā) > 網(wǎng)頁被自動轉(zhuǎn)接到 很快 微信開發(fā)

    網(wǎng)頁被自動轉(zhuǎn)接到 很快 微信開發(fā)

    提問者:果果  |   分類:微信開發(fā)  |   瀏覽236次  |   懸賞分:3積分 2017-04-02 06:00:25

    我要回答

    提 交

    匿名

    • think

      網(wǎng)頁授權(quán)分為四步: 1. 引導用戶進入授權(quán)頁面同意授權(quán),獲取code 2. 通過code換取網(wǎng)頁授權(quán)access_token(與基礎(chǔ)支持中的access_token不同) 3. 如果需要,開發(fā)者可以刷新網(wǎng)頁授權(quán)access_token,避免過期 4. 通過網(wǎng)頁授權(quán)access_token和openid獲取用戶基本信息(支持UnionID機制) 配置授權(quán)回調(diào)域名 如果用戶在微信客戶端中訪問第三方網(wǎng)頁,公眾號可以通過微信網(wǎng)頁授權(quán)機制,來獲取用戶基本信息,進而實現(xiàn)業(yè)務(wù)邏輯。所以第一步是配置域名,在微信公眾號的公眾號設(shè)置中可以配置,域名是需要備案的。 獲取code 接口請求為:https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect redirect_uri為請求后重定向地址,也就是你要跳轉(zhuǎn)至的網(wǎng)頁地址,state為重定向后的參數(shù)。 scope的區(qū)別說明,有2種授權(quán)方式,根據(jù)自己的需要進行處理: scope為snsapi_base,靜默授權(quán)并自動跳轉(zhuǎn)到回調(diào)頁的。用戶感知的就是直接進入了回調(diào)頁(往往是業(yè)務(wù)頁面) scope為snsapi_userinfo,這種授權(quán)需要用戶手動同意,并且由于用戶同意過,所以無須關(guān)注,就可在授權(quán)后獲取該用戶的基本信息 獲取網(wǎng)頁授權(quán)的access_token 獲取code后,請求以下鏈接獲取access_token,code為上一步得到的code: https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code 代碼說明 新用戶進來的時候是沒有cookie的,而且type=2,首先是要授權(quán),授權(quán)的代碼在下面。這個時候可以給其設(shè)置一個cookie,設(shè)置存活時間為10小時。授權(quán)完成后,還是會重定向進入這個方法來處理,只是type變化,這個時候進入測試或者正式環(huán)境,根據(jù)參數(shù)menuType進行判斷是哪個目錄被點擊,然后進入相對應(yīng)的頁面。若cookie不為空,則直接跳轉(zhuǎn)測試或者正式環(huán)境相對應(yīng)的頁面。 /** * * @param type 0-測試, 1-正式, 2-跳轉(zhuǎn)獲取CODE,3:認證過的測試號 * @param menuType * @param request * @param wechatUserId * @param response * @return */ @RequestMapping("/view") public ModelAndView view(Integer type,Integer menuType, Integer wechatUserId, String redirect,HttpServletRequest request, HttpServletResponse response) { Cookie cookie = CookieUtil.getCookieByName(request, "wechatUserId"); log.info("type:" + type + ",menuType:" + menuType + ",wechatUserId:" + wechatUserId + ",redirect:" + redirect); String url = null; if(cookie == null) { log.info("Cookie已過期....."); if(type == 0) { CookieUtil.addCookie(response, "wechatUserId", Randoms.getInt(1, 53)+"", 60 * 10); /* 測試環(huán)境 */ url = "view?format=json&type=0&menuType=" + menuType + "&redirect=" + redirect; log.info("url:" + url); return new ModelAndView(new RedirectView(url)); } else if(type == 1) { CookieUtil.addCookie(response, "wechatUserId", wechatUserId+"", (60 * 60 * 10)); /* 生產(chǎn)環(huán)境 */ url = "view?format=json&type=1&menuType=" + menuType + "&redirect=" + redirect; log.info("url:" + url); return new ModelAndView(new RedirectView(url)); } else if(type == 2) { String wechatRedirece = UrlUtil.encode(wechatConfig.getHOST() + "wechat/user/auth?format=json&type=1&menuType=" + menuType + "&redirect=" + redirect); /** * 授權(quán)的鏈接 * 注意redirect_uri為重定向地址,/auth在下面的代碼中 * public String getAUTHORIZE_URL() { * return "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+getAPPID() +"&redirect_uri="; } */ url = wechatConfig.getAUTHORIZE_URL() + wechatRedirece + "&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect"; log.info("url:" + url); return new ModelAndView(new RedirectView(url)); } else { return new ModelAndView(new RedirectView(url)); } } else { log.info("Cookie未過期....."); if(type == 0) { switch (menuType) { case 0: url = AESCryptoSecurity.decrypt(redirect, wechatConfig.getAPPID()); break; case 1: //社區(qū) url = wechatConfig.getHOST_FRONT() + "page/topicList.html"; break; case 2: //活動 url = wechatConfig.getHOST_FRONT() + "page/activityList.html"; break; } } else { switch (menuType) { case 0: url = AESCryptoSecurity.decrypt(redirect, wechatConfig.getAPPID()); break; case 1: //社區(qū) url = wechatConfig.getHOST_FRONT() + "page/topicList.html"; break; case 2: //活動 url = wechatConfig.getHOST_FRONT() + "page/activityList.html"; break; } } return new ModelAndView(new RedirectView(url)); } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 下面的代碼為獲取code,獲取access_token,獲取用戶信息等,認證完跳轉(zhuǎn)至對應(yīng)的頁面 @RequestMapping("/auth") public ModelAndView auth(String code, Integer type, Integer menuType, String redirect) throws Exception { log.info("code:" + code + ",type:" + type + ",menuType:" + menuType); /* 向微信發(fā)請求獲取access_token */ Map map = wechatUserService.getPageAccessToken(code); /* 向微信發(fā)請求,用access_token獲取用戶信息并保存 */ WechatUser pageWechatUser = wechatUserService.getPageWechatUser(map.get("access_token").toString(), map.get("openid").toString()); String url = null; if(type == 1) { /* 權(quán)限認證完成后,將type改為1或者0,重定向進入上面的方法進行頁面跳轉(zhuǎn) */ url = wechatConfig.getHOST() + "wechat/menu/view?&type=1&menuType=" + menuType + "&wechatUserId=" + pageWechatUser.getWechatId() + "&redirect=" + redirect; log.info("url:" + url); } return new ModelAndView(new RedirectView(url)); }

      2017-06-07 11:19:27
      評論0  |   0
    問答詳情中間banner
    99re8这里有精品热视频免费| 惠民福利中文字幕人妻无码乱精品 | 久久久亚洲精品蜜桃臀| 日韩AV无码一区二区三区不卡毛片| 亚洲国产精品va在线播放| 久久精品中文字幕一区| 亚洲精品高清一二区久久| 日韩一区二区视频| 日韩在线中文字幕制服丝袜| 在线观看91精品国产不卡免费| 亚洲精品久久无码av片俺去也| 国产精品1024香蕉在线观看| 91精品国产综合久久青草| 日韩精品无码一区二区三区| 久久精品一区二区三区日韩| 久久青草国产精品一区| 亚洲av日韩aⅴ无码色老头| 国产产在线精品亚洲AAVV| 精品欧洲男同同志videos| 久久精品人人做人人爱爱| 中文字幕日韩精品一区二区三区| 国内精品久久久久影院免费| 久久久久久无码国产精品中文字幕 | 久久精品国产99国产精品导航| 99精品国产高清自在线看超| 亚洲综合精品一二三区在线| 日韩一区精品视频一区二区| 五月花精品视频在线观看| 亚洲一区精品中文字幕| 老司机午夜精品视频资源| 日产精品一线二线三线芒果| 久久精品一本到99热免费| 亚洲精品中文字幕乱码| 国内精品免费在线观看 | 国产日韩精品视频一区二区三区| 国产成人精品怡红院| 国产精品日本一区二区在线播放| 国内精品51视频在线观看| 久久伊人精品热在75| 999这里只有精品| 亚洲国产精品专区|