當前位置:編程學習大全網 - 源碼下載 - ios 微信的openid有效期是多久

ios 微信的openid有效期是多久

獲取微信OpenId 先獲取code 再通過code獲取authtoken,從authtoken中取出openid給前臺 微信端壹定不要忘記設定網頁賬號中的授權回調頁面域名 流程圖如下 主要代碼 頁面js代碼 /* 寫cookie */ function setCookie(name, value) { var Days = 30; var exp = new Date(); exp/connect/oauth2/authorize?appid=") /sns/oauth2/access_token?"; StringBuffer url = new StringBuffer(uri); url.URL; public class HttpClientUtil { // 設置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; } } 封裝AuthToken的VO類 package com.huatek.shebao.wxpay; public class AuthToken { private String access_token; private Long expires_in; private String refresh_token; private String openid; private String scope; private String unionid; private Long errcode; private String errmsg; public String getAccess_token() { return access_token; } public void setAccess_token(String access_token) { this.access_token = access_token; } public Long getExpires_in() { return expires_in; } public void setExpires_in(Long expires_in) { this.expires_in = expires_in; } public String getRefresh_token() { return refresh_token; } public void setRefresh_token(String refresh_token) { this.refresh_token = refresh_token; } public String getOpenid() { return openid; } public void setOpenid(String openid) { this.openid = openid; } public String getScope() { return scope; } public void setScope(String scope) { this.scope = scope; } public String getUnionid() { return unionid; } public void setUnionid(String unionid) { this.unionid = unionid; } public Long getErrcode() { return errcode; } public void setErrcode(Long errcode) { this.errcode = errcode; } public String getErrmsg() { return errmsg; } public void setErrmsg(String errmsg) { this.errmsg = errmsg; } } 感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

  • 上一篇:9年前湖人交易保羅被叫停,當時的籌碼有什麽?
  • 下一篇:配音網站源代碼
  • copyright 2024編程學習大全網