微信小程序二维码生成工具,后端二维码生成工具类。
发布日期:2021-05-14 12:40:47 浏览次数:17 分类:精选文章

本文共 6848 字,大约阅读时间需要 22 分钟。

���������������������������������������������

������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������logo������������������������������������������������������������������������������������������������������������������������������������

������������

���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������API������������������������������������������������������������������������������������������������������������

������������

���������������������������������������������������

  • ������������
  • ���������������API���������������������������������������������������������������������������������������������������������������������������������

    • ������������������������������APPID���SECRET������������
    • ���������������������������������
    • ������������������������������������������������

    ���������������������������������������������������������������������������������������

    1. ������������
    2. ���������������API������������������������������������������������

      • ���������������access_token���
      • ���������������

      ���������������������������������������������

      1. ���������������
      2. ������������������������������������������������������

        package com.haishi.webappdemo.utils;
        import java.io.BufferedReader;
        import java.io.IOException;
        import java.io.InputStreamReader;
        import java.io.PrintWriter;
        import java.net.URL;
        import java.net.URLConnection;
        public class HttpRequestUtils {
        public static String sendGet(String url, String param) throws IOException {
        BufferedReader in = null;
        try {
        String urlNameString = url + "?" + param;
        URL realUrl = new URL(urlNameString);
        URLConnection connection = realUrl.openConnection();
        connection.setRequestProperty("accept", "*/*");
        connection.setRequestProperty("connection", "Keep-Alive");
        connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
        connection.connect();
        Map
        > map = connection.getHeaderFields();
        for (String key : map.keySet()) {
        System.out.println(key + "---" + map.get(key));
        }
        in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String line;
        while ((line = in.readLine()) != null) {
        result += line;
        }
        } catch (Exception e) {
        System.out.println("������GET���������������������" + e);
        e.printStackTrace();
        } finally {
        try {
        if (in != null) {
        in.close();
        }
        } catch (Exception e2) {
        e2.printStackTrace();
        }
        }
        return result;
        }
        public static String sendPost(String url, Map
        param, HttpServletResponse response) throws IOException {
        PrintWriter out = null;
        InputStream in = null;
        try {
        URL realUrl = new URL(url);
        URLConnection conn = realUrl.openConnection();
        conn.setRequestProperty("accept", "*/*");
        conn.setRequestProperty("connection", "Keep-Alive");
        conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
        conn.setDoOutput(true);
        conn.setDoInput(true);
        out = new PrintWriter(conn.getOutputStream());
        out.print(param);
        out.flush();
        in = conn.getInputStream();
        OutputStream outputStream = response.getOutputStream();
        byte[] bytes = new byte[1024];
        while ((len = in.read(bytes)) != -1) {
        outputStream.write(bytes, 0, len);
        }
        outputStream.flush();
        outputStream.close();
        } catch (Exception e) {
        System.out.println("������ POST ���������������������" + e);
        e.printStackTrace();
        } finally {
        try {
        if (out != null) {
        out.close();
        }
        if (in != null) {
        in.close();
        }
        } catch (IOException ex) {
        ex.printStackTrace();
        }
        }
        }

        ������������������������HttpServletResponse���������������������������������������������

        ������������������������������������

      3. Controller������
      4. ������������������������������������������Controller���������������RESTful���������������������������������������

        package com.webappdemo.controller;
        import com.haishi.webappdemo.utils.HttpRequestUtils;
        import org.springframework.web.bind.annotation.RequestMapping;
        import org.springframework.web.bind.annotation.RequestMethod;
        import org.springframework.web.bind.annotation.RequestParam;
        import org.springframework.web.bind.annotation.RestController;
        import javax.servlet.http.HttpServletResponse;
        import java.util.HashMap;
        import java.util.Map;
        @RestController
        public class TestController {
        @RequestMapping(value = "/getQRcode.json", method = RequestMethod.GET)
        public void getQRcode(@RequestParam("url") String url, HttpServletResponse response) {
        Map
        param = new HashMap<>();
        HttpRequestUtils.sendPost(url, param, response);
        }
        }

        ���������������������������������������������������������������������������������������������������������������HttpServletResponse���������������������������������������������������������������������������������������������������������������

        1. ������������
        2. ������������������������������������������������

          • ���������������������������������������������������������������������������������������������
          • ������������������������������������������������������
          • ���������������������������������������������������������������������������������������������������������������������������������

          ���������������������������������

        3. ������������������
        4. ������������������������������
        5. .ResponseBody���������������
        6. ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

          ���������������������������������������������������������������������������������������������������������������������

    上一篇:Mac上SpringBoot初始化项目后运行失败
    下一篇:SSM框架基础入门教程(一)

    发表评论

    最新留言

    网站不错 人气很旺了 加油
    [***.192.178.218]2025年05月04日 06时18分32秒