天天看點

paip.微信菜單直接跳轉url和擷取openid流程總結

paip.微信菜單直接跳轉url和擷取openid流程總結

#------不能直接跳轉,貝兒提示不安全的連結..

#-------使用auth跳轉.

//todox 直接轉到。。  direct goto

        viewbutton skrechcard = new viewbutton("刮刮卡o428,view," +

                "https://open.weixin.qq.com/connect/oauth2/authorize?" +

                "appid="+appid+"&" +

                "redirect_uri="+website+"mobile/card.jsp?actid=1" +

                "" +

                "&response_type=code&scope=snsapi_base&state=1" +

                "#wechat_redirect");

#------auth跳轉實際跳轉url

這個url執行後,走自動redirect到個

    website+"mobile/card.jsp?actid=1&code=xxxx&state=1

    作者 老哇的爪子 attilax 艾龍,  email:[email protected]

轉載請注明來源: http://blog.csdn.net/attilax

#---url跳轉的調試.

隻要不個wlan break..奏能看見平闆上顯示url錯誤蘭...    

#-------擷取openid

,但是view不能擷取使用者的openid,需與網頁授權擷取使用者基本資訊接口結合使用,獲得使用者的登入個人資訊。

a.配置授權回調頁面域名

進入微信公衆平台背景後,依次進入 服務-我的服務,找到oauth2.0網頁授權,

微信自定義菜單view類型擷取openid通路網頁

4

點選右側的修改

授權回調域名配置規範為全域名并且不帶http。

這裡我們填寫上面的ip位址,192.168.1.1

b.通過code獲得openid

string code = request.getparameter("code");//我們要的code

code說明 : code作為換取access_token的票據,每次使用者授權帶上的code将不一樣,code隻能使用一次,5分鐘未被使用自動過期。

txt=  webpagecontent( "https://api.weixin.qq.com/sns/oauth2/access_token?appid=appid&secret=secret&code=code&grant_type=authorization_code")

正确時傳回json資料

{   "access_token":"access_token",   

    "expires_in":7200,  

    "refresh_token":"refresh_token",   

    "openid":"openid",  

    "scope":"scope"

}

到此我們成功擷取到了使用者的openid

參考

微信自定義菜單view類型擷取openid通路網頁_百度經驗.htm