/**
* 獲取不限制的小程序碼(沒有數(shù)量限制)
*
* @param accessToken
* @param page
* @return
*/
public void getUnlimitedQRCode(String filePath, String scene, String accessToken, String page) {
try (OutputStream os = new FileOutputStream(new File(filePath))) {
//調(diào)用微信接口生成二維碼
URL url = new URL(wxUrl + "/wxa/getwxacodeunlimit?access_token=" + accessToken);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setRequestMethod("POST");// 提交模式
// 發(fā)送POST請求必須設(shè)置如下兩行
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
// 獲取URLConnection對象對應(yīng)的輸出流
PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
// 發(fā)送請求參數(shù)
JSONObject paramJson = new JSONObject();
//這就是你二維碼里攜帶的參數(shù) String型 名稱不可變
paramJson.put("scene", scene);
//注意該接口傳入的是page而不是path
paramJson.put("page", page);
//這是設(shè)置掃描二維碼后跳轉(zhuǎn)的頁面
paramJson.put("width", 430);
printWriter.write(paramJson.toString());
// flush輸出流的緩沖
printWriter.flush();
//開始獲取數(shù)據(jù)
BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream());
int len;
byte[] arr = new byte[1024];
while ((len = bis.read(arr)) != -1) {
os.write(arr, 0, len);
os.flush();
}
os.close();
bis.close();
log.info("生成二維碼成功,{}", filePath);
} catch (Exception e) {
log.error("getUnlimitedQRCode error", e);
throw new BizException(BizCodeEnum.WX_QR_CODE_ERROR);
}
}
參數(shù)說明: filePath 文件路徑
scene 可以放參數(shù)
accessToken 調(diào)用微信小程序憑證,不懂獲取的去看官方文檔
page 頁面路徑 如 pages/task/mybook
說明:
獲取不限制的小程序碼 | 微信開放文檔
以上是官網(wǎng)鏈接,可以自行查看文章來源:http://www.zghlxwxcb.cn/news/detail-506500.html
不懂的可以留言告訴我文章來源地址http://www.zghlxwxcb.cn/news/detail-506500.html
到了這里,關(guān)于微信小程序生成頁面分享二維碼(代碼親測有效)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!