赞
踩
实现代码:
public static String wxQrCodeB(String accessToken, WxGetUnlimitedQRCodeObj wxGetUnlimitedQRCodeObj) throws Exception{ String URL_GET_UNLIMITED_QRCODE = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=%s"; String jsonStr = JSON.toJSONString(wxGetUnlimitedQRCodeObj); CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpPost httpPost = new HttpPost(String.format(URL_GET_UNLIMITED_QRCODE, accessToken)); httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); httpPost.setEntity(new StringEntity(jsonStr)); HttpResponse response = httpClient.execute(httpPost); InputStream ins = response.getEntity().getContent(); byte[] bytes = IOUtils.toByteArray(ins); String base64Str = Base64.getEncoder().encodeToString(bytes); System.out.println("base64Str=" + base64Str); return base64Str; } public static void main(String[] args) throws Exception { String accessToken = "你的accessToken"; WxGetUnlimitedQRCodeObj wxGetUnlimitedQRCodeObj = new WxGetUnlimitedQRCodeObj(); wxGetUnlimitedQRCodeObj.setPath("page/index"); // 要跳转的小程序页面 wxGetUnlimitedQRCodeObj.setScene("aaa=1"); wxQrCodeB2(accessToken, wxGetUnlimitedQRCodeObj); }
注意:不保存二维码图片文件,而是直接转base64,因为不需要把图片这些图片保存到服务器中占用空间。
2. base64转图片:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。