ソースを参照

fix : 游戏应用新增公众号类型

bilingfeng 1 年間 前
コミット
8d9859fc23

+ 5 - 0
game-module/game-module-mybatis/src/main/java/com/zanxiang/game/module/mybatis/entity/GameApplet.java

@@ -55,6 +55,11 @@ public class GameApplet implements Serializable {
      */
     private String appSecret;
 
+    /**
+     * 类型,1 : 小程序, 2 : 公众号
+     */
+    private Integer type;
+
     /**
      * 米大师配置
      */

+ 5 - 0
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/pojo/dto/GameAppletDTO.java

@@ -51,6 +51,11 @@ public class GameAppletDTO {
      */
     private String appSecret;
 
+    /**
+     * 类型,1 : 小程序, 2 : 公众号
+     */
+    private Integer type;
+
     /**
      * 米大师配置
      */

+ 6 - 9
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/api/WxApiService.java

@@ -13,6 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
@@ -41,18 +42,14 @@ public class WxApiService {
      * @param type   : 应用类型
      * @return {@link String}
      */
-    public String getOpenIdByType(String code, String appId, String secret, Integer type) {
-        Map<String, String> resultMap = null;
+    public Map<String, String> getOpenIdByType(String code, String appId, String secret, Integer type) {
         if (Objects.equals(type, PayApplicationTypeEnum.WX_MINI_APP.getType())) {
-            resultMap = this.getAppletOpenId(code, appId, secret);
+            return this.getAppletOpenId(code, appId, secret);
         }
         if (Objects.equals(type, PayApplicationTypeEnum.WX_MP.getType())) {
-            resultMap = this.getMpOpenId(code, appId, secret);
+            return this.getMpOpenId(code, appId, secret);
         }
-        if (resultMap != null && resultMap.containsKey("openid")) {
-            return resultMap.get("openid");
-        }
-        return null;
+        return Collections.emptyMap();
     }
 
     /**
@@ -63,7 +60,7 @@ public class WxApiService {
      * @param secret : 应用密钥
      * @return {@link String}
      */
-    public Map<String, String> getAppletOpenId(String code, String appId, String secret) {
+    private Map<String, String> getAppletOpenId(String code, String appId, String secret) {
         // 请求微信服务器,使用code获取openid
         Map<String, String> paramMap = new HashMap<>(4);
         paramMap.put("appid", appId);

+ 7 - 5
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/LoginServiceImpl.java

@@ -94,8 +94,8 @@ public class LoginServiceImpl implements IRegisterLoginService {
         //查询微信小游戏信息
         GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(userData.getGameId());
         //获取用户微信小游戏的openId
-        Map<String, String> resultMap = wxApiService.getAppletOpenId(param.getCode(), gameAppletDTO.getAppId(),
-                gameAppletDTO.getAppSecret());
+        Map<String, String> resultMap = wxApiService.getOpenIdByType(param.getCode(), gameAppletDTO.getAppId(),
+                gameAppletDTO.getAppSecret(), gameAppletDTO.getType());
         String openId = resultMap.get("openid");
         String sessionKey = resultMap.get("session_key");
 
@@ -108,9 +108,11 @@ public class LoginServiceImpl implements IRegisterLoginService {
         //已注册
         if (user != null) {
             //更新用户sessionKey
-            userService.update(new LambdaUpdateWrapper<User>()
-                    .set(User::getSessionKey, sessionKey)
-                    .eq(User::getId, user.getId()));
+            if (Strings.isNotBlank(sessionKey)) {
+                userService.update(new LambdaUpdateWrapper<User>()
+                        .set(User::getSessionKey, sessionKey)
+                        .eq(User::getId, user.getId()));
+            }
             //渠道更新和回传判断
             agentService.userAgentUpdate(user, userData.getChannel());
             //判断账号是否停用

+ 2 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/impl/PayApplicationServiceImpl.java

@@ -112,7 +112,8 @@ public class PayApplicationServiceImpl extends ServiceImpl<PayApplicationMapper,
         //下单参数
         Map<String, String> payConfigMap = JsonUtil.toMap(payMerchantDTO.getPayConfig(), Map.class, String.class);
         //获取用户openId
-        String openId = wxApiService.getOpenIdByType(payParam.getCode(), payApplication.getAppId(), payApplication.getAppSecret(), payApplication.getType());
+        String openId = wxApiService.getOpenIdByType(payParam.getCode(), payApplication.getAppId(),
+                payApplication.getAppSecret(), payApplication.getType()).get("openid");
         //订单id
         String orderId = this.getOrderNum(openId);
         try {

+ 2 - 1
game-module/game-module-sdk/src/main/java/com/zanxiang/game/module/sdk/service/pay/WxPayService.java

@@ -240,7 +240,8 @@ public class WxPayService extends PayBaseService {
     private Map<String, Object> miniAppPay(ProductPayParamDTO product) {
         try {
             //获取用户openId
-            String openId = wxApiService.getOpenIdByType(product.getCode(), config.getAppId(), config.getAppSecret(), config.getAppletType());
+            String openId = wxApiService.getOpenIdByType(product.getCode(), config.getAppId(), config.getAppSecret(),
+                    config.getAppletType()).get("openid");
             //下单
             Map<String, String> successMap = this.unifiedOrder(product, WX_PAY_JSAPI, openId);
             // 支付参数