取得微信OpenId
先取得code
再透過code取得authtoken,從authtoken中取出openid給前臺
微信端一定不要忘記設(shè)定網(wǎng)頁帳號中的授權(quán)回呼頁面網(wǎng)域
圖
/* 寫cookie */ function setCookie(name, value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/"; } /* 讀cookie */ function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)")); if (arr != null) { return unescape(arr[2]); } return null; } /* 獲取URL參數(shù) */ function getUrlParams(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = window.location.search.substr(1).match(reg); if (r != null) { return unescape(r[2]); } return null; } /* 獲取openid */ function getOpenId(url) { var openid = getCookie("usropenid"); if (openid == null) { openid = getUrlParams('openid'); alert("openid="+openid); if (openid == null) { window.location.href = "wxcode?url=" + url; } else { setCookie("usropenid", openid); } } }? ?WxCodeServlet程式碼
//訪問微信獲取code @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String state = req.getParameter("url"); //WxOpenIdServlet的地址 String redirect ="http://"+Configure.SITE+"/wxopenid"; redirect = URLEncoder.encode(redirect, "utf-8"); StringBuffer url = new StringBuffer("https://open.weixin.qq.com/connect/oauth2/authorize?appid=") .append(Configure.APP_ID).append("&redirect_uri=").append(redirect) .append("&response_type=code&scope=snsapi_base&state=").append(state).append("#wechat_redirect"); resp.sendRedirect(url.toString()); }Serhir 取得AuthToken(WXUtil.getAuthToken(code))代碼
//訪問微信獲取openid @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String code = req.getParameter("code"); String state = req.getParameter("state"); Result ret = new Result(); AuthToken token = WXUtil.getAuthToken(code); if(null != token.getOpenid()){ ret.setCode(0); log.info("====openid=="+token.getOpenid()); Map<String,String> map = new HashMap<String,String>(); map.put("openid", token.getOpenid()); map.put("state", state); ret.setData(map); }else{ ret.setCode(-1); ret.setMsg("登錄錯誤"); } String redUrl = state+"?openid="+token.getOpenid(); resp.sendRedirect(redUrl); }? ?
HttpClientUtil類
public static AuthToken getAuthToken(String code){ AuthToken vo = null; try { String uri = "https://api.weixin.qq.com/sns/oauth2/access_token?"; StringBuffer url = new StringBuffer(uri); url.append("appid=").append(Configure.APP_ID); url.append("&secret=").append(Configure.APP_SECRET); url.append("&code=").append(code); url.append("&grant_type=").append("authorization_code"); HttpURLConnection conn = HttpClientUtil.CreatePostHttpConnection(url.toString()); InputStream input = null; if (conn.getResponseCode() == 200) { input = conn.getInputStream(); } else { input = conn.getErrorStream(); } vo = JSON.parseObject(new String(HttpClientUtil.readInputStream(input),"utf-8"),AuthToken.class); } catch (Exception e) { log.error("getAuthToken error", e); } return vo; }? ?封裝AuthToken的VO類
package com.huatek.shebao.util; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; public class HttpClientUtil { // 設(shè)置body體 public static void setBodyParameter(String sb, HttpURLConnection conn) throws IOException { DataOutputStream out = new DataOutputStream(conn.getOutputStream()); out.writeBytes(sb); out.flush(); out.close(); } // 添加簽名header public static HttpURLConnection CreatePostHttpConnection(String uri) throws MalformedURLException, IOException, ProtocolException { URL url = new URL(uri); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setUseCaches(false); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod("POST"); conn.setInstanceFollowRedirects(true); conn.setConnectTimeout(30000); conn.setReadTimeout(30000); conn.setRequestProperty("Content-Type","application/json"); conn.setRequestProperty("Accept-Charset", "utf-8"); conn.setRequestProperty("contentType", "utf-8"); return conn; } public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outStream = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } byte[] data = outStream.toByteArray(); outStream.close(); inStream.close(); return data; } }?

熱AI工具

Undress AI Tool
免費脫衣圖片

Undresser.AI Undress
人工智慧驅(qū)動的應(yīng)用程序,用於創(chuàng)建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強(qiáng)大的PHP整合開發(fā)環(huán)境

Dreamweaver CS6
視覺化網(wǎng)頁開發(fā)工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

抖音網(wǎng)頁版的登錄入口是https://www.douyin.com/。登錄步驟包括:1.打開瀏覽器;2.輸入網(wǎng)址https://www.douyin.com/;3.點擊“登錄”按鈕並選擇登錄方式;4.輸入賬號密碼;5.完成登錄。網(wǎng)頁版提供了瀏覽、搜索、互動、上傳視頻和個人主頁管理等功能,具有大屏幕體驗、多任務(wù)處理、便捷的賬號管理和數(shù)據(jù)統(tǒng)計等優(yōu)勢。

拷貝漫畫無疑是一個不容錯過的寶藏。在這裡,你可以找到各種風(fēng)格的籃球漫畫,從熱血勵志的競技故事,到輕鬆幽默的日常喜劇,應(yīng)有盡有。無論是想重溫經(jīng)典,還是想發(fā)掘新作,拷貝漫畫都能滿足你的需求。通過拷貝漫畫提供的正版在線閱讀入口,你將告別盜版資源的困擾,享受高清流暢的閱讀體驗,更能支持你喜愛的漫畫作者,為正版漫畫的發(fā)展貢獻(xiàn)一份力量。

選擇UC瀏覽器還是QQ瀏覽器取決於你的需求:1.UC瀏覽器適合追求快速加載和豐富娛樂功能的用戶;2.QQ瀏覽器適合需要穩(wěn)定性和與騰訊產(chǎn)品無縫連接的用戶。

結(jié)合 2025 年最新行業(yè)動態(tài)與多維度評測數(shù)據(jù),以下為綜合排名前十的 AI 寫作軟件推薦,涵蓋通用創(chuàng)作、學(xué)術(shù)研究、商業(yè)營銷等主流場景,同時兼顧中文優(yōu)化與本地化服務(wù):

奈斯漫畫,一個致力於為漫畫愛好者打造的沉浸式閱讀體驗平臺,匯聚了海量國內(nèi)外優(yōu)質(zhì)漫畫資源。它不僅僅是一個漫畫閱讀平臺,更是一個連接漫畫家與讀者、分享漫畫文化的社區(qū)。通過簡潔直觀的界面設(shè)計和強(qiáng)大的搜索功能,奈斯漫畫讓你能夠輕鬆找到心儀的作品,享受流暢舒適的閱讀體驗。告別漫長的等待和繁瑣的操作,即刻進(jìn)入奈斯漫畫的世界,開啟你的漫畫之旅吧!

蛙漫漫畫,憑藉其豐富多元的漫畫資源和便捷流暢的在線閱讀體驗,已成為眾多漫畫愛好者的首選。它就像一個充滿活力的池塘,源源不斷地湧現(xiàn)出新鮮有趣的故事,等待著你去發(fā)現(xiàn)和探索。蛙漫漫畫涵蓋了各種題材,從熱血冒險到甜蜜戀愛,從奇幻科幻到懸疑推理,無論你喜歡哪種類型,都能在這裡找到心儀的作品。其簡潔直觀的界面設(shè)計,更讓你能夠輕鬆上手,快速找到想看的漫畫,沉浸在精彩紛呈的漫畫世界中。

在這裡,您可以盡情暢遊於浩瀚的漫畫海洋,探索各種題材和風(fēng)格的作品,從熱血激昂的少年漫,到細(xì)膩動人的少女漫,從懸疑燒腦的推理漫,到輕鬆搞笑的日常漫,應(yīng)有盡有,總有一款能夠觸動您的心弦。我們不僅擁有海量的正版漫畫資源,還不斷引進(jìn)和更新最新的作品,確保您能夠第一時間閱讀到您喜愛的漫畫。

2025b安最新官網(wǎng)入口地址:https://www.marketwebb.co/zh-CN/join?ref=507720986&type=wenzi;幣安(Binance)交易所是一家全球性的加密貨幣交易所,服務(wù)包括北美、歐洲、臺灣、中東、香港、馬來西亞在內(nèi)的180個國家地區(qū),提供超過600種加密貨幣,在全球擁有2.7億註冊用戶。
