當前位置:首頁 » 安卓系統 » android第三方登錄微信

android第三方登錄微信

發布時間: 2022-12-07 03:22:37

『壹』 android 微信第三方登錄怎麼通過code獲取openid

1.登錄公眾賬號設置OAuth2.0
2.設置菜單按鈕URL為OAuth鏈接
3.頁面後台獲取:
public String getopenId() {
HttpServletRequest request = ServletActionContext.getRequest();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("text/html");
String code = request.getParameter("code");
String urlstr = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=<appId>&secret=<secret>&code=" + code + "&grant_type=authorization_code";
JSONObject json;
try {
json = JSONObject.fromObject(HTTPTools.postToGetJson(urlstr));
openId = json.getString("openid");
} catch (Exception e) {
// e.printStackTrace();
return "";
}
return openId;
}

『貳』 第三方微信登錄安卓介面實現

1)在build.gradle的dependencies中添加2、申明應用許可權3、向微信注冊APP4、請求微信授權登錄5、創建WXEntryActivity.java來接收微信的響應事件這里和簽名一樣,很重要,你如果名字錯了,或者包名的位置錯了,都是不能回調的,切記

『叄』 Android微信第三方登錄/支付,沒有走回調

1、要正式簽名的apk,使用debug包貌似無法調動微信
2、清單文件中要注冊微信回調

<activity
android:name=".wxapi.WXEntryActivity"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTop"
android:theme="@android:style/Theme.Translucent" />
3、回調的類名,一定要是官網的WXEntryActivity.java。這里很迷,我之前名字是WXPayEntryActivity,因為之前使用了微信支付,就起了這個名字,後續又加入了微信分享,也沒有問題,當我又加入微信登錄之後,就不走回調了,改成WXEntryActivity.java成功走了回調。
4、回調類所在包名,一定要是wxapi:
.wxapi.WXEntryActivity

熱點內容
編譯器中的數據結構 發布:2025-07-01 05:10:53 瀏覽:526
雲伺服器最先跑什麼 發布:2025-07-01 05:02:39 瀏覽:216
微信公眾平台手機上傳視頻 發布:2025-07-01 04:58:53 瀏覽:415
數控車床螺紋編程實例 發布:2025-07-01 04:46:27 瀏覽:422
什麼是安卓品牌尖貨 發布:2025-07-01 04:45:50 瀏覽:697
寫入設備緩存 發布:2025-07-01 04:37:35 瀏覽:431
小雞g4怎麼連安卓 發布:2025-07-01 04:37:25 瀏覽:355
黃金線主圖源碼 發布:2025-07-01 04:35:38 瀏覽:298
阿里輕量伺服器有固定IP嗎 發布:2025-07-01 04:30:27 瀏覽:507
電腦什麼配置要合適 發布:2025-07-01 04:24:15 瀏覽:167