<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Java生成微信小程序碼

      官網文檔地址:獲取小程序碼

      package test;
      
      import com.alibaba.fastjson.JSONObject;
      import com.fasterxml.jackson.core.JsonProcessingException;
      import com.fasterxml.jackson.databind.ObjectMapper;
      import org.apache.http.HttpEntity;
      import org.apache.http.client.methods.CloseableHttpResponse;
      import org.apache.http.client.methods.HttpGet;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.entity.StringEntity;
      import org.apache.http.impl.client.CloseableHttpClient;
      import org.apache.http.impl.client.HttpClientBuilder;
      import org.apache.http.util.EntityUtils;
      
      import java.io.*;
      import java.net.URLEncoder;
      import java.util.*;
      import java.util.stream.Collectors;
      
      /**
       * @description:
       * @author: Mr.Fang
       * @create: 2023-04-03 17:06
       **/
      
      public class WxUtils {
      
          /**
           * description: 獲取token,返回結果為 JSON 自行轉 map
           * create by: Mr.Fang
           *
           * @return: java.lang.String
           * @date: 2023/4/3 17:46
           */
          public String getToken() throws IOException {
              CloseableHttpClient httpClient = HttpClientBuilder.create().build();
              Map<String, Object> params = new HashMap<>();
              params.put("appid", "appid");
              params.put("secret", "secret");
              params.put("grant_type", "client_credential");
      
              String url = handleParams("https://api.weixin.qq.com/cgi-bin/token", params);
              HttpGet httpGet = new HttpGet(url);
      
              CloseableHttpResponse response = httpClient.execute(httpGet);
              HttpEntity entity = response.getEntity(); // 響應結果
      
              return EntityUtils.toString(entity, CharSetType.UTF8.getType());
          }
      
          /**
           * description: 對象轉 字符串
           * create by: Mr.Fang
           *
           * @param obj
           * @return: java.lang.String
           * @date: 2023/4/3 17:45
           */
          public String objToStr(Object obj) {
              ObjectMapper objectMapper = new ObjectMapper();
              if (Objects.nonNull(obj)) {
                  try {
                      return objectMapper.writeValueAsString(obj);
                  } catch (JsonProcessingException e) {
                      e.printStackTrace();
                  }
              }
              return null;
          }
      
          /**
           * description:  字符串 轉 對象轉
           * create by: Mr.Fang
           *
           * @param jsonStr
           * @param objClass
           * @return: java.lang.String
           * @date: 2023/4/3 17:45
           */
          public <T> T strToObj(String jsonStr, Class<T> objClass) {
              ObjectMapper objectMapper = new ObjectMapper();
              try {
                  T t = objectMapper.readValue(jsonStr, objClass);
                  return t;
              } catch (IOException e) {
                  e.printStackTrace();
                  return null;
              }
          }
      
          
          /**
           * description: 生成小程序碼
           * create by: Mr.Fang
           *
           * @param scene 攜帶參數
           * @param page  頁面路徑
           * @param token token
           * @param path  保存路徑
           * @return: java.lang.String
           * @date: 2023/5/11 14:22
           */
          public String appletQR(String scene, String page, String token, String path) throws IOException {
              CloseableHttpClient httpClient = HttpClientBuilder.create().build();
              Map<String, Object> params = new HashMap<>();
              params.put("scene", scene);
              params.put("page", page); //developer為開發版;trial為體驗版;formal為正式版;默認為正式版
              params.put("env_version", "develop"); //要打開的小程序版本。正式版為 "release",體驗版為 "trial",開發版為 "develop"。默認是正式版。
              HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" + token);
              httpPost.addHeader("ContentTyp", "application/json");
      
              // 參數轉 JSON 格式
              String json = objToStr(params);
              StringEntity stringEntity = new StringEntity(json, CharSetType.UTF8.getType());
              stringEntity.setContentEncoding(CharSetType.UTF8.getType());
              httpPost.setEntity(stringEntity);
              CloseableHttpResponse response = httpClient.execute(httpPost);
              HttpEntity entity = response.getEntity(); // 響應結果
              byte[] data;
              try {
                  data = readInputStream(entity.getContent());
              } catch (Exception e) {
                  e.printStackTrace();
                  return null;
              }
              if (data.length < 100) { // 異常
                  String error = new String(data);
                  return null;
              }
              String fileName = UUID.randomUUID().toString().replaceAll("-", "") + ".png";
              String filePath = path + File.separator + fileName;
              // 創建文件
              FileOutputStream fileOutputStream = null;
              try {
                  fileOutputStream = new FileOutputStream(filePath);
                  fileOutputStream.write(data);
                  fileOutputStream.flush();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              // 釋放資源
              try {
                  assert fileOutputStream != null;
                  fileOutputStream.close();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              return fileName;
          }
      
          /**
           * description: 輸入流轉字節數組
           * create by: Mr.Fang
           *
           * @param inStream 輸入流
           * @return: byte[]
           * @date: 2023/5/11 11:52
           */
          public static byte[] readInputStream(InputStream inStream) throws Exception {
              ByteArrayOutputStream outStream = new ByteArrayOutputStream();
              // 創建一個Buffer字符串
              byte[] buffer = new byte[1024];
              // 每次讀取的字符串長度,如果為-1,代表全部讀取完畢
              int len = 0;
              // 使用一個輸入流從buffer里把數據讀取出來
              while ((len = inStream.read(buffer)) != -1) {
                  // 用輸出流往buffer里寫入數據,中間參數代表從哪個位置開始讀,len代表讀取的長度
                  outStream.write(buffer, 0, len);
              }
              // 關閉輸入流
              inStream.close();
              // 把outStream里的數據寫入內存
              return outStream.toByteArray();
          }
      
          public static void main(String[] args) throws IOException {
              WxUtils wxUtils = new WxUtils();
              // 獲取 token
              String token = wxUtils.getToken();
              // 字符串轉 map 對象
              Map map = wxUtils.strToObj(token, Map.class);
              // 生成小程序碼
              String path = wxUtils.appletQR("2023", "pages/index/index", map.get("access_token").toString(), System.getProperty("user.dir") + File.separator);
              System.out.println(path);
          }
      
      }

      項目根目錄生成小程序碼

      posted @ 2023-05-11 14:47  天葬  閱讀(228)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 狠狠噜天天噜日日噜无码| 放荡的少妇2欧美版| 国产微拍一区二区三区四区| 国产精品一区二区三区黄色| 国产免费午夜福利在线观看| 国产精品无码专区| 99久久精品费精品国产一区二| 曝光无码有码视频专区| 久久亚洲精品中文字幕无| 另类专区一区二区三区| 竹山县| 一区二区三区在线色视频| 亚洲精品一区二区在线播| 精品人妻少妇一区二区三区在线| 在线中文字幕国产精品| 蜜桃av无码免费看永久| 国产成人AV国语在线观看| 风流少妇bbwbbw69视频| 国产在线一区二区在线视频| 成人免费乱码大片a毛片| 天天躁夜夜踩很很踩2022| 欧美黑人又粗又大又爽免费| 漂亮的人妻不敢呻吟被中出| 久久香蕉国产线看观看亚洲片| 国产免费无遮挡吃奶视频| 亚洲av无码片在线播放| 婷婷色香五月综合缴缴情香蕉| 少妇人妻系列无码专区视频| 国产精品人妻久久ai换脸| 老师扒下内裤让我爽了一夜| 丰满熟女人妻一区二区三| 精品国内自产拍在线观看| 中文字幕一区二区三区久久蜜桃 | 精品偷拍被偷拍在线观看| 女人的天堂A国产在线观看| 荥阳市| 性视频一区| 无码 人妻 在线 视频| 精品九九人人做人人爱| 日日爽日日操| 欧美亚洲综合成人A∨在线|