@RequestMapping(value = "/getJSApiTicket")
public void getJSApiTicket(HttpServletRequest request,
HttpServletResponse response) throws UnsupportedEncodingException, IOException {
String urlStr = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token="+token+"&type=jsapi";
URL url = new URL(urlStr);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestMethod("GET");
uc.setUseCaches(false);
uc.setRequestProperty("Accept", "application/json");
String msg = "";
String line = "";
if(uc.getResponseCode() == 200) {
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"UTF-8"));
while((line = in.readLine()) != null) {
msg = msg + line;
}
System.out.println(msg);
}
String ticket = (String) JSONObject.fromObject(msg).get("ticket");
jsapiTicket = ticket;
}
微信公众平台获得jsApiTicket
最新推荐文章于 2024-05-30 13:55:51 发布