Kaynağa Gözat

feat : 小游戏消息事件接收接口

bilingfeng 2 yıl önce
ebeveyn
işleme
72a7bd7983

+ 10 - 0
game-module/game-sdk/src/main/java/com/zanxiang/sdk/controller/AppletController.java

@@ -33,4 +33,14 @@ public class AppletController {
         return gameAppletService.appletMsgCheck(appId, signature, timestamp, nonce, echostr);
     }
 
+    @UnSignCheck
+    @ApiOperation(value = "小程序客服消息事件")
+    @PostMapping("/custom/msg/{appId}")
+    @ApiResponses(value = {@ApiResponse(code = 200, message = "成功", response = GameAppletVO.class)})
+    public String appletMsg(@PathVariable("appId") String appId, @RequestParam String signature,
+                            @RequestParam String timestamp, @RequestParam String nonce,
+                            @RequestParam String echostr, @RequestBody String postData) throws Exception {
+        return gameAppletService.appletMsg(appId, signature, timestamp, nonce, echostr, postData);
+    }
+
 }

+ 13 - 0
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/GameAppletService.java

@@ -26,6 +26,19 @@ public interface GameAppletService extends IService<GameApplet> {
      */
     String appletMsgCheck(String appId, String signature, String timestamp, String nonce, String echoStr) throws Exception;
 
+    /**
+     * 小游戏消息推送
+     *
+     * @param appId     应用程序id
+     * @param signature 签名
+     * @param timestamp 时间戳
+     * @param nonce     现时标志
+     * @param echoStr   回声str
+     * @return {@link String}
+     * @throws Exception 异常
+     */
+    String appletMsg(String appId, String signature, String timestamp, String nonce, String echoStr, String postData) throws Exception;
+
     /**
      * 通过游戏id和app id
      *

+ 28 - 0
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/Impl/GameAppletServiceImpl.java

@@ -52,6 +52,34 @@ public class GameAppletServiceImpl extends ServiceImpl<GameAppletMapper, GameApp
         return echoStr;
     }
 
+    /**
+     * 小游戏消息推送
+     *
+     * @param appId     应用程序id
+     * @param signature 签名
+     * @param timestamp 时间戳
+     * @param nonce     现时标志
+     * @param echoStr   回声str
+     * @return {@link String}
+     * @throws Exception 异常
+     */
+    @Override
+    public String appletMsg(String appId, String signature, String timestamp, String nonce, String echoStr, String postData) throws Exception {
+        log.error("接收到事件消息, appId : {}, signature : {}, timestamp : {}, nonce : {}, echoStr : {}, postData : {}",
+                appId, signature, timestamp, nonce, echoStr, postData);
+        GameApplet gameApplet = super.getOne(new LambdaQueryWrapper<GameApplet>()
+                .eq(GameApplet::getAppId, appId));
+        if (gameApplet == null) {
+            return "success";
+        }
+        String mySignature = SignUtil.SHA1(gameApplet.getMsgPushToken(), timestamp, nonce);
+        log.error("计算出来的签名, signature : {},  mySignature : {}", signature, mySignature);
+        if (!Objects.equals(mySignature, signature)) {
+            return "success";
+        }
+        return "success";
+    }
+
     /**
      * 通过游戏id查询
      *