<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圖
    您的位置:首頁 >開發 > 移動應用 > 微信開發 > 網頁被自動轉接到 很快 微信開發

    網頁被自動轉接到 很快 微信開發

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

    我要回答

    提 交

    匿名

    • think

      網頁授權分為四步: 1. 引導用戶進入授權頁面同意授權,獲取code 2. 通過code換取網頁授權access_token(與基礎支持中的access_token不同) 3. 如果需要,開發者可以刷新網頁授權access_token,避免過期 4. 通過網頁授權access_token和openid獲取用戶基本信息(支持UnionID機制) 配置授權回調域名 如果用戶在微信客戶端中訪問第三方網頁,公眾號可以通過微信網頁授權機制,來獲取用戶基本信息,進而實現業務邏輯。所以第一步是配置域名,在微信公眾號的公眾號設置中可以配置,域名是需要備案的。 獲取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為請求后重定向地址,也就是你要跳轉至的網頁地址,state為重定向后的參數。 scope的區別說明,有2種授權方式,根據自己的需要進行處理: scope為snsapi_base,靜默授權并自動跳轉到回調頁的。用戶感知的就是直接進入了回調頁(往往是業務頁面) scope為snsapi_userinfo,這種授權需要用戶手動同意,并且由于用戶同意過,所以無須關注,就可在授權后獲取該用戶的基本信息 獲取網頁授權的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,首先是要授權,授權的代碼在下面。這個時候可以給其設置一個cookie,設置存活時間為10小時。授權完成后,還是會重定向進入這個方法來處理,只是type變化,這個時候進入測試或者正式環境,根據參數menuType進行判斷是哪個目錄被點擊,然后進入相對應的頁面。若cookie不為空,則直接跳轉測試或者正式環境相對應的頁面。 /** * * @param type 0-測試, 1-正式, 2-跳轉獲取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); /* 測試環境 */ 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)); /* 生產環境 */ 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); /** * 授權的鏈接 * 注意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: //社區 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: //社區 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,獲取用戶信息等,認證完跳轉至對應的頁面 @RequestMapping("/auth") public ModelAndView auth(String code, Integer type, Integer menuType, String redirect) throws Exception { log.info("code:" + code + ",type:" + type + ",menuType:" + menuType); /* 向微信發請求獲取access_token */ Map map = wechatUserService.getPageAccessToken(code); /* 向微信發請求,用access_token獲取用戶信息并保存 */ WechatUser pageWechatUser = wechatUserService.getPageWechatUser(map.get("access_token").toString(), map.get("openid").toString()); String url = null; if(type == 1) { /* 權限認證完成后,將type改為1或者0,重定向進入上面的方法進行頁面跳轉 */ 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
    竹菊影视国产精品| 国产成人精品2021| 日韩精品无码免费专区网站| 精品无码人妻一区二区三区18| 精品日韩99亚洲的在线发布| 久久99精品一久久久久久| 自拍偷在线精品自拍偷无码专区| 国产精品成人小电影在线观看 | 国产精品日韩欧美一区二区三区| 国产精品色午夜免费视频| 含羞草国产亚洲精品岁国产精品| 国产精品第13页| 精品国精品国产自在久国产应用| 久久久精品人妻一区二区三区蜜桃 | 国产91在线|日韩| 亚洲国产日韩综合久久精品| www.日韩在线| 中文字幕国产日韩| 国产亚洲日韩一区二区三区| 日韩蜜芽精品视频在线观看| 国产成人综合久久精品| 国产精品白浆在线观看无码专区| 精品国产一区二区三区| 精品国产乱码欠欠欠欠精品| 国产精品美女久久久久浪潮AV| 精品久久久久久久久亚洲偷窥女厕 | www国产亚洲精品久久久| 国产日韩视频在线| 日韩一级视频免费观看| 日韩亚洲精品福利| 亚洲精品国产高清嫩草影院| 国产精品一区二区三区免费| 中日欧洲精品视频在线| 99re6在线精品免费观看| 最新国产精品拍自在线播放| 久久久国产精品福利免费| 国产成人亚洲精品青草天美 | 国产精品萌白酱在线观看| 国产成人无码精品久久二区三区| 日韩视频在线播放| 日韩精品一区二区三区中文版 |