java 微信帶引數的二維碼
阿新 • • 發佈:2018-12-27
//獲取ticket
public static String getQr(String accessToken, String jsonMsg){ String result = null; String requestUrl = " https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=TOKEN"; requestUrl = requestUrl.replace("TOKEN", accessToken); JSONObject jsonObject = WeixinUtil.httpRequest(requestUrl, "POST", jsonMsg); if(null != jsonObject){ System.out.println(jsonObject); result = jsonObject+""; } return result; } //用ticket獲取二維碼 public static boolean chageQr(String ticket){ boolean result = false; String requestUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET"; requestUrl = requestUrl.replace("TICKET", ticket); JSONObject jsonObject = WeixinUtil.httpRequest(requestUrl, "GET", null); System.out.println(jsonObject+""); if(null != jsonObject){ System.out.println(jsonObject); int errorCode = jsonObject.getInt("errcode"); String errorMsg = jsonObject.getString("errmsg"); if(0 == errorCode){ result = true; logger.info("成功errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}"); System.out.println("成功errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}"); }else{ logger.info("失敗errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}"); System.out.println("失敗errorCode:{"+errorCode+"},errmsg:{"+errorMsg+"}"); } } return result; }