Bladeren bron

Merge remote-tracking branch 'origin/master'

tianyunperfect 3 jaren geleden
bovenliggende
commit
fbe30e7866

+ 3 - 0
book-dao/src/main/java/com/book/dao/cps/mapper/PlatformMapper.java

@@ -1,6 +1,7 @@
 package com.book.dao.cps.mapper;
 
 import com.book.dao.cps.pojo.Platform;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -19,4 +20,6 @@ public interface PlatformMapper {
 
     int updateByPrimaryKey(Platform record);
     List<Platform> selectAll();
+
+    Platform selectByAppid(@Param("appid") String appid);
 }

+ 4 - 0
book-dao/src/main/resources/mapper/cps/PlatformMapper.xml

@@ -31,6 +31,10 @@
     <select id="selectAll" resultMap="BaseResultMap">
       SELECT * FROM platform;
     </select>
+    <select id="selectByAppid" parameterType="string" resultMap="BaseResultMap">
+        SELECT  * from platform where appid = #{appid}
+
+    </select>
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
     delete from platform
     where id = #{id,jdbcType=INTEGER}

+ 23 - 2
book-push/src/main/java/com/book/push/config/WxOpenInRedisBookConfigStorage.java

@@ -43,8 +43,15 @@ public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
 
     public String getComponentTokenCacheKey() {
         if (this.getComponentAppId() == null || this.getComponentAppSecret() == null || this.getComponentVerifyTicket() == null) {
-            throw new NullPointerException("ComponentAppId , ComponentAppSecret and ComponentVerifyTicket " +
-                    "must be not null,please set component appid");
+            System.out.println("getVerifyTicketCacheKey is null,please set component appid");
+//            throw new NullPointerException("ComponentAppId " +
+//                    "must not be  null,please set component appid");
+        }
+        if (this.getComponentAppSecret() == null) {
+            System.out.println("ComponentAppSecret is null, please set  ComponentAppSecret");
+        }
+        if(this.getComponentVerifyTicket() == null){
+            System.out.println("ComponentVerifyTicket is null, please set  ComponentVerifyTicket");
         }
         ComponentInfo componentInfo = new ComponentInfo(getComponentAppId(), getComponentAppSecret(), getComponentVerifyTicket());
         return WxThirdPartService.TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(componentInfo));
@@ -56,5 +63,19 @@ public class WxOpenInRedisBookConfigStorage extends WxOpenInRedisConfigStorage {
         return WxThirdPartService.TOKEN_KEY_PREFIX + Md5Util.md5(JsonUtils.toJsonString(authorizerInfo));
     }
 
+    @Override
+    public void setComponentVerifyTicket(String componentVerifyTicket) {
+        if (componentVerifyTicket==null){
+            throw new NullPointerException("componentVerifyTicket is null " );
+        }
+        super.setComponentVerifyTicket(componentVerifyTicket);
+    }
 
+    @Override
+    public void setComponentAccessToken(String componentAccessToken) {
+        if (componentAccessToken==null){
+            throw new NullPointerException("componentAccessToken is null " );
+        }
+        super.setComponentAccessToken(componentAccessToken);
+    }
 }

+ 126 - 0
book-push/src/main/java/com/book/push/controller/WxEventController.java

@@ -0,0 +1,126 @@
+package com.book.push.controller;
+
+import com.book.dao.cps.pojo.Platform;
+import com.book.push.service.dao.PlatformService;
+import com.book.push.service.wx.WxThirdPartService;
+import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
+import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
+import me.chanjar.weixin.open.api.WxOpenService;
+import me.chanjar.weixin.open.bean.message.WxOpenXmlMessage;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * created in 2021/8/26
+ * Project: book-store
+ *  接收微信事件
+ * @author win7
+ */
+@RestController
+@RequestMapping("/api/wechat")
+public class WxEventController {
+
+    public static final Logger logger = LoggerFactory.getLogger(WxEventController.class);
+    @Autowired
+    private WxThirdPartService thirdPartService;
+    @Autowired
+    private PlatformService platformService;
+
+
+    /**
+     * 公众号事件接口
+     * @param requestBody
+     * @param appId
+     * @param signature
+     * @param timestamp
+     * @param nonce
+     * @param openid
+     * @param encType
+     * @param msgSignature
+     * @return
+     */
+    @RequestMapping("/mpapi/appid/{appId}")
+    public Object callback(@RequestBody(required = false) String requestBody,
+                           @PathVariable("appId") String appId,
+                           @RequestParam("signature") String signature,
+                           @RequestParam("timestamp") String timestamp,
+                           @RequestParam("nonce") String nonce,
+                           @RequestParam("openid") String openid,
+                           @RequestParam("encrypt_type") String encType,
+                           @RequestParam("msg_signature") String msgSignature) {
+        logger.info(
+                "\n接收微信请求:[appId=[{}], openid=[{}], signature=[{}], encType=[{}], msgSignature=[{}],"
+                        + " timestamp=[{}], nonce=[{}], requestBody=[\n{}\n] ",
+                appId, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
+
+
+        Platform platform = platformService.selectByAppid(appId);
+
+        WxOpenService wxOpenService = thirdPartService.getWxOpenServiceByPlatFormId(platform.getId());
+
+        if (!StringUtils.equalsIgnoreCase("aes", encType)
+                || !wxOpenService.getWxOpenComponentService().checkSignature(timestamp, nonce, signature)) {
+            throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
+        }
+
+        String out = "";
+        // aes加密的消息
+        WxMpXmlMessage inMessage = WxOpenXmlMessage.fromEncryptedMpXml(requestBody,
+                wxOpenService.getWxOpenConfigStorage(), timestamp, nonce, msgSignature);
+        logger.debug("\n消息解密后内容为:\n{} ", inMessage.toString());
+        // 全网发布测试用例
+        if (StringUtils.equalsAnyIgnoreCase(appId, "wxd101a85aa106f53e", "wx570bc396a51b8ff8")) {
+            try {
+                out = AllNetTest(appId, wxOpenService, out, inMessage);
+            } catch (WxErrorException e) {
+                logger.error("测试报错:", e);
+            }
+        } else {
+            WxMpXmlOutMessage outMessage = thirdPartService.getWxThirdPartMessageRouter().route(inMessage, platform.getId(), appId);
+            if (outMessage != null) {
+                out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(outMessage, wxOpenService.getWxOpenConfigStorage());
+            }
+        }
+        return out;
+    }
+
+
+    /**
+     * 全网测试
+     *
+     * @param appId
+     * @param wxOpenService
+     * @param out
+     * @param inMessage
+     * @return
+     * @throws WxErrorException
+     */
+    private String AllNetTest(String appId, WxOpenService wxOpenService, String out, WxMpXmlMessage inMessage) throws WxErrorException {
+        if (StringUtils.equals(inMessage.getMsgType(), "text")) {
+            if (StringUtils.equals(inMessage.getContent(), "TESTCOMPONENT_MSG_TYPE_TEXT")) {
+                out = WxOpenXmlMessage.wxMpOutXmlMessageToEncryptedXml(
+                        WxMpXmlOutMessage.TEXT().content("TESTCOMPONENT_MSG_TYPE_TEXT_callback")
+                                .fromUser(inMessage.getToUser())
+                                .toUser(inMessage.getFromUser())
+                                .build(),
+                        wxOpenService.getWxOpenConfigStorage()
+                );
+            } else if (StringUtils.startsWith(inMessage.getContent(), "QUERY_AUTH_CODE:")) {
+                String msg = inMessage.getContent().replace("QUERY_AUTH_CODE:", "") + "_from_api";
+                WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(msg).toUser(inMessage.getFromUser()).build();
+                wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage);
+            }
+        } else if (StringUtils.equals(inMessage.getMsgType(), "event")) {
+            WxMpKefuMessage kefuMessage = WxMpKefuMessage.TEXT().content(inMessage.getEvent() + "from_callback").toUser(inMessage.getFromUser()).build();
+            wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appId).getKefuService().sendKefuMessage(kefuMessage);
+        }
+        return out;
+    }
+
+
+}

+ 9 - 4
book-push/src/main/java/com/book/push/controller/WxRedirectController.java

@@ -16,6 +16,8 @@ import lombok.AllArgsConstructor;
 import me.chanjar.weixin.common.api.WxConsts;
 import me.chanjar.weixin.common.bean.oauth2.WxOAuth2AccessToken;
 import me.chanjar.weixin.common.error.WxErrorException;
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import me.chanjar.weixin.open.api.WxOpenMpService;
 import me.chanjar.weixin.open.api.WxOpenService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,7 +37,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 @Controller
 @RequestMapping("/wx/redirect/{appid}")
 public class WxRedirectController {
-//    public static final Logger logger = LoggerFactory.getLogger(WxRedirectController.class);
+    public static final Logger logger = LoggerFactory.getLogger(WxRedirectController.class);
     @Autowired
     private UserService userService;
     @Autowired
@@ -98,11 +100,14 @@ public class WxRedirectController {
             String openId = accessToken.getOpenId();
             User user = userService.selectByOpenId(openId);
             if (user == null) {
-                user = new User();
-                user.setOpenid(openId);
-                user.setChannelId(channelId);
+
 
                 //todo 获取基本信息,save
+                WxOpenMpService wxMpServiceByAppid = wxOpenService.getWxOpenComponentService().getWxMpServiceByAppid(appid);
+                WxMpUser wxMpUser = wxMpServiceByAppid.getUserService()
+                        .userInfo(openId, null);
+
+               user =  userService.createUserByWxUser(wxMpUser,channelId);
 
             }
             if (userSlientExist(user, null, defaultAdminConfig.getAppid())) {

+ 21 - 3
book-push/src/main/java/com/book/push/handler/SubscribeHandler.java

@@ -1,12 +1,18 @@
 package com.book.push.handler;
 
+import com.book.dao.cps.pojo.AdminConfig;
+import com.book.dao.cps.pojo.User;
 import com.book.push.builder.TextBuilder;
+import com.book.push.service.dao.AdminConfigService;
+import com.book.push.service.dao.UserService;
 import me.chanjar.weixin.common.error.WxErrorException;
 import me.chanjar.weixin.common.session.WxSessionManager;
 import me.chanjar.weixin.mp.api.WxMpService;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
 import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
 import me.chanjar.weixin.mp.bean.result.WxMpUser;
+import org.checkerframework.checker.units.qual.A;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.util.Map;
@@ -16,7 +22,10 @@ import java.util.Map;
  */
 @Component
 public class SubscribeHandler extends AbstractHandler {
-
+    @Autowired
+    private UserService userService;
+    @Autowired
+    private AdminConfigService adminConfigService;
     @Override
     public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                     Map<String, Object> context, WxMpService weixinService,
@@ -27,9 +36,18 @@ public class SubscribeHandler extends AbstractHandler {
         // 获取微信用户基本信息
         try {
             WxMpUser userWxInfo = weixinService.getUserService()
-                .userInfo(wxMessage.getFromUser(), null);
+                    .userInfo(wxMessage.getFromUser(), null);
             if (userWxInfo != null) {
                 // TODO 可以添加关注用户到本地数据库
+
+                String openId = userWxInfo.getOpenId();
+                User user = userService.selectByOpenId(openId);
+                if (user==null){
+                    AdminConfig adminConfig = adminConfigService.selectByAppid(wxMessage.getToUser());
+                    userService.createUserByWxUser(userWxInfo,adminConfig.getAdminId());
+
+                }
+
             }
         } catch (WxErrorException e) {
             if (e.getError().getErrorCode() == 48001) {
@@ -62,7 +80,7 @@ public class SubscribeHandler extends AbstractHandler {
      * 处理特殊请求,比如如果是扫码进来的,可以做相应处理
      */
     private WxMpXmlOutMessage handleSpecial(WxMpXmlMessage wxMessage)
-        throws Exception {
+            throws Exception {
         //TODO
         return null;
     }

+ 2 - 0
book-push/src/main/java/com/book/push/service/dao/PlatformService.java

@@ -14,4 +14,6 @@ import java.util.Map;
 
 public interface PlatformService {
     Map<Integer, Platform> selectAll();
+
+    Platform selectByAppid(String appId);
 }

+ 2 - 0
book-push/src/main/java/com/book/push/service/dao/UserService.java

@@ -2,6 +2,7 @@ package com.book.push.service.dao;
 
 
 import com.book.dao.cps.pojo.User;
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
 
 /**
  * created in 2021/8/17
@@ -14,4 +15,5 @@ public interface UserService {
      User selectUserByUser(User user);
      User selectByOpenId(String openId);
      User selectById(Long id);
+     User createUserByWxUser(WxMpUser wxMpUser,int channel_id);
 }

+ 5 - 0
book-push/src/main/java/com/book/push/service/dao/impl/PlatformServiceImpl.java

@@ -27,4 +27,9 @@ public class PlatformServiceImpl implements PlatformService {
         Map<Integer, Platform> collect = platforms.stream().collect(Collectors.toMap(Platform::getId, Platform -> Platform));
         return collect;
     }
+
+    @Override
+    public Platform selectByAppid(String appId) {
+        return platformMapper.selectByAppid(appId);
+    }
 }

+ 26 - 0
book-push/src/main/java/com/book/push/service/dao/impl/UserServiceImpl.java

@@ -3,6 +3,7 @@ package com.book.push.service.dao.impl;
 import com.book.dao.cps.mapper.UserMapper;
 import com.book.dao.cps.pojo.User;
 import com.book.push.service.dao.UserService;
+import me.chanjar.weixin.mp.bean.result.WxMpUser;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -16,6 +17,7 @@ import org.springframework.stereotype.Service;
 public class UserServiceImpl implements UserService {
     @Autowired
     private UserMapper userMapper;
+
     @Override
     public User selectUserByUser(User user) {
         return userMapper.selectByUser(user);
@@ -30,4 +32,28 @@ public class UserServiceImpl implements UserService {
     public User selectById(Long id) {
         return userMapper.selectByPrimaryKey(id);
     }
+
+    @Override
+    public User createUserByWxUser(WxMpUser wxMpUser, int channel_id) {
+
+        User user = new User();
+        user.setOpenid(wxMpUser.getOpenId());
+        user.setArea(wxMpUser.getCity());
+        user.setCity(wxMpUser.getCity());
+        user.setCountry(wxMpUser.getCountry());
+        user.setUnionid(wxMpUser.getUnionId());
+        user.setNickname(wxMpUser.getNickname());
+        user.setSex(wxMpUser.getSex());
+//        user.setMobile(wxMpUser.getmobile);
+        user.setAvatar(wxMpUser.getHeadImgUrl());
+        user.setSubscribeTime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
+        user.setOperateTime(user.getSubscribeTime());
+//        user.setRegisterIp(wxMpUser.geti);
+        user.setProvince(wxMpUser.getProvince());
+        user.setCreatetime(Integer.valueOf(String.valueOf(System.currentTimeMillis() / 1000)));
+        user.setChannelId(channel_id);
+
+        userMapper.insert(user);
+        return user;
+    }
 }

+ 4 - 0
book-push/src/main/java/com/book/push/service/wx/WxThirdPartService.java

@@ -1,5 +1,6 @@
 package com.book.push.service.wx;
 
+import com.book.push.service.wx.impl.WxThirdPartMessageRouter;
 import me.chanjar.weixin.open.api.WxOpenComponentService;
 import me.chanjar.weixin.open.api.WxOpenService;
 
@@ -15,4 +16,7 @@ public interface WxThirdPartService {
     public static final String VERIFY_TICKET_KEY_PREFIX = "easywechat.open_platform.verify_ticket.";
     public static final String TOKEN_KEY_PREFIX = "easywechat.kernel.access_token.";
     WxOpenService getWxOpenServiceByPlatFormId(Integer platFormId);
+
+
+    WxThirdPartMessageRouter getWxThirdPartMessageRouter();
 }

+ 19 - 1
book-push/src/main/java/com/book/push/service/wx/impl/WxThirdPartMessageRouter.java

@@ -6,11 +6,13 @@ import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
 import me.chanjar.weixin.open.api.WxOpenService;
 import me.chanjar.weixin.open.api.impl.WxOpenMessageRouter;
 
+import java.util.HashMap;
 import java.util.Map;
 
 /**
  * created in 2021/8/20
  * Project: book-store
+ * 消息路由
  *
  * @author win7
  */
@@ -23,8 +25,24 @@ public class WxThirdPartMessageRouter extends WxOpenMessageRouter {
         this.wxThirdPartService = wxThirdPartService;
     }
 
-    public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, Integer platFormId ,Map<String, Object> context, String appId) {
+    public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, Integer platFormId, Map<String, Object> context, String appId) {
         return this.route(wxMessage, context, wxThirdPartService.getWxOpenServiceByPlatFormId(platFormId)
                 .getWxOpenComponentService().getWxMpServiceByAppid(appId));
     }
+
+    public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, Integer platFormId, String appId) {
+        return this.route(wxMessage, new HashMap<>(10), wxThirdPartService.getWxOpenServiceByPlatFormId(platFormId)
+                .getWxOpenComponentService().getWxMpServiceByAppid(appId));
+    }
+
+
+    @Override
+    public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage, String appId) {
+        return super.route(wxMessage, appId);
+    }
+
+    @Override
+    public WxMpXmlOutMessage route(WxMpXmlMessage wxMessage) {
+        return super.route(wxMessage);
+    }
 }

+ 23 - 8
book-push/src/main/java/com/book/push/service/wx/impl/WxThirdPartServiceImpl.java

@@ -69,14 +69,10 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
 
 
     @PostConstruct
-    public void load() {
-
-
-
+    public void init() {
 
         Map<Integer, Platform> integerPlatformMap = platformService.selectAll();
         Set<Integer> platFormIdSet = integerPlatformMap.keySet();
-        ConcurrentHashMap newWxOpenServiceMap = new ConcurrentHashMap<Integer, WxOpenService>();
         platFormIdSet.stream().forEach(id -> {
             Platform platform = integerPlatformMap.get(id);
             WxOpenService wxOpenService = new WxOpenServiceImpl();
@@ -85,13 +81,24 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
             inRedisConfigStorage.setComponentAppSecret(platform.getSecret());
 
             //FIXME  这里有错误,请注意修改
-            inRedisConfigStorage.setComponentVerifyTicket(redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey()));
-            inRedisConfigStorage.setComponentToken(redisService.get(inRedisConfigStorage.getComponentTokenCacheKey()));//错误位置
+            if (redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey())==null){
+                logger.error("ComponentVerifyTicket is null in redis for key :" + inRedisConfigStorage.getVerifyTicketCacheKey());
+            }else {
+
+                inRedisConfigStorage.setComponentVerifyTicket(redisService.get(inRedisConfigStorage.getVerifyTicketCacheKey()));
+            }
+            if (redisService.get(inRedisConfigStorage.getComponentTokenCacheKey())==null){
+                logger.error("ComponentToken is null in redis for key :" + inRedisConfigStorage.getComponentTokenCacheKey());
+            }else {
+
+                inRedisConfigStorage.setComponentToken(redisService.get(inRedisConfigStorage.getComponentTokenCacheKey()));
+            }
+
             inRedisConfigStorage.setComponentAesKey(platform.getAesKey());
             wxOpenService.setWxOpenConfigStorage(inRedisConfigStorage);
             wxOpenServiceMap.put(id, wxOpenService);
         });
-        wxOpenServiceMap = newWxOpenServiceMap;
+
 
         wxThirdPartMessageRouter = new WxThirdPartMessageRouter(this);
         // 记录所有事件的日志 (异步执行)
@@ -135,8 +142,16 @@ public class WxThirdPartServiceImpl implements WxThirdPartService {
 
     }
 
+
+
+
     @Override
     public WxOpenService getWxOpenServiceByPlatFormId(Integer platFormId) {
         return wxOpenServiceMap.get(platFormId);
     }
+
+    @Override
+    public WxThirdPartMessageRouter getWxThirdPartMessageRouter() {
+        return this.wxThirdPartMessageRouter;
+    }
 }

+ 2 - 2
book-push/src/main/resources/application-dev.yml

@@ -4,10 +4,10 @@ server:
 book:
   debug: true
   redis:
-    host: 127.0.0.1
+    host: 121.41.100.198
     port: 6379
     database: 0
-    password:
+    password: wrfg6OTNaXTqd96H7TK7bYIV
     timeout: 1000  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
     # 最大空闲连接数
     maxIdle: 500

+ 18 - 20
book-push/src/main/resources/application-pro.yml

@@ -1,6 +1,22 @@
 server:
   port: 16063
-
+book:
+  debug: true
+  redis:
+    host: 121.41.100.198
+    port: 6379
+    database: 0
+    password: wrfg6OTNaXTqd96H7TK7bYIV
+    timeout: 1000  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
+    # 最大空闲连接数
+    maxIdle: 500
+    # 最小空闲连接数
+    minIdle: 50
+    # 等待可用连接的最大时间,负数为不限制
+    maxWait: -1
+    # 最大活跃连接数,负数为不限制
+    maxActive: -1
+    #  最大连接数
 spring:
   datasource:
     type: com.alibaba.druid.pool.DruidDataSource
@@ -36,25 +52,7 @@ spring:
         allow: # 默认运行所有
         deny: # 默认即可
         reset-enable: true
-  redis:
-    host: 39.107.250.174
-    port: 6379
-    database: 0
-    timeout: 1000s  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
-    # 连接池配置,2.0中直接使用jedis或者lettuce配置连接池
-    jedis:
-      pool:
-        # 最大空闲连接数
-        max-idle: 500
-        # 最小空闲连接数
-        min-idle: 50
-        # 等待可用连接的最大时间,负数为不限制
-        max-wait: -1
-        # 最大活跃连接数,负数为不限制
-        max-active: -1
-    cache:
-      redis:
-        time-to-live: -1 #毫秒
+
 
 mybatis:
   type-aliases-package: com.book.server.entity

+ 123 - 54
book-push/src/main/resources/application-test.yml

@@ -1,64 +1,133 @@
 server:
-  port: 9999
+  port: 8080
 
-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
+book:
+  debug: true
   redis:
-    host: 39.107.250.174
+    host: r-bp1fhw9pqpgtfnu638pd.redis.rds.aliyuncs.com
     port: 6379
     database: 0
-    timeout: 1000s  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
-    # 连接池配置,2.0中直接使用jedis或者lettuce配置连接池
-    jedis:
-      pool:
-        # 最大空闲连接数
-        max-idle: 500
-        # 最小空闲连接数
-        min-idle: 50
-        # 等待可用连接的最大时间,负数为不限制
-        max-wait: -1
-        # 最大活跃连接数,负数为不限制
-        max-active: -1
-    cache:
-      redis:
-        time-to-live: -1 #毫秒
+    password: 5uUL$V!UBsVPf+9P$q4Y
+    timeout: 1000  # 数据库连接超时时间,2.0 中该参数的类型为Duration,这里在配置的时候需要指明单位
+    # 最大空闲连接数
+    maxIdle: 500
+    # 最小空闲连接数
+    minIdle: 50
+    # 等待可用连接的最大时间,负数为不限制
+    maxWait: -1
+    # 最大活跃连接数,负数为不限制
+    maxActive: -1
+    #  最大连接数
+
+spring:
+  datasource:
+    cps:
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.cj.jdbc.Driver
+      jdbc-url: jdbc:mysql://rm-bp1978b18gyf7v7byzo.mysql.rds.aliyuncs.com:3306/test_cps?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+      username: test_cps
+      password: oRt+rY(7x3&kB#OQdit9
+      #下面为连接池补充设置
+      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
+    polar:
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.cj.jdbc.Driver
+      jdbc-url: jdbc:mysql://rm-bp1978b18gyf7v7byzo.mysql.rds.aliyuncs.com:3306/polar?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+      username: test_cps
+      password: oRt+rY(7x3&kB#OQdit9
+      #下面为连接池补充设置
+      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
+    cpsshard:
+      type: com.alibaba.druid.pool.DruidDataSource
+      driver-class-name: com.mysql.cj.jdbc.Driver
+      jdbc-url: jdbc:mysql://rm-bp1978b18gyf7v7byzo.mysql.rds.aliyuncs.com:3306/test_cps_shard?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=UTC
+      username: test_cps
+      password: oRt+rY(7x3&kB#OQdit9
+      #下面为连接池补充设置
+      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
+  configuration:
+    map-underscore-to-camel-case: true
 
 
 # 设置debug模式下打印mysql

+ 1 - 1
book-push/src/main/resources/application.yml

@@ -1,4 +1,4 @@
 spring:
   # 环境 dev:开发环境|test:测试环境|prod:生产环境
   profiles:
-    active: dev #激活的配置文件
+    active: test #激活的配置文件