Переглянути джерело

admin屏蔽mns队列组件,更新微信商户号资料,删除部分代码

skyline 1 рік тому
батько
коміт
74150d8828

+ 3 - 1
car-wash-admin/src/main/java/com/kym/admin/AdminApplication.java

@@ -2,10 +2,12 @@ package com.kym.admin;
 
 
 import cn.hutool.crypto.SecureUtil;
+import com.kym.service.mq.MnsHandler;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.annotation.ComponentScan;
+import org.springframework.context.annotation.FilterType;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.stereotype.Controller;
@@ -16,7 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 @Controller
 @EnableScheduling
 @SpringBootApplication
-@ComponentScan(value = "com.kym")
+@ComponentScan(basePackages = {"com.kym"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = MnsHandler.class))
 @MapperScan(basePackages = {"com.kym.mapper"})
 public class AdminApplication {
 

+ 8 - 7
car-wash-admin/src/main/resources/application.yml

@@ -44,17 +44,18 @@ wechat:
   payment:
     appid: wxe466e6b630cc47ae
     # 微信商户号
-    mchid: 1635831469
-    mchsn: 6A45EEB068369430B2FFD45EA29F641A8E18165F
-    v3Key: iTRovdvaTUQq0b9Jr91D7Tx66JnIes5U
-#    notifyUrl: https://dev.kuaiyuman.cn/api/payment/notify
-#    refundNotifyUrl: https://dev.kuaiyuman.cn/api/payment/refundNotify
+    mchid: 1698416484
+    # 证书序列号 API安全 - 管理证书
+    mchsn: 4F8FF1CC14F07A981FD2A7B622C6D1CBB7090BAC
+    v3Key: PvHD8xlZxhKodj4aTFPhIuXW8rRpj3zP
+    notifyUrl: https://dev.kuaiyuman.cn/api/payment/notify
+    refundNotifyUrl: https://dev.kuaiyuman.cn/api/payment/refundNotify
     certPath: cert/apiclient_cert.pem
     keyPath: cert/apiclient_key.pem
 
   miniapp:
     appid: wxe466e6b630cc47ae
-    secret: e36560b99afd5f744754cd09e8f6cc2a
+    secret: 5a974661ea83c1cc7065a1a1de72341c
     # 以下需要先开通消息推送
     token: #微信小程序消息服务器配置的token
     aesKey: #微信小程序消息服务器配置的EncodingAESKey
@@ -70,7 +71,7 @@ wechat:
     baseInformation: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/base-information
     taxCodes: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/tax-codes
     fapiaoApplications: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications
-#    notifyUrl: https://dev.kuaiyuman.cn/api/invoice/notify
+    #    notifyUrl: https://dev.kuaiyuman.cn/api/invoice/notify
     devConfig: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/merchant/development-config
     fapiaoFiles: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s/fapiao-files
     queryFapiao: https://api.mch.weixin.qq.com/v3/new-tax-control-fapiao/fapiao-applications/%s

+ 5 - 5
car-wash-mapper/pom.xml

@@ -44,11 +44,11 @@
 <!--            <version>4.1.3</version>-->
 <!--        </dependency>-->
 
-        <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>druid-spring-boot-starter</artifactId>
-            <version>1.2.20</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>com.alibaba</groupId>-->
+<!--            <artifactId>druid-spring-boot-starter</artifactId>-->
+<!--            <version>1.2.20</version>-->
+<!--        </dependency>-->
 
         <dependency>
             <groupId>com.mysql</groupId>

+ 6 - 27
car-wash-miniapp/src/main/resources/application-dev.yml

@@ -27,39 +27,18 @@ wechat:
   fapiao:
     notifyUrl: https://dev-wash.kuaiyuman.cn/api/invoice/notify
 
-
-  mp:
-    appid: wx93b0ef1be901bd19
-    secret: eea715b3058717f44e17c3e4e5cf1d2f
-    token: kym
-    aeskey: U1ZC5gRrY4DDLZeyKxwpvU5Q7lQvvnQdOV0aX0UPpn6
-
 spring:
   datasource:
+    hikari:
+      max-lifetime: 0
+      minimum-idle: 3
+      maximum-pool-size: 10
+      idle-timeout: 60000
+      connection-timeout: 10000
     url: jdbc:mysql://121.40.98.15:3307/car_wash?serverTimezone=Asia/Shanghai
     username: root
     password: KuaiyuMan/*-
     driver-class-name: com.mysql.cj.jdbc.Driver
-    druid: #以下是全局默认值,可以全局更改
-      #监控统计拦截的filters
-      filters: stat,slf4j
-      #配置初始化大小/最小/最大
-      initial-size: 2
-      min-idle: 2
-      max-active: 20
-      #获取连接等待超时时间
-      max-wait: 60000
-      #间隔多久进行一次检测,检测需要关闭的空闲连接
-      time-between-eviction-runs-millis: 60000
-      #一个连接在池中最小生存的时间
-      min-evictable-idle-time-millis: 300000
-      validation-query: SELECT 'x'
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 20
   data:
     redis:
       port: 6380

+ 0 - 93
car-wash-miniapp/src/main/resources/application-prod.yml

@@ -1,93 +0,0 @@
-# EN+充电配置
-en-plus:
-  # 运营商ID
-  operatorId: MA5HJNDG1
-  # 运营商密钥
-  operatorSecret: c7fd9b753a9f434e
-  # 消息密钥
-  dataSecret: 5cb7e12da198420a
-  # 消息密钥初始化向量
-  dataSecretIv: 8a6ac88326bc4d3f
-  # 签名密钥
-  sigSecret: 2365b20f69e44817
-  # 最小充电余额(分)
-  chargeMinAmount: 200
-  # 接口地址
-  apiDomain: https://api.en-plus.cn:8080/Charge/evcs/v1//MA5HJNDG1/
-  # sass配置
-  sass: https://api.en-plus.cn:8080/Charge/op/login?username=快与慢工程&password=Kuaiyuman2o22
-  # sass结算订单
-  sassClose: https://api.en-plus.cn:8080/Charge/op/analyze/order/close?orderCode=
-
-# 微信支付
-wechat:
-  payment:
-    notifyUrl: https://dev-wash.kuaiyuman.cn/api/payment/notify
-    refundNotifyUrl: https://dev-wash.kuaiyuman.cn/api/payment/refundNotify
-  fapiao:
-    notifyUrl: https://dev-wash.kuaiyuman.cn/api/invoice/notify
-
-spring:
-  datasource:
-    url: jdbc:mysql://121.40.98.15:3307/car_wash?serverTimezone=Asia/Shanghai
-    username: root
-    password: KuaiyuMan/*-
-    driver-class-name: com.mysql.cj.jdbc.Driver
-    druid: #以下是全局默认值,可以全局更改
-      #监控统计拦截的filters
-      filters: stat,slf4j
-      #配置初始化大小/最小/最大
-      initial-size: 2
-      min-idle: 2
-      max-active: 20
-      #获取连接等待超时时间
-      max-wait: 60000
-      #间隔多久进行一次检测,检测需要关闭的空闲连接
-      time-between-eviction-runs-millis: 60000
-      #一个连接在池中最小生存的时间
-      min-evictable-idle-time-millis: 300000
-      validation-query: SELECT 'x'
-      test-while-idle: true
-      test-on-borrow: false
-      test-on-return: false
-      #打开PSCache,并指定每个连接上PSCache的大小。oracle设为true,mysql设为false。分库分表较多推荐设置为false
-      pool-prepared-statements: false
-      max-pool-prepared-statement-per-connection-size: 20
-  data:
-    redis:
-      port: 6380
-      host: 121.40.98.15
-      password: KtXA^Zx!TZmLEy(@JjB@2(TVG0kdy5)&
-      database: 11
-      lettuce:
-        pool:
-          min-idle: 1
-        cluster:
-          refresh:
-            adaptive: true
-            period: 20
-  cache:
-    type: redis
-    redis:
-      # 缓存过期时间:7天
-      time-to-live: 604800
-  rabbitmq:
-    host: 121.40.98.15
-    port: 5674
-    username: kym
-    password: kym!@123
-    virtual-host: /dev
-    publisher-returns: true
-    publisher-confirms: true
-    listener:
-      simple:
-        acknowledge-mode: manual
-        retry:
-          enabled: true
-          max-attempts: 3
-          initial-interval: 3000ms
-          max-interval: 6000ms
-          multiplier: 2
-
-kym:
-  notify-email: zaizai@kuaiyuman.cn,skyline@kuaiyuman.cn

+ 5 - 5
car-wash-service/pom.xml

@@ -66,11 +66,11 @@
         </dependency>
 
         <!-- amqp 1.0 qpid client -->
-        <dependency>
-            <groupId>org.apache.qpid</groupId>
-            <artifactId>qpid-jms-client</artifactId>
-            <version>0.57.0</version>
-        </dependency>
+<!--        <dependency>-->
+<!--            <groupId>org.apache.qpid</groupId>-->
+<!--            <artifactId>qpid-jms-client</artifactId>-->
+<!--            <version>0.57.0</version>-->
+<!--        </dependency>-->
 
         <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
         <dependency>

+ 0 - 130
car-wash-service/src/main/java/com/kym/service/mq/ConsumerQueueForTopicDemo.java

@@ -1,130 +0,0 @@
-package com.kym.service.mq;
-
-import com.aliyun.mns.client.CloudAccount;
-import com.aliyun.mns.client.CloudQueue;
-import com.aliyun.mns.client.MNSClient;
-import com.aliyun.mns.common.ClientException;
-import com.aliyun.mns.common.ServiceException;
-import com.aliyun.mns.common.utils.ServiceSettings;
-import com.aliyun.mns.model.Message;
-import java.io.StringReader;
-import java.util.List;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.apache.commons.codec.binary.Base64;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-
-/**
- * 在 topic 模型下,queue有三个类型,xml、json、simple,在base 64加密下不一样,详见下文
- * 1. 遵循阿里云规范,env 设置ak、sk。
- * 2. ${"user.home"}/.aliyun-mns.properties 文件配置如下:
- *           mns.endpoint=http://xxxxxxx
- *           mns.msgBodyBase64Switch=true/false
- */
-public class ConsumerQueueForTopicDemo {
-    /**
-     * 是否做 base64 编码
-     */
-    private static final Boolean IS_BASE64 = Boolean.valueOf(ServiceSettings.getMNSPropertyValue("msgBodyBase64Switch","false"));
-
-    public static void main(String[] args) {
-        String QUEUE_NAME = "TestQueue";
-
-        // 遵循阿里云规范,env设置ak、sk。
-        CloudAccount account = new CloudAccount(ServiceSettings.getMNSAccountEndpoint());
-        //this client need only initialize once
-        MNSClient client = account.getMNSClient();
-        CloudQueue queue = client.getQueueRef(QUEUE_NAME);
-
-        try {
-            longPollingBatchReceive(queue);
-        } catch (ClientException ce) {
-            System.out.println("Something wrong with the network connection between client and MNS service."
-                    + "Please check your network and DNS availablity.");
-            ce.printStackTrace();
-        } catch (ServiceException se) {
-            if (se.getErrorCode().equals("QueueNotExist")) {
-                System.out.println("Queue is not exist.Please create queue before use");
-            } else if (se.getErrorCode().equals("TimeExpired")) {
-                System.out.println("The request is time expired. Please check your local machine timeclock");
-            }
-            se.printStackTrace();
-        } catch (Exception e) {
-            System.out.println("Unknown exception happened!");
-            e.printStackTrace();
-        }
-
-        client.close();
-    }
-
-    private static void longPollingBatchReceive(CloudQueue queue) {
-        System.out.println("=============start longPollingBatchReceive=============");
-
-        // 一次性拉取 最多 xx 条消息
-        int batchSize = 15;
-        // 长轮询时间为 xx s
-        int waitSeconds = 15;
-
-        List<Message> messages = queue.batchPopMessage(batchSize, waitSeconds);
-        if (messages != null && messages.size() > 0) {
-
-            for (Message message : messages) {
-                System.out.println("message handle: " + message.getReceiptHandle());
-                System.out.println("message body: " + message.getOriginalMessageBody());
-                System.out.println("message body real data: " + getMessageBodyData(message));
-                System.out.println("message id: " + message.getMessageId());
-                System.out.println("message dequeue count:" + message.getDequeueCount());
-                //<<to add your special logic.>>
-
-                //remember to  delete message when consume message successfully.
-                queue.deleteMessage(message.getReceiptHandle());
-                System.out.println("delete message successfully.\n");
-            }
-        }
-
-        System.out.println("=============end longPollingBatchReceive=============");
-
-    }
-
-    private static String getMessageBodyData(Message message){
-        if (message == null){
-            return null;
-        }
-        String originalMessageBody = message.getOriginalMessageBody();
-
-        // 1. 尝试解析为JSON
-        try {
-            JSONObject object = new JSONObject(originalMessageBody);
-            String jsonMessageData = String.valueOf(object.get("Message"));
-            System.out.println("message body type: JSON,value:"+jsonMessageData );
-            return IS_BASE64? new String(Base64.decodeBase64(jsonMessageData)): jsonMessageData;
-        } catch (JSONException ex1) {
-            // 不是JSON,继续检查XML
-        }
-
-        // 2. 尝试解析为XML
-        try {
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            DocumentBuilder builder = factory.newDocumentBuilder();
-            Document doc = builder.parse(new InputSource(new StringReader(originalMessageBody)));
-            Element root = doc.getDocumentElement();
-            NodeList nodeList = root.getElementsByTagName("Message");
-            String content = nodeList.item(0).getTextContent();
-            System.out.println("message body type: XML,value:"+content );
-
-            return IS_BASE64? new String(Base64.decodeBase64(content)): content;
-        } catch (Exception ex) {
-            // 不是有效的XML
-        }
-
-        // 既不是JSON也不是XML,视为普通文本
-        System.out.println("message body type: SIMPLE" );
-        return IS_BASE64 ? message.getMessageBody() : message.getMessageBodyAsRawString();
-
-    }
-}

+ 43 - 21
car-wash-service/src/main/java/com/kym/service/mq/MnsHandler.java

@@ -6,10 +6,12 @@ import com.alibaba.fastjson2.TypeReference;
 import com.aliyun.mns.client.CloudAccount;
 import com.aliyun.mns.client.CloudQueue;
 import com.aliyun.mns.client.MNSClient;
+import com.aliyun.mns.common.ClientException;
+import com.aliyun.mns.common.ServiceException;
 import com.aliyun.mns.model.Message;
-import com.kym.service.awoara.factory.AwoaraEventHandlerFactory;
 import com.kym.entity.awoara.Event;
 import com.kym.entity.awoara.MessageBody;
+import com.kym.service.awoara.factory.AwoaraEventHandlerFactory;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.text.StringEscapeUtils;
 import org.springframework.context.event.ContextRefreshedEvent;
@@ -55,31 +57,51 @@ public class MnsHandler {
     MNSClient client = account.getMNSClient();
     CloudQueue queue = client.getQueueRef(queueName);
 
+
+    private static void batchReceive(CloudQueue queue) {
+        executorService.execute(() -> {
+            while (true) {
+                try {
+                    longPollingBatchReceive(queue);
+                } catch (ClientException ce) {
+                    System.out.println("Something wrong with the network connection between client and MNS service."
+                            + "Please check your network and DNS availablity.");
+                    ce.printStackTrace();
+                } catch (ServiceException se) {
+                    if (se.getErrorCode().equals("QueueNotExist")) {
+                        System.out.println("Queue is not exist.Please create queue before use");
+                    } else if (se.getErrorCode().equals("TimeExpired")) {
+                        System.out.println("The request is time expired. Please check your local machine timeclock");
+                    }
+                    se.printStackTrace();
+                } catch (Exception e) {
+                    System.out.println("Unknown exception happened!");
+                    e.printStackTrace();
+                }
+            }
+        });
+    }
+
     /**
      * 长轮询批量获取消息
      *
      * @param queue
      */
-    @SuppressWarnings("InfiniteLoopStatement")
     private static void longPollingBatchReceive(CloudQueue queue) {
-        executorService.execute(() -> {
-            while (true) {
-                log.info("=============开始 长轮询批量获取消息=============");
+        log.info("=============开始 长轮询批量获取消息=============");
 
-                // 一次性拉取最多xx条消息
-                int batchSize = 15;
-                // 长轮询时间为 xx s
-                int waitSeconds = 15;
+        // 一次性拉取最多xx条消息
+        int batchSize = 15;
+        // 长轮询时间为 xx s
+        int waitSeconds = 15;
 
-                List<Message> messages = queue.batchPopMessage(batchSize, waitSeconds);
-                if (messages != null && !messages.isEmpty()) {
-                    for (Message message : messages) {
-                        printMsgAndDelete(queue, message);
-                    }
-                }
-                log.info("=============结束 长轮询批量获取消息=============");
+        List<Message> messages = queue.batchPopMessage(batchSize, waitSeconds);
+        if (messages != null && !messages.isEmpty()) {
+            for (Message message : messages) {
+                printMsgAndDelete(queue, message);
             }
-        });
+        }
+        log.info("=============结束 长轮询批量获取消息=============");
     }
 
     /**
@@ -129,9 +151,9 @@ public class MnsHandler {
         log.info("消息内容:{}", json.toJSONString());
         if ("upload".equals(json.getString("messagetype"))) {
             var event = json.getJSONObject("payload").getString("event");
-                var handler = AwoaraEventHandlerFactory.getEventHandler(event);
-                var message = parseMessageBody(json.toJSONString(), Event.getClazz(event));
-                handler.handle(message);
+            var handler = AwoaraEventHandlerFactory.getEventHandler(event);
+            var message = parseMessageBody(json.toJSONString(), Event.getClazz(event));
+            handler.handle(message);
         } else {
             log.info("message type is not upload");
         }
@@ -150,7 +172,7 @@ public class MnsHandler {
     @EventListener(classes = {ContextRefreshedEvent.class})
     @Async
     public void init() {
-        longPollingBatchReceive(queue);
+        batchReceive(queue);
     }
 
 }

+ 0 - 103
car-wash-service/src/main/java/com/kym/service/mq/ReceiveMessageDemo.java

@@ -1,103 +0,0 @@
-package com.kym.service.mq;
-
-import com.aliyun.mns.client.CloudAccount;
-import com.aliyun.mns.client.CloudQueue;
-import com.aliyun.mns.client.MNSClient;
-import com.aliyun.mns.common.ClientException;
-import com.aliyun.mns.common.ServiceException;
-import com.aliyun.mns.model.Message;
-
-import java.util.List;
-
-/**
- * 1. 遵循阿里云规范,env设置ak、sk。
- * 2. ${"user.home"}/.aliyun-mns.properties 文件配置如下:
- * mns.endpoint=http://xxxxxxx
- * mns.msgBodyBase64Switch=true/false
- */
-public class ReceiveMessageDemo {
-
-    /**
-     * 是否做 base64 编码
-     */
-    private static final Boolean IS_BASE64 = false;
-
-
-    public static void main(String[] args) {
-        String queueName = "aliyun-iot-k1olfsszoYB";
-
-        // 遵循阿里云规范,env设置ak、sk。
-        CloudAccount account = new CloudAccount("LTAI5tNhD2KFuLUN1hMEukmS","dtVF6na8Hp9W8DmAoWI9k24VXwjNyM","http://1757940634296846.mns.cn-shanghai.aliyuncs.com");
-        //this client need only initialize once
-        MNSClient client = account.getMNSClient();
-        CloudQueue queue = client.getQueueRef(queueName);
-
-        try {
-            // 基础: 单次拉取
-//            singleReceive(queue);
-
-            // 推荐: 使用的 长轮询批量拉取模型
-            longPollingBatchReceive(queue);
-        } catch (ClientException ce) {
-            System.out.println("Something wrong with the network connection between client and MNS service."
-                    + "Please check your network and DNS availablity.");
-            ce.printStackTrace();
-        } catch (ServiceException se) {
-            if (se.getErrorCode().equals("QueueNotExist")) {
-                System.out.println("Queue is not exist.Please create queue before use");
-            } else if (se.getErrorCode().equals("TimeExpired")) {
-                System.out.println("The request is time expired. Please check your local machine timeclock");
-            }
-            se.printStackTrace();
-        } catch (Exception e) {
-            System.out.println("Unknown exception happened!");
-            e.printStackTrace();
-        }
-
-        client.close();
-    }
-
-    private static void longPollingBatchReceive(CloudQueue queue) {
-        System.out.println("=============start longPollingBatchReceive=============");
-
-        // 一次性拉取最多xx条消息
-        int batchSize = 15;
-        // 长轮询时间为 xx s
-        int waitSeconds = 15;
-
-        List<Message> messages = queue.batchPopMessage(batchSize, waitSeconds);
-        if (messages != null && !messages.isEmpty()) {
-
-            for (Message message : messages) {
-                printMsgAndDelete(queue, message);
-            }
-        }
-
-        System.out.println("=============end longPollingBatchReceive=============");
-
-    }
-
-    private static void singleReceive(CloudQueue queue) {
-        System.out.println("=============start singleReceive=============");
-
-        Message popMsg = queue.popMessage();
-        printMsgAndDelete(queue, popMsg);
-
-        System.out.println("=============end singleReceive=============");
-    }
-
-    private static void printMsgAndDelete(CloudQueue queue, Message popMsg) {
-        if (popMsg != null) {
-            System.out.println("message handle: " + popMsg.getReceiptHandle());
-            System.out.println("message body: " + (IS_BASE64 ? popMsg.getMessageBody() : popMsg.getMessageBodyAsRawString()));
-            System.out.println("message id: " + popMsg.getMessageId());
-            System.out.println("message dequeue count:" + popMsg.getDequeueCount());
-            //<<to add your special logic.>>
-
-            //remember to  delete message when consume message successfully.
-            queue.deleteMessage(popMsg.getReceiptHandle());
-            System.out.println("delete message successfully.\n");
-        }
-    }
-
-}