1. 程式人生 > 其它 >將微信小程式某個路徑轉成小程式碼 無前端程式碼

將微信小程式某個路徑轉成小程式碼 無前端程式碼

try{

  JSONObject parentJSON = new JSONObject();
  parentJSON.put("page", "pages/gu_life/discount_coupon/discount_coupon");
  parentJSON.put("scene", coupon_id);
  //token 小程式apptoken   String sendUrl="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token;
  //臨時生成 所以直接放到專案中 生成後截圖就行 單個檔案 生成新的直接覆蓋舊的 不會浪費記憶體 如果有需求需要儲存的 直接資料庫持久化儲存即可   byte[] data = HttpsClientUtils.createHttpsInstance().postByte(sendUrl, parentJSON.toString());   HttpServletResponse response = this.getHttpResponse();   String path="coupon.jpg";   response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode(path, "UTF-8"));   BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());   bos.write(data);   //new一個檔案物件用來儲存圖片   File imageFile = new File(path);   outStream = new FileOutputStream(imageFile);   //寫入資料   outStream.write(data); } catch (Exception e) {   e.printStackTrace(); }finally{   // 釋放資源   try{     if(outStream!=null){       outStream.close();       outStream = null;     }   }catch(Exception e){     LogUtil.e(e.getMessage(),e);   } } return null;