فهرست منبع

add(operation-backend):[wechat 信息]

wangxiao 4 سال پیش
والد
کامیت
c14ba76531

+ 43 - 0
operation-backend/src/main/java/com/idiot/operationbackend/controller/WeChatController.java

@@ -0,0 +1,43 @@
+package com.idiot.operationbackend.controller;
+
+import com.idiot.operationbackend.support.JsonResult;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+
+
+/**
+ * @author wang xiao
+ * @date Created in 10:38 2020/9/11
+ */
+@RestController
+@RequestMapping("/wechat")
+@Api(value = "WeChatController", tags ="微信")
+public class WeChatController {
+
+
+
+
+
+    @GetMapping("preAuth")
+    @ApiOperation(value = "获取预授权码地址,微信认证公众号")
+    public ResponseEntity<JsonResult<String>> getPreAuthUrl ()   {
+        return null;
+    }
+
+
+
+
+    @PostMapping("/authCallBack")
+    @ApiOperation(value = "第三方平台,授权事件接受url")
+    public String componentCallBack() {
+        return "success";
+    }
+
+
+}

+ 26 - 0
operation-backend/src/main/java/com/idiot/operationbackend/handler/WeChatMessageFactory.java

@@ -0,0 +1,26 @@
+package com.idiot.operationbackend.handler;
+
+import com.idiot.operationbackend.service.facade.WeChatMessageService;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author wang xiao
+ * @date Created in 11:42 2020/9/11
+ */
+public class WeChatMessageFactory {
+
+
+
+    private final static Map<String, WeChatMessageService> SERVICE_MAP = new HashMap<>(16);
+
+
+    public static WeChatMessageService getService (String key) {
+        return SERVICE_MAP.get(key);
+    }
+
+    public static void addService (String key, WeChatMessageService messageService) {
+        SERVICE_MAP.put(key, messageService);
+    }
+}

+ 34 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/facade/WeChatMessageService.java

@@ -0,0 +1,34 @@
+package com.idiot.operationbackend.service.facade;
+
+import org.springframework.beans.factory.InitializingBean;
+
+import java.util.Map;
+
+/**
+ * 微信事件接受
+ * @author wang xiao
+ * @date Created in 11:39 2020/9/11
+ */
+public interface WeChatMessageService extends InitializingBean {
+
+    /**
+     *  处理消息回调
+     * @author wangxiao
+     * @date 11:33 2020/6/18
+     * @param param
+     * @return java.lang.String
+     */
+    String processMessage(Map<String,String> param);
+
+
+    /**
+     *  默认不支持消息
+     * @author wangxiao
+     * @date 15:27 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    default String unSupportedMessage(Map<String,String> param) {
+      return "success";
+    }
+}

+ 9 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/facade/WeChatService.java

@@ -0,0 +1,9 @@
+package com.idiot.operationbackend.service.facade;
+
+/**
+ * 微信处理
+ * @author wang xiao
+ * @date Created in 10:53 2020/9/11
+ */
+public interface WeChatService {
+}

+ 140 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/EventMessageServiceImpl.java

@@ -0,0 +1,140 @@
+package com.idiot.operationbackend.service.impl;
+
+
+
+import com.idiot.operationbackend.handler.WeChatMessageFactory;
+import com.idiot.operationbackend.service.facade.WeChatMessageService;
+import com.idiot.operationbackend.support.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+/**
+ * @author: wang xiao
+ * @description: 微信 event 消息
+ * @date: Created in 14:17 2020/6/18
+ */
+@Service
+public class EventMessageServiceImpl implements WeChatMessageService {
+
+
+
+
+
+
+    private final Logger logger = LoggerFactory.getLogger(EventMessageServiceImpl.class);
+
+
+    @Override
+    public void afterPropertiesSet()  {
+        WeChatMessageFactory.addService("event",this);
+        eventMap.put("subscribe",this::subscribeEvent);
+        eventMap.put("SCAN",this::scanEvent);
+        eventMap.put("LOCATION",this::locationEvent);
+        eventMap.put("CLICK",this::clickEvent);
+        eventMap.put("VIEW",this::viewEvent);
+    }
+
+
+    @Override
+    public String processMessage(Map<String, String> param) {
+        String eventType = param.get("Event");
+        return eventMap.getOrDefault(eventType,this::unSupportedMessage).apply(param);
+    }
+
+
+    /**
+     * 所有事件函数 集合
+     */
+    private Map<String, Function<Map<String,String>,String> > eventMap = new HashMap<>();
+
+
+    /**
+     *  subscribe
+     * 扫描二维码 (用户未关注时,进行关注后的事件推送)
+     * @author wangxiao
+     * @date 18:54 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    private String subscribeEvent (Map<String,String> param) {
+        logger.info("********************* param is {}*****************",param.toString());
+        String key = param.get("EventKey");
+        if (StringUtils.isEmpty(key)) {
+            param.put("Content","欢迎关注中德智慧教育科技");
+            return unSupportedMessage(param);
+        }
+        key = key.replace("qrscene_","");
+        logger.info("************** subscribe Received weChat  event key : {} ****************",key);
+
+        return Constants.SUCCESS;
+    }
+
+
+    /**
+     *  SCAN
+     *  扫描二维码 (用户关注时)
+     * @author wangxiao
+     * @date 18:54 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    private String scanEvent (Map<String,String> param) {
+        String key = param.get("EventKey");
+        if (StringUtils.isEmpty(key)) {
+            return unSupportedMessage(param);
+        }
+        logger.info("************** SCAN Received weChat  event key : {} ****************",key);
+        return Constants.SUCCESS;
+    }
+    
+    /**
+     *  LOCATION 位置上报
+     * @author wangxiao
+     * @date 19:09 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    private String locationEvent (Map<String,String> param) {
+        String latitude = param.get("Latitude");
+        String longitude = param.get("Longitude");
+        String precision = param.get("Precision");
+        logger.info("**** LOCATION Received weChat  latitude : {},longitude: {},precision: {} ****",latitude,longitude,precision);
+        return Constants.SUCCESS;
+    }
+
+
+    /**
+     *  CLICK 自定义菜单
+     * @author wangxiao
+     * @date 19:09 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    private String clickEvent (Map<String,String> param) {
+        String key = param.get("EventKey");
+        logger.info("************** CLICK Received weChat  event key : {} ****************",key);
+        return Constants.SUCCESS;
+    }
+
+
+    /**
+     *  VIEW 点击菜单跳转链接
+     * @author wangxiao
+     * @date 19:09 2020/7/1
+     * @param param
+     * @return java.lang.String
+     */
+    private String viewEvent (Map<String,String> param) {
+        String key = param.get("EventKey");
+        logger.info("************** VIEW Received weChat  event key : {} ****************",key);
+        return Constants.SUCCESS;
+    }
+
+}

+ 32 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/TextMessageServiceImpl.java

@@ -0,0 +1,32 @@
+package com.idiot.operationbackend.service.impl;
+
+
+
+import com.idiot.operationbackend.handler.WeChatMessageFactory;
+import com.idiot.operationbackend.service.facade.WeChatMessageService;
+import org.springframework.stereotype.Service;
+
+import java.util.Map;
+
+/**
+ * @author: wang xiao
+ * @description:
+ * @date: Created in 14:29 2020/6/18
+ */
+@Service
+public class TextMessageServiceImpl implements WeChatMessageService {
+
+    @Override
+    public String processMessage(Map<String, String> param) {
+        String content = param.get("Content");
+        String msgId = param.get("MsgId");
+        return unSupportedMessage(param);
+    }
+
+
+
+    @Override
+    public void afterPropertiesSet() throws Exception {
+        WeChatMessageFactory.addService("text",this);
+    }
+}

+ 12 - 0
operation-backend/src/main/java/com/idiot/operationbackend/service/impl/WeChatServiceImpl.java

@@ -0,0 +1,12 @@
+package com.idiot.operationbackend.service.impl;
+
+import com.idiot.operationbackend.service.facade.WeChatService;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author wang xiao
+ * @date Created in 10:54 2020/9/11
+ */
+@Service
+public class WeChatServiceImpl implements WeChatService {
+}

+ 10 - 0
operation-backend/src/main/java/com/idiot/operationbackend/support/Constants.java

@@ -0,0 +1,10 @@
+package com.idiot.operationbackend.support;
+
+/**
+ * @author wang xiao
+ * @date Created in 11:52 2020/9/11
+ */
+public class Constants {
+
+    public static final String SUCCESS = "success";
+}

+ 55 - 0
operation-backend/src/main/resources/application-test.yml

@@ -0,0 +1,55 @@
+spring:
+  #  datasource
+  datasource:
+    driver-class-name: com.mysql.cj.jdbc.Driver
+    url: jdbc:mysql://192.168.1.142:3307/db_operation?serverTimezone=UTC&characterEncoding=utf8
+    username: root
+    password: asdfg12345
+    type: com.zaxxer.hikari.HikariDataSource
+    hikari:
+      pool-name: mysqlDataSourcePool
+      maximum-pool-size: 20
+      minimum-idle: 10
+      connection-timeout: 120000
+      validation-timeout: 6000
+      idle-timeout: 60000
+      login-timeout: 5
+      max-lifetime: 60000
+#  mybatis-plus
+mybatis-plus:
+  global-config:
+    db-config:
+      id-type: id_worker_str
+  configuration:
+    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    map-underscore-to-camel-case: true
+# logging
+logging:
+  file:
+    name: ./log/gameContest.log
+  level:
+    root: info
+    org.mybatis: debug
+#kaptcha 图形验证码配置
+kaptcha:
+  height: 50
+  width: 150
+  content:
+    length: 4
+    source: 0123456789abcdefghijklmnopqrstuvwxyz
+    space: 10
+  font:
+    color: blue
+    name: 宋体,楷体,微软雅黑
+    size: 40
+  background-color:
+    from: lightGray
+    to: white
+  border:
+    enabled: false
+weChat:
+  # 微信第三方平台 (独立部署需要自主申请)
+  platform:
+    appid: xxxxxxxxxxxx
+
+