Forráskód Böngészése

1、手动拉取书籍列表
2、章节列表接口

lijilei 3 éve
szülő
commit
b65983afd0

+ 6 - 0
book-server/pom.xml

@@ -160,5 +160,11 @@
             <artifactId>mysql-connector-java</artifactId>
             <version>8.0.16</version>
         </dependency>
+        <!--fastjosn-->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.75</version>
+        </dependency>
     </dependencies>
 </project>

+ 45 - 4
book-server/src/main/java/com/book/server/controller/BookController.java

@@ -1,9 +1,12 @@
 package com.book.server.controller;
 
+import com.alibaba.fastjson.JSONObject;
 import com.book.server.common.entity.PageResult;
 import com.book.server.common.entity.Result;
+import com.book.server.common.entity.ResultCode;
 import com.book.server.dao.entity.Book;
 import com.book.server.model.VO.BlockRes;
+import com.book.server.model.VO.Chapter;
 import com.book.server.model.VO.QueryVO;
 import com.book.server.service.BookService;
 import lombok.extern.slf4j.Slf4j;
@@ -11,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.EnableCaching;
+import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -39,35 +43,72 @@ public class BookController extends BaseController {
 
     /**
      * 书城分页推荐
+     *
      * @param queryVO
      * @return
      */
     @PostMapping("/recommend")
-    public PageResult<Book> recommendByRead(@RequestBody QueryVO queryVO,String pageId) {
+    public PageResult<Book> recommendByRead(@RequestBody QueryVO queryVO, String pageId) {
         queryVO.setSex(pageId);
         return bookService.recommendByRead(queryVO);
     }
 
     /**
      * 书城block
+     *
      * @param pageId
      * @return
      */
     @GetMapping("/getBlockByPageId")
-    @Cacheable(value = "block",key = "#pageId")
+    @Cacheable(value = "block", key = "#pageId")
     public Result<List<BlockRes>> getBlockByPageId(Integer pageId) {
-        List<BlockRes> list =bookService.getBlockByPageId(pageId);
+        List<BlockRes> list = bookService.getBlockByPageId(pageId);
         return Result.byObject(list);
     }
 
     /**
      * 移除block缓存
+     *
      * @return
      */
     @GetMapping("/removeBlockCache")
-    @CacheEvict(value = "block",allEntries = true)
+    @CacheEvict(value = "block", allEntries = true)
     public Result removeBlockCache() {
         return Result.byObject("OK");
     }
 
+
+    /**
+     * 导入书库
+     * 注意:此代码仅限拉取书籍使用,只能运行一次。
+     *
+     * @return
+     */
+
+    @GetMapping("/insertBooks")
+    public Result insertBooks() {
+        boolean open = false;
+        if (open) {
+            bookService.insertBooks();
+        }
+        return Result.byObject("OK");
+    }
+
+    /**
+     * 获取章节列表
+     * @param book
+     * @return
+     */
+    @PostMapping("/chapterList")
+    public Result<List<Chapter>> getChaptersByPageAndRow(@RequestBody JSONObject book) {
+
+      List<Chapter>  chapterList =  bookService.getChaptersByBookId(book.getString("bookId"));
+      if ( CollectionUtils.isEmpty(chapterList)){
+          return Result.failure(ResultCode.FAIL.getCode(),"哎呀~没有数据啦~");
+      }else {
+          return Result.byObject(chapterList);
+      }
+    }
+
+
 }

+ 23 - 0
book-server/src/main/java/com/book/server/model/VO/Chapter.java

@@ -0,0 +1,23 @@
+package com.book.server.model.VO;
+
+import lombok.Data;
+
+/**
+ * created in 2021/8/16
+ * Project: book-store
+ *
+ * @author win7
+ */
+@Data
+public class Chapter {
+    private String bookId;
+    private String contentId;
+    private String isPay;
+    private String name;
+    private String num;
+    private String type;
+    private String words;
+    private String volumeId;
+
+
+}

+ 5 - 0
book-server/src/main/java/com/book/server/service/BookService.java

@@ -3,6 +3,7 @@ package com.book.server.service;
 import com.book.server.common.entity.PageResult;
 import com.book.server.dao.entity.Book;
 import com.book.server.model.VO.BlockRes;
+import com.book.server.model.VO.Chapter;
 import com.book.server.model.VO.QueryVO;
 
 import java.util.List;
@@ -12,4 +13,8 @@ public interface BookService {
     PageResult<Book> recommendByRead(QueryVO queryVO);
 
     List<BlockRes> getBlockByPageId(Integer pageId);
+
+    void insertBooks();
+
+    List<Chapter> getChaptersByBookId(String bookId);
 }

+ 148 - 2
book-server/src/main/java/com/book/server/service/impl/BookServiceImpl.java

@@ -1,5 +1,8 @@
 package com.book.server.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.book.server.common.entity.PageResult;
 import com.book.server.dao.entity.Book;
 import com.book.server.dao.entity.ManageBlock;
@@ -11,16 +14,21 @@ import com.book.server.dao.mapper.BookMapper;
 import com.book.server.dao.mapper.ManageBlockMapper;
 import com.book.server.dao.mapper.ManageBlockResourceMapper;
 import com.book.server.model.VO.BlockRes;
+import com.book.server.model.VO.Chapter;
 import com.book.server.model.VO.QueryVO;
 import com.book.server.service.BookService;
+import com.book.server.utils.HttpTool;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
 
 @Service
 public class BookServiceImpl implements BookService {
+    public static final Logger logger = LoggerFactory.getLogger(BookServiceImpl.class);
     @Autowired
     private BookMapper bookMapper;
 
@@ -83,4 +91,142 @@ public class BookServiceImpl implements BookService {
         }
         return list;
     }
+
+    @Override
+    public void insertBooks() {
+
+        //插入书籍基本信息
+        String bookInfoUrl = "http://new.emeixs.com/index.php/Home/Interface/listing";
+
+        String jsonStr = HttpTool.sendGet(bookInfoUrl, "");
+        JSONObject listJson = JSON.parseObject(jsonStr);
+        JSONArray list = listJson.getJSONArray("list");
+        Map<String, String> typeMap = new HashMap<String, String>();
+        typeMap.put("15", "豪门总裁");
+        typeMap.put("16", "婚恋家庭");
+        typeMap.put("17", "豪门虐恋");
+        typeMap.put("18", "甜宠萌宝");
+        typeMap.put("19", "重生逆袭");
+        typeMap.put("20", "穿越重生");
+        typeMap.put("21", "权谋宫斗");
+        typeMap.put("22", "经商种田");
+        typeMap.put("23", "出版");
+        typeMap.put("24", "其他");
+        List<Book> bookList = new ArrayList<>();
+        for (int i = 0; i < list.size(); i++) {
+            JSONObject bookObject = list.getJSONObject(i);
+            String author_name = bookObject.getString("author_name");
+            String book_brief = bookObject.getString("book_brief");
+            String book_id = bookObject.getString("book_id");
+            String book_name = bookObject.getString("book_name");
+            String chapter = bookObject.getString("chapter");
+            String charge = bookObject.getString("charge");
+            String cover = bookObject.getString("cover");
+            String ctype_id = bookObject.getString("ctype_id");
+            String gender = bookObject.getString("gender");
+            String is_show = bookObject.getString("is_show");
+            String state = bookObject.getString("state");
+            String type_id = bookObject.getString("type_id");
+            String words = bookObject.getString("words");
+            //章节列表
+            String chaptersStr = HttpTool.sendGet("http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + book_id, "");
+            JSONArray listChapters = JSON.parseArray(chaptersStr);
+            JSONObject firstChapters = listChapters.getJSONObject(1);
+            String first_chapter_id = firstChapters.getString("content_id");
+            String first_chapter_name = firstChapters.getString("name");
+            JSONObject lastChapters = listChapters.getJSONObject(listChapters.size() - 1);
+            String last_chapter_id = lastChapters.getString("content_id");
+            String last_chapter_name = lastChapters.getString("name");
+
+            Book book = new Book();
+            book.setId(Long.parseLong(book_id));
+            book.setBookCategoryId(Integer.parseInt(type_id));
+            book.setName(book_name);
+            book.setRealname(book_name);
+            book.setAuthor(author_name);
+            book.setImage(cover);
+            book.setDescription(book_brief);
+            book.setSex(gender);
+            book.setBillingType(String.valueOf(Integer.parseInt(charge) + 1));
+            book.setWordCount(words);
+            book.setChapterNum(Integer.valueOf(chapter));
+//            book.setLastChapterUtime(Integer.parseInt(System.currentTimeMillis()+""));
+            book.setCreatetime(Integer.parseInt(System.currentTimeMillis() / 1000 + ""));
+            book.setCpId(Integer.parseInt(book_id));
+            book.setCpName(book_name);
+            book.setTags(typeMap.get(ctype_id));
+            book.setState("1");
+            book.setPrice(45);
+            book.setArticleChapterOrder(4);
+            book.setAttentChapterOrder(4);
+            book.setCornerMark("hot");
+            book.setIsFinish(String.valueOf(Integer.parseInt(state) - 1));
+            book.setReferralNum(new Byte((byte) 5));
+            book.setPutAdSet(new Byte((byte) 1));
+            book.setClassifyWhiteList(new Byte((byte) 0));
+            book.setCheckRank(new Byte((byte) 0));
+            book.setRank(new Byte((byte) 6));
+            book.setExpireTime(Integer.MAX_VALUE);
+            book.setLastChapterUtime(Integer.parseInt(System.currentTimeMillis() / 1000 + ""));
+            book.setAppPrice(45);
+            book.setFirstChapterId(Long.parseLong(first_chapter_id));
+            book.setFirstChapterName(first_chapter_name);
+            book.setLastChapterId(Long.parseLong(last_chapter_id));
+            book.setLastChapterName(last_chapter_name);
+            book.setCansee("1");
+            book.setRank(new Byte((byte) 6));
+
+            bookList.add(book);
+
+
+        }
+
+        for (Book book : bookList) {
+            int i = new Random().nextInt(bookList.size());
+            book.setRecommandBookId(bookList.get(i).getId());
+            System.out.println(JSON.toJSONString(book));
+            bookMapper.insert(book);
+
+
+        }
+
+    }
+
+    @Override
+    public List<Chapter> getChaptersByBookId(String bookId) {
+        List<Chapter> list = new ArrayList<>();
+        try {
+            if (StringUtils.isEmpty(bookId)){
+                throw new IllegalArgumentException("bookId cannot be null or empty");
+            }
+            final   String chaptersUrl = "http://new.emeixs.com/index.php/Home/Interface/chapters/bid/" + bookId;
+            String result = HttpTool.sendGet(chaptersUrl, "");
+            if (StringUtils.isEmpty(result)) {
+                return list;
+            }
+            JSONArray jsonArray = JSON.parseArray(result);
+            for (int i = 0; i < jsonArray.size(); i++) {
+                JSONObject jsonObject = jsonArray.getJSONObject(i);
+                Chapter chapter = new Chapter();
+                chapter.setBookId(jsonObject.getString("book_id"));
+                chapter.setContentId(jsonObject.getString("content_id"));
+                chapter.setIsPay(jsonObject.getString("ispay"));
+                chapter.setName(jsonObject.getString("name"));
+                chapter.setNum(jsonObject.getString("num"));
+                chapter.setType(jsonObject.getString("type"));
+                chapter.setVolumeId(jsonObject.getString("volume_id"));
+                chapter.setWords(jsonObject.getString("words"));
+                list.add(chapter);
+            }
+        } catch (Exception e) {
+            logger.error(e.getMessage());
+            e.printStackTrace();
+
+            return list;
+        }
+
+        return list;
+    }
 }
+
+

+ 397 - 0
book-server/src/main/java/com/book/server/utils/HttpTool.java

@@ -0,0 +1,397 @@
+package com.book.server.utils;
+
+
+import javax.net.ssl.HttpsURLConnection;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+
+public class HttpTool {
+    public static final String GET = "GET";
+    public static final String POST = "POST";
+    // 签名key
+    public final static String SIGNATURE = "sign";
+    // 签名方法key
+    public final static String SIGN_METHOD = "sign_type";
+    // =
+    public static final String QSTRING_EQUAL = "=";
+    // &
+    public static final String QSTRING_SPLIT = "&";
+
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param address 发送请求的URL
+     * @param form    请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+
+    public static String sendGet(final String address, String form) {
+        String req = address + "?" + form;
+        System.out.println("请求:" + req);
+        StringBuilder response = new StringBuilder();
+        HttpURLConnection connection = null;
+        InputStream in = null;
+        try {
+            // 创建一个URL对象并传入地址
+            URL url = new URL(req);
+            // 用地址打开连接通道
+            connection = (HttpURLConnection) url.openConnection();
+            // 设置请求方式为get
+            connection.setRequestMethod("GET");
+            // 设置连接超时为8秒
+            connection.setConnectTimeout(8000);
+            // 设置读取超时为8秒
+            connection.setReadTimeout(8000);
+            connection.setRequestProperty("Charset", "utf-8");
+            // 设置可取
+//			connection.setDoInput(true);
+//			// 设置可读
+//			connection.setDoOutput(true);
+//			// 得到输入流
+            in = connection.getInputStream();
+
+            // 创建高效流对象
+            BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
+            // 创建StringBuilder对象存储数据
+
+            String line;// 一次读取一行
+            while ((line = reader.readLine()) != null) {
+                response.append(line);// 得到的数据存入StringBuilder
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (connection != null) {// 通道不为null
+                connection.disconnect();// 关闭通道
+            }
+            try {
+                if (in != null) {
+                    in.close();
+                }
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return response.toString();
+    }
+
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+
+    public static String sendGetCookie(String url, String param, String cookie) {
+        String result = "";
+        BufferedReader in = null;
+        try {
+            String urlName = url + "?" + param;
+            System.out.println(urlName);
+            URL realUrl = new URL(urlName);
+            // 打开和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.setRequestProperty("Cookie", cookie);
+            // 建立实际的连接
+            conn.connect();
+            // 获取所有响应头字段
+            Map<String, List<String>> map = conn.getHeaderFields();
+            // 遍历所有的响应头字段
+            // for (String key : map.keySet()) {
+            // System.out.println(key + "--->" + map.get(key));
+            // }
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送GET请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输入流
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 向指定URL发送POST方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+    public static String sendPost(String url, String param) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            URL realUrl = new URL(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)");
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送POST请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 向指定URL发送POST方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+    public static String sendPostCookie(String url, String param, String cookie) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            URL realUrl = new URL(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.setRequestProperty("Cookie", cookie);
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送POST请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * https访问
+     */
+    public static String doHttps(String httpurl, String method, String param) {
+        try {
+            URL reqURL = new URL(httpurl + param); // 创建URL对象
+            HttpsURLConnection httpsConn = (HttpsURLConnection) reqURL
+                    .openConnection();
+
+            /*
+             * 下面这段代码实现向Web页面发送数据,实现与网页的交互访问 httpsConn.setDoOutput(true);
+             * OutputStreamWriter out = new
+             * OutputStreamWriter(huc.getOutputStream(), "8859_1"); out.write(
+             * "……" ); out.flush(); out.close();
+             */
+
+            // 取得该连接的输入流,以读取响应内容
+            InputStreamReader insr = new InputStreamReader(
+                    httpsConn.getInputStream());
+
+            // 读取服务器的响应内容并显示
+            int respInt = insr.read();
+            while (respInt != -1) {
+                System.out.print((char) respInt);
+                respInt = insr.read();
+            }
+        } catch (Exception e) {
+            // TODO: handle exception
+        }
+
+        return "";
+    }
+
+
+    /**
+     * 除去请求要素中的空值和签名参数
+     *
+     * @param para 请求要素
+     * @return 去掉空值与签名参数后的请求要素
+     */
+    public static Map<String, String> paraFilter(Map<String, String> para) {
+
+        Map<String, String> result = new HashMap<String, String>();
+
+        if (para == null || para.size() <= 0) {
+            return result;
+        }
+
+        for (String key : para.keySet()) {
+            String value = para.get(key);
+            if (value == null || value.equals("")
+                    || key.equalsIgnoreCase(SIGNATURE)
+                    || key.equalsIgnoreCase(SIGN_METHOD)) {
+                continue;
+            }
+            result.put(key, value);
+        }
+
+        return result;
+    }
+
+    /**
+     * 把请求要素按照“参数=参数值”的模式用“&”字符拼接成字符串
+     *
+     * @param para   请求要素
+     * @param sort   是否需要根据key值作升序排列
+     * @param encode 是否需要URL编码
+     * @return 拼接成的字符串
+     */
+    public static String createLinkString(Map<String, String> para,
+                                          boolean sort, boolean encode) {
+
+        List<String> keys = new ArrayList<String>(para.keySet());
+
+        if (sort)
+            Collections.sort(keys);
+
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < keys.size(); i++) {
+            String key = keys.get(i);
+            String value = para.get(key);
+
+            if (encode) {
+                try {
+                    value = URLEncoder.encode(value, "utf-8");
+                } catch (UnsupportedEncodingException e) {
+                }
+            }
+
+            if (i == keys.size() - 1) {// 拼接时,不包括最后一个&字符
+                sb.append(key).append(QSTRING_EQUAL).append(value);
+            } else {
+                sb.append(key).append(QSTRING_EQUAL).append(value)
+                        .append(QSTRING_SPLIT);
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 对传入的参数进行MD5摘要
+     *
+     * @param str 需进行MD5摘要的数据
+     * @return MD5摘要值
+     */
+    public static String md5Summary(String str) {
+
+        if (str == null) {
+            return null;
+        }
+
+        MessageDigest messageDigest = null;
+
+        try {
+            messageDigest = MessageDigest.getInstance("MD5");
+            messageDigest.reset();
+            messageDigest.update(str.getBytes(StandardCharsets.UTF_8));
+        } catch (NoSuchAlgorithmException e) {
+
+            return str;
+        }
+
+        byte[] byteArray = messageDigest.digest();
+
+        StringBuffer md5StrBuff = new StringBuffer();
+
+        for (int i = 0; i < byteArray.length; i++) {
+            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
+                md5StrBuff.append("0").append(
+                        Integer.toHexString(0xFF & byteArray[i]));
+            else
+                md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
+        }
+
+        return md5StrBuff.toString();
+    }
+
+
+
+}

+ 52 - 0
book-server/src/main/resources/application-dev.yml

@@ -0,0 +1,52 @@
+server:
+  port: 8080
+
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://121.41.100.198:3306/test_cps?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+    username: root
+    password: root
+    #下面为连接池补充设置
+    druid:
+      initial-size: 5 # 初始化
+      max-active: 5 # 最大
+      min-idle: 5 # 最小
+      max-wait: 6000 # 超时时间
+      time-between-eviction-runs-millis: 60000 # 每分钟检查一次空闲链接
+      min-evictable-idle-time-millis: 300000 # 空闲链接可以保持多久而不被驱逐
+      # 检测链接是否有效的query
+      validation-query: SELECT 1 FROM DUAL
+      test-while-idle: true # 检测到链接空闲时,验证是否有效
+      test-on-borrow: false # 申请链接时,不检测
+      test-on-return: false # 返回链接时,不检测
+      pool-prepared-statements: false # 是否缓存preparedStatement,oracle打开,mysql关闭
+      # 如果上面开启了游标,这里要设置一下大小,例如 50
+      max-pool-prepared-statement-per-connection-size: -1
+      # 统计、监控配置
+      filters: stat,wall # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      # 合并执行的相同sql,避免因为参数不同而统计多条sql语句;开启慢sql记录
+      connect-properties: config.stat.mergeSql=true;config.stat.slowSqlMillis=500
+      use-global-data-source-stat: true # 合并多个DruidDataSource的监控数据
+      stat-view-servlet:
+        enabled: true
+        login-username: tianyun
+        login-password: tianyunperfect
+        allow: # 默认运行所有
+        deny: # 默认即可
+        reset-enable: true
+
+
+mybatis:
+  type-aliases-package: com.book.server.entity
+  mapper-locations: classpath:mapper/*Mapper.xml
+
+
+# 设置debug模式下打印mysql
+logging:
+  level:
+    com:
+      book:
+        server:
+          mapper: debug

+ 52 - 0
book-server/src/main/resources/application-test.yml

@@ -0,0 +1,52 @@
+server:
+  port: 9999
+
+spring:
+  datasource:
+    type: com.alibaba.druid.pool.DruidDataSource
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://www.tianyunperfect.cn:3306/test_cps?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+    username: test_cps
+    password: xKysDECnJLXkMYdJ
+    #下面为连接池补充设置
+    druid:
+      initial-size: 5 # 初始化
+      max-active: 5 # 最大
+      min-idle: 5 # 最小
+      max-wait: 6000 # 超时时间
+      time-between-eviction-runs-millis: 60000 # 每分钟检查一次空闲链接
+      min-evictable-idle-time-millis: 300000 # 空闲链接可以保持多久而不被驱逐
+      # 检测链接是否有效的query
+      validation-query: SELECT 1 FROM DUAL
+      test-while-idle: true # 检测到链接空闲时,验证是否有效
+      test-on-borrow: false # 申请链接时,不检测
+      test-on-return: false # 返回链接时,不检测
+      pool-prepared-statements: false # 是否缓存preparedStatement,oracle打开,mysql关闭
+      # 如果上面开启了游标,这里要设置一下大小,例如 50
+      max-pool-prepared-statement-per-connection-size: -1
+      # 统计、监控配置
+      filters: stat,wall # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
+      # 合并执行的相同sql,避免因为参数不同而统计多条sql语句;开启慢sql记录
+      connect-properties: config.stat.mergeSql=true;config.stat.slowSqlMillis=500
+      use-global-data-source-stat: true # 合并多个DruidDataSource的监控数据
+      stat-view-servlet:
+        enabled: true
+        login-username: tianyun
+        login-password: tianyunperfect
+        allow: # 默认运行所有
+        deny: # 默认即可
+        reset-enable: true
+
+
+mybatis:
+  type-aliases-package: com.book.server.entity
+  mapper-locations: classpath:mapper/*Mapper.xml
+
+
+# 设置debug模式下打印mysql
+logging:
+  level:
+    com:
+      book:
+        server:
+          mapper: debug

+ 3 - 48
book-server/src/main/resources/application.yml

@@ -2,51 +2,6 @@ server:
   port: 9999
 
 spring:
-  datasource:
-    type: com.alibaba.druid.pool.DruidDataSource
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    url: jdbc:mysql://www.tianyunperfect.cn:3306/test_cps?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
-    username: test_cps
-    password: xKysDECnJLXkMYdJ
-    #下面为连接池补充设置
-    druid:
-      initial-size: 5 # 初始化
-      max-active: 5 # 最大
-      min-idle: 5 # 最小
-      max-wait: 6000 # 超时时间
-      time-between-eviction-runs-millis: 60000 # 每分钟检查一次空闲链接
-      min-evictable-idle-time-millis: 300000 # 空闲链接可以保持多久而不被驱逐
-      # 检测链接是否有效的query
-      validation-query: SELECT 1 FROM DUAL
-      test-while-idle: true # 检测到链接空闲时,验证是否有效
-      test-on-borrow: false # 申请链接时,不检测
-      test-on-return: false # 返回链接时,不检测
-      pool-prepared-statements: false # 是否缓存preparedStatement,oracle打开,mysql关闭
-      # 如果上面开启了游标,这里要设置一下大小,例如 50
-      max-pool-prepared-statement-per-connection-size: -1
-      # 统计、监控配置
-      filters: stat,wall # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
-      # 合并执行的相同sql,避免因为参数不同而统计多条sql语句;开启慢sql记录
-      connect-properties: config.stat.mergeSql=true;config.stat.slowSqlMillis=500
-      use-global-data-source-stat: true # 合并多个DruidDataSource的监控数据
-      stat-view-servlet:
-        enabled: true
-        login-username: tianyun
-        login-password: tianyunperfect
-        allow: # 默认运行所有
-        deny: # 默认即可
-        reset-enable: true
-
-
-mybatis:
-  type-aliases-package: com.book.server.entity
-  mapper-locations: classpath:mapper/*Mapper.xml
-
-
-# 设置debug模式下打印mysql
-logging:
-  level:
-    com:
-      book:
-        server:
-          mapper: debug
+  # 环境 dev:开发环境|test:测试环境|prod:生产环境
+  profiles:
+    active: dev #激活的配置文件

+ 400 - 0
book-server/src/test/java/utils/HttpTool.java

@@ -0,0 +1,400 @@
+package utils;
+
+
+import javax.net.ssl.HttpsURLConnection;
+import java.io.*;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.*;
+
+public class HttpTool {
+    public static final String GET = "GET";
+    public static final String POST = "POST";
+    // 签名key
+    public final static String SIGNATURE = "sign";
+    // 签名方法key
+    public final static String SIGN_METHOD = "sign_type";
+    // =
+    public static final String QSTRING_EQUAL = "=";
+    // &
+    public static final String QSTRING_SPLIT = "&";
+
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param address 发送请求的URL
+     * @param form    请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+
+    public static String sendGet(final String address, String form) {
+        String req = address + "?" + form;
+        System.out.println("请求:" + req);
+        StringBuilder response = new StringBuilder();
+        HttpURLConnection connection = null;
+        InputStream in = null;
+        try {
+            // 创建一个URL对象并传入地址
+            URL url = new URL(req);
+            // 用地址打开连接通道
+            connection = (HttpURLConnection) url.openConnection();
+            // 设置请求方式为get
+            connection.setRequestMethod("GET");
+            // 设置连接超时为8秒
+            connection.setConnectTimeout(8000);
+            // 设置读取超时为8秒
+            connection.setReadTimeout(8000);
+            connection.setRequestProperty("Charset", "utf-8");
+            // 设置可取
+//			connection.setDoInput(true);
+//			// 设置可读
+//			connection.setDoOutput(true);
+//			// 得到输入流
+            in = connection.getInputStream();
+
+            // 创建高效流对象
+            BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
+            // 创建StringBuilder对象存储数据
+
+            String line;// 一次读取一行
+            while ((line = reader.readLine()) != null) {
+                response.append(line);// 得到的数据存入StringBuilder
+            }
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (connection != null) {// 通道不为null
+                connection.disconnect();// 关闭通道
+            }
+            try {
+                if (in != null) {
+                    in.close();
+                }
+
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        return response.toString();
+    }
+
+    /**
+     * 向指定URL发送GET方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+
+    public static String sendGetCookie(String url, String param, String cookie) {
+        String result = "";
+        BufferedReader in = null;
+        try {
+            String urlName = url + "?" + param;
+            System.out.println(urlName);
+            URL realUrl = new URL(urlName);
+            // 打开和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.setRequestProperty("Cookie", cookie);
+            // 建立实际的连接
+            conn.connect();
+            // 获取所有响应头字段
+            Map<String, List<String>> map = conn.getHeaderFields();
+            // 遍历所有的响应头字段
+            // for (String key : map.keySet()) {
+            // System.out.println(key + "--->" + map.get(key));
+            // }
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送GET请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输入流
+        finally {
+            try {
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 向指定URL发送POST方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+    public static String sendPost(String url, String param) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            URL realUrl = new URL(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)");
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送POST请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 向指定URL发送POST方法的请求
+     *
+     * @param url   发送请求的URL
+     * @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式。
+     * @return URL所代表远程资源的响应
+     */
+    public static String sendPostCookie(String url, String param, String cookie) {
+        PrintWriter out = null;
+        BufferedReader in = null;
+        String result = "";
+        try {
+            URL realUrl = new URL(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.setRequestProperty("Cookie", cookie);
+            // 发送POST请求必须设置如下两行
+            conn.setDoOutput(true);
+            conn.setDoInput(true);
+            // 获取URLConnection对象对应的输出流
+            out = new PrintWriter(conn.getOutputStream());
+            // 发送请求参数
+            out.print(param);
+            // flush输出流的缓冲
+            out.flush();
+            // 定义BufferedReader输入流来读取URL的响应
+            in = new BufferedReader(
+                    new InputStreamReader(conn.getInputStream()));
+            String line;
+            while ((line = in.readLine()) != null) {
+                result += line;
+                // result += "/n" + line;
+            }
+        } catch (Exception e) {
+            System.out.println("发送POST请求出现异常!" + e);
+            e.printStackTrace();
+        }
+        // 使用finally块来关闭输出流、输入流
+        finally {
+            try {
+                if (out != null) {
+                    out.close();
+                }
+                if (in != null) {
+                    in.close();
+                }
+            } catch (IOException ex) {
+                ex.printStackTrace();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * https访问
+     */
+    public static String doHttps(String httpurl, String method, String param) {
+        try {
+            URL reqURL = new URL(httpurl + param); // 创建URL对象
+            HttpsURLConnection httpsConn = (HttpsURLConnection) reqURL
+                    .openConnection();
+
+            /*
+             * 下面这段代码实现向Web页面发送数据,实现与网页的交互访问 httpsConn.setDoOutput(true);
+             * OutputStreamWriter out = new
+             * OutputStreamWriter(huc.getOutputStream(), "8859_1"); out.write(
+             * "……" ); out.flush(); out.close();
+             */
+
+            // 取得该连接的输入流,以读取响应内容
+            InputStreamReader insr = new InputStreamReader(
+                    httpsConn.getInputStream());
+
+            // 读取服务器的响应内容并显示
+            int respInt = insr.read();
+            while (respInt != -1) {
+                System.out.print((char) respInt);
+                respInt = insr.read();
+            }
+        } catch (Exception e) {
+            // TODO: handle exception
+        }
+
+        return "";
+    }
+
+
+    /**
+     * 除去请求要素中的空值和签名参数
+     *
+     * @param para 请求要素
+     * @return 去掉空值与签名参数后的请求要素
+     */
+    public static Map<String, String> paraFilter(Map<String, String> para) {
+
+        Map<String, String> result = new HashMap<String, String>();
+
+        if (para == null || para.size() <= 0) {
+            return result;
+        }
+
+        for (String key : para.keySet()) {
+            String value = para.get(key);
+            if (value == null || value.equals("")
+                    || key.equalsIgnoreCase(SIGNATURE)
+                    || key.equalsIgnoreCase(SIGN_METHOD)) {
+                continue;
+            }
+            result.put(key, value);
+        }
+
+        return result;
+    }
+
+    /**
+     * 把请求要素按照“参数=参数值”的模式用“&”字符拼接成字符串
+     *
+     * @param para   请求要素
+     * @param sort   是否需要根据key值作升序排列
+     * @param encode 是否需要URL编码
+     * @return 拼接成的字符串
+     */
+    public static String createLinkString(Map<String, String> para,
+                                          boolean sort, boolean encode) {
+
+        List<String> keys = new ArrayList<String>(para.keySet());
+
+        if (sort)
+            Collections.sort(keys);
+
+        StringBuilder sb = new StringBuilder();
+        for (int i = 0; i < keys.size(); i++) {
+            String key = keys.get(i);
+            String value = para.get(key);
+
+            if (encode) {
+                try {
+                    value = URLEncoder.encode(value, "utf-8");
+                } catch (UnsupportedEncodingException e) {
+                }
+            }
+
+            if (i == keys.size() - 1) {// 拼接时,不包括最后一个&字符
+                sb.append(key).append(QSTRING_EQUAL).append(value);
+            } else {
+                sb.append(key).append(QSTRING_EQUAL).append(value)
+                        .append(QSTRING_SPLIT);
+            }
+        }
+        return sb.toString();
+    }
+
+    /**
+     * 对传入的参数进行MD5摘要
+     *
+     * @param str 需进行MD5摘要的数据
+     * @return MD5摘要值
+     */
+    public static String md5Summary(String str) {
+
+        if (str == null) {
+            return null;
+        }
+
+        MessageDigest messageDigest = null;
+
+        try {
+            messageDigest = MessageDigest.getInstance("MD5");
+            messageDigest.reset();
+            messageDigest.update(str.getBytes(StandardCharsets.UTF_8));
+        } catch (NoSuchAlgorithmException e) {
+
+            return str;
+        }
+
+        byte[] byteArray = messageDigest.digest();
+
+        StringBuffer md5StrBuff = new StringBuffer();
+
+        for (int i = 0; i < byteArray.length; i++) {
+            if (Integer.toHexString(0xFF & byteArray[i]).length() == 1)
+                md5StrBuff.append("0").append(
+                        Integer.toHexString(0xFF & byteArray[i]));
+            else
+                md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
+        }
+
+        return md5StrBuff.toString();
+    }
+
+
+    public static void main(String[] args) {
+        String result = sendGet("http://localhost:8080/agentPay", "account_type=01&amount=ds&appid=4110&banck_name=dsf&card_number=fsds&customer_name=sdfsdf&customer_type=01&mchorder_id=1505280293071&pay_password=123&sign=cf587510835e4f2d2fbdf43b094a13e4");
+        System.out.println(result);
+    }
+}