Forráskód Böngészése

feat : 米大师支付2.0代码提交

bilingfeng 1 éve
szülő
commit
32e68f8d9f

+ 1 - 1
game-module/game-sdk/src/main/java/com/zanxiang/sdk/adapter/WebHandlerAdapter.java

@@ -71,7 +71,7 @@ public class WebHandlerAdapter implements HandlerInterceptor {
             throw new CustomException(HttpStatusEnum.INVALID_PARAMS);
             throw new CustomException(HttpStatusEnum.INVALID_PARAMS);
         }
         }
         String str = "appKey=" + gameExt.getAppKey() + "&gameId=" + gameId + "&timestamp=" + timestamp;
         String str = "appKey=" + gameExt.getAppKey() + "&gameId=" + gameId + "&timestamp=" + timestamp;
-        String mySign = SignUtil.MD5(str).toUpperCase();
+        String mySign = SignUtil.MD5(str);
         //签名对比
         //签名对比
         if (!Objects.equals(mySign, sign)) {
         if (!Objects.equals(mySign, sign)) {
             log.error("非法参数, 签名错误, mySign : {}, sign : {}, str : {}", mySign, sign, str);
             log.error("非法参数, 签名错误, mySign : {}, sign : {}, str : {}", mySign, sign, str);

+ 32 - 2
game-module/game-sdk/src/main/java/com/zanxiang/sdk/domain/dto/MiPayConfigDTO.java

@@ -5,6 +5,8 @@ import lombok.Builder;
 import lombok.Data;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NoArgsConstructor;
 
 
+import java.util.Objects;
+
 /**
 /**
  * @author : lingfeng
  * @author : lingfeng
  * @time : 2023-01-15
  * @time : 2023-01-15
@@ -16,15 +18,30 @@ import lombok.NoArgsConstructor;
 @Builder
 @Builder
 public class MiPayConfigDTO {
 public class MiPayConfigDTO {
 
 
+    /**
+     * 米大师现网环境
+     */
+    private static final Integer IS_PRODUCT = 0;
+
+    /**
+     * 米大师沙箱环境
+     */
+    public static final Integer IS_SAND = 1;
+
     /**
     /**
      * 微信小程序appId
      * 微信小程序appId
      */
      */
-    private String wxAppId;
+    private String appId;
+
+    /**
+     * 微信小程序密钥
+     */
+    private String secret;
 
 
     /**
     /**
      * 米大师支付应用id
      * 米大师支付应用id
      */
      */
-    private String appId;
+    private String offerId;
 
 
     /**
     /**
      * 米大师现网AppKey
      * 米大师现网AppKey
@@ -35,4 +52,17 @@ public class MiPayConfigDTO {
      * 米大师沙箱AppKey
      * 米大师沙箱AppKey
      */
      */
     private String appKeyDev;
     private String appKeyDev;
+
+    /**
+     * 根据环境返回对应的密钥
+     *
+     * @param isSand : 0 : 现网, 1 : 沙箱
+     * @return : 返回aapKey
+     */
+    public String getAppKeyByIsSand(Integer isSand) {
+        if (Objects.equals(isSand, MiPayConfigDTO.IS_SAND)) {
+            return this.appKeyDev;
+        }
+        return this.appKey;
+    }
 }
 }

+ 5 - 0
game-module/game-sdk/src/main/java/com/zanxiang/sdk/domain/dto/UserDTO.java

@@ -62,6 +62,11 @@ public class UserDTO {
      */
      */
     private String openId;
     private String openId;
 
 
+    /**
+     * 微信用户会话密钥
+     */
+    private String sessionKey;
+
     /**
     /**
      * 设备来源 mobile,android,iphone,ipad,web,pc,mac,wxapp
      * 设备来源 mobile,android,iphone,ipad,web,pc,mac,wxapp
      */
      */

+ 2 - 2
game-module/game-sdk/src/main/java/com/zanxiang/sdk/enums/PayTypeEnum.java

@@ -1,7 +1,7 @@
 package com.zanxiang.sdk.enums;
 package com.zanxiang.sdk.enums;
 
 
 import com.zanxiang.sdk.service.pay.AliPayService;
 import com.zanxiang.sdk.service.pay.AliPayService;
-import com.zanxiang.sdk.service.pay.MiPayService;
+import com.zanxiang.sdk.service.pay.MiPay2Service;
 import com.zanxiang.sdk.service.pay.PayBaseService;
 import com.zanxiang.sdk.service.pay.PayBaseService;
 import com.zanxiang.sdk.service.pay.WxPayService;
 import com.zanxiang.sdk.service.pay.WxPayService;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
@@ -31,7 +31,7 @@ public enum PayTypeEnum {
     /**
     /**
      * 米大师支付
      * 米大师支付
      */
      */
-    MI_PAY(3, "MI_PAY", MiPayService.class);
+    MI_PAY(3, "MI_PAY", MiPay2Service.class);
 
 
     /**
     /**
      * 支付方式
      * 支付方式

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

@@ -137,7 +137,7 @@ public class PerformOrderServiceImpl implements IPerformOrderService {
         //加密
         //加密
         String sign;
         String sign;
         try {
         try {
-            sign = SignUtil.MD5(sb.toString()).toUpperCase();
+            sign = SignUtil.MD5(sb.toString());
         } catch (Exception e) {
         } catch (Exception e) {
             throw new BaseException("支付加密异常");
             throw new BaseException("支付加密异常");
         }
         }

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

@@ -79,7 +79,7 @@ public class UserTokenServiceImpl extends ServiceImpl<UserTokenMapper, UserToken
         sb.append("&token=").append(token);
         sb.append("&token=").append(token);
         String mySign;
         String mySign;
         try {
         try {
-            mySign = SignUtil.MD5(sb.toString()).toUpperCase();
+            mySign = SignUtil.MD5(sb.toString());
         } catch (Exception e) {
         } catch (Exception e) {
             log.error("md5工具类加密异常, str : {}, e : {}", sb.toString(), e.getMessage());
             log.error("md5工具类加密异常, str : {}, e : {}", sb.toString(), e.getMessage());
             throw new BaseException("MD5加密异常");
             throw new BaseException("MD5加密异常");

+ 196 - 75
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/pay/MiPay2Service.java

@@ -1,20 +1,35 @@
 package com.zanxiang.sdk.service.pay;
 package com.zanxiang.sdk.service.pay;
 
 
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.zanxiang.common.enums.HttpStatusEnum;
+import com.zanxiang.common.enums.OrderStateEnum;
 import com.zanxiang.common.exception.BaseException;
 import com.zanxiang.common.exception.BaseException;
+import com.zanxiang.common.exception.CustomException;
+import com.zanxiang.common.utils.StringUtils;
 import com.zanxiang.common.utils.URIUtil;
 import com.zanxiang.common.utils.URIUtil;
 import com.zanxiang.module.util.JsonUtil;
 import com.zanxiang.module.util.JsonUtil;
+import com.zanxiang.module.util.pojo.ResultVO;
+import com.zanxiang.mybatis.entity.Order;
+import com.zanxiang.sdk.domain.bo.ProductPayParamBO;
+import com.zanxiang.sdk.domain.dto.*;
+import com.zanxiang.sdk.service.IGameAppletService;
+import com.zanxiang.sdk.service.IOrderService;
+import com.zanxiang.sdk.service.IUserService;
+import com.zanxiang.sdk.service.api.WxApiService;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.logging.log4j.util.Strings;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 import org.springframework.web.client.RestTemplate;
 
 
 import javax.crypto.Mac;
 import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import javax.crypto.spec.SecretKeySpec;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
-import java.security.InvalidKeyException;
-import java.security.NoSuchAlgorithmException;
 import java.util.HashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Map;
+import java.util.Objects;
 
 
 /**
 /**
  * @author : lingfeng
  * @author : lingfeng
@@ -23,76 +38,191 @@ import java.util.Map;
  */
  */
 @Slf4j
 @Slf4j
 @Service
 @Service
-public class MiPay2Service {
-
-    public void test() {
-        String appId = "wx79b493916563c377";
-        String secret = "e5b1825a288ea5b54b724c64cc57e5a4";
-        String miPayAppId = "1450050301";
-        String miPaySecret = "ZAksvG2Y2v7pVvRmbahZh4HR4aaCdpnE";
-        String openId = "oA-YO5YY2VVhwuSGst1gHfDBGo6s";
-        String sessionKey = "mnO0qqRHI6JOmAr0P5WbNA==";
-
-        Map<String, Object> postBodyMap = new HashMap<>();
-        postBodyMap.put("offer_id", miPayAppId);
-        postBodyMap.put("openid", openId);
-        postBodyMap.put("ts", System.currentTimeMillis() / 1000);
-        postBodyMap.put("zone_id", "1");
-        postBodyMap.put("env", 0);
-
-        String postBody = JsonUtil.toString(postBodyMap);
+public class MiPay2Service extends PayBaseService {
 
 
-        try {
-
-            //接口token
-            String accessToken = getAccessToken(appId, secret);
-
-            //登录签名
-            String signature = calcSignature(postBody, sessionKey);
+    private static final String SIGN_HMACSHA256 = "HMACSHA256";
 
 
-            //支付签名
-            String paySig = calcPaySig("/wxa/game/getbalance", postBody, miPaySecret);
+    private static final String MI_PAY_HOST = "https://api.weixin.qq.com";
 
 
+    private static final String BALANCE_URL = "/wxa/game/getbalance";
 
 
-            Map<String, String> headParamMap = new HashMap<>();
-            headParamMap.put("access_token", accessToken);
-            headParamMap.put("signature", signature);
-            headParamMap.put("pay_sig", paySig);
+    private static final String PAY_URL = "/wxa/game/pay";
 
 
+    @Value("${payConfig.miPay.isSand}")
+    private Integer isSand;
 
 
-            //调用接口获取余额
-            RestTemplate restTemplate = new RestTemplate();
+    @Autowired
+    private IOrderService orderService;
 
 
-            String url = URIUtil.fillUrlParams("https://api.weixin.qq.com/wxa/game/getbalance", headParamMap, Boolean.FALSE);
+    @Autowired
+    private IGameAppletService gameAppletService;
 
 
+    @Autowired
+    private RestTemplate restTemplate;
 
 
-            System.out.println("url : ------>" + url);
+    @Autowired
+    private WxApiService wxApiService;
 
 
+    @Autowired
+    private IUserService userService;
 
 
-            String result = restTemplate.postForObject(url, postBody, String.class);
+    /**
+     * 支付配置
+     */
+    private MiPayConfigDTO config;
+
+    @Override
+    public Map<String, Object> create(ProductPayParamBO product, GamePayWayDTO gamePayWayDTO) {
+        //查询订单
+        PlatformOrderDTO orderInfo = orderService.getByOrderId(product.getOutTradeNo());
+        if (Objects.isNull(orderInfo)) {
+            throw new CustomException(HttpStatusEnum.ORDER_NO_FIND);
+        }
+        if (orderInfo.getGameId() == null || orderInfo.getGameId() == 0) {
+            throw new CustomException(HttpStatusEnum.ORDER_GAME_ID_IS_NULL);
+        }
+        this.configInit(product.getGameId());
+        //获取用户openId
+        UserDTO userDTO = userService.getUserByUserId(product.getUserId());
+        String openId = userDTO.getOpenId();
+        String sessionKey = userDTO.getSessionKey();
+        //获取米大师钱包余额
+        Long balance = this.midasGetBalance(openId, sessionKey);
+        //返回参数
+        Map<String, Object> payParamMap = new HashMap<>(9);
+        //余额充足, 直接扣除
+        if (balance >= orderInfo.getAmount().longValue()) {
+            String billNo = this.midasPay(openId, sessionKey, orderInfo);
+            payParamMap.put("status", "0");
+            payParamMap.put("billNo", billNo);
+            //支付成功
+            this.paySuccess(product.getOutTradeNo(), orderInfo.getAmount().toString(), config.getAppId());
+        } else {
+            //余额不足, 返回订单id, 前端调充值接口, 充值完后再继续支付
+            payParamMap.put("currencyType", "CNY");
+            payParamMap.put("mode", "game");
+            payParamMap.put("zoneId", "1");
+            payParamMap.put("offerId", config.getAppId());
+            payParamMap.put("env", String.valueOf(this.isSand));
+            payParamMap.put("buyQuantity", orderInfo.getAmount().toString());
+            payParamMap.put("status", "1");
+            payParamMap.put("balance", String.valueOf(balance));
+            payParamMap.put("orderId", product.getOutTradeNo());
+            //更新订单商户信息
+            orderService.update(new LambdaUpdateWrapper<Order>()
+                    .set(Order::getMerchantNo, config.getAppId())
+                    .set(Order::getStatus, OrderStateEnum.WAIT_PAY.getCode())
+                    .eq(Order::getOrderId, product.getOutTradeNo()));
+        }
+        return payParamMap;
+    }
 
 
-            System.out.println("result -----> " + result);
+    private Long midasGetBalance(String openId, String sessionKey) {
+        //接口参数
+        Map<String, Object> postBodyMap = new HashMap<>(5);
+        postBodyMap.put("offer_id", config.getAppId());
+        postBodyMap.put("openid", openId);
+        postBodyMap.put("ts", System.currentTimeMillis() / 1000);
+        postBodyMap.put("zone_id", "1");
+        postBodyMap.put("env", this.isSand);
+        String postBody = JsonUtil.toString(postBodyMap);
+        //接口token
+        String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
+        //登录签名
+        String signature = calcSignature(postBody, sessionKey);
+        //支付签名
+        String paySig = calcPaySig(MiPay2Service.BALANCE_URL, postBody, config.getAppKeyByIsSand(this.isSand));
+        //请求头参数
+        Map<String, String> headParamMap = new HashMap<>(3);
+        headParamMap.put("access_token", accessToken);
+        headParamMap.put("signature", signature);
+        headParamMap.put("pay_sig", paySig);
+        //调接口返回
+        String url = URIUtil.fillUrlParams(MiPay2Service.MI_PAY_HOST + MiPay2Service.BALANCE_URL, headParamMap, Boolean.FALSE);
+        Map<String, String> resultMap = this.miPayApi(url, postBody);
+        return Long.valueOf(resultMap.get("balance"));
+    }
 
 
-        } catch (Exception ignored) {
+    private String midasPay(String openId, String sessionKey, PlatformOrderDTO orderInfo) {
+        //接口参数
+        Map<String, Object> postBodyMap = new HashMap<>(7);
+        postBodyMap.put("openid", openId);
+        postBodyMap.put("offer_id", config.getAppId());
+        postBodyMap.put("ts", System.currentTimeMillis() / 1000);
+        postBodyMap.put("zone_id", "1");
+        postBodyMap.put("env", this.isSand);
+        postBodyMap.put("amount", orderInfo.getAmount());
+        postBodyMap.put("bill_no", orderInfo.getOrderId());
+        String postBody = JsonUtil.toString(postBodyMap);
+        //接口token
+        String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
+        //登录签名
+        String signature = this.calcSignature(postBody, sessionKey);
+        //支付签名
+        String paySig = this.calcPaySig(MiPay2Service.PAY_URL, postBody, config.getAppKeyByIsSand(this.isSand));
+        //请求头参数
+        Map<String, String> headParamMap = new HashMap<>(3);
+        headParamMap.put("access_token", accessToken);
+        headParamMap.put("signature", signature);
+        headParamMap.put("pay_sig", paySig);
+        //调接口返回
+        String url = URIUtil.fillUrlParams(MiPay2Service.MI_PAY_HOST + MiPay2Service.PAY_URL, headParamMap, Boolean.FALSE);
+        Map<String, String> resultMap = this.miPayApi(url, postBody);
+        return resultMap.get("bill_no");
+    }
 
 
+    private Map<String, String> miPayApi(String url, String postBody) {
+        String result;
+        try {
+            result = restTemplate.postForObject(url, postBody, String.class);
+        } catch (Exception e) {
+            log.error("米大师接口调用异常, url : {}, postBody : {}, e : {}", url, postBody, e.getMessage());
+            throw new BaseException("米大师接口调用异常");
+        }
+        if (StringUtils.isEmpty(result)) {
+            log.error("米大师接口调用失败, 返回结果为空, url : {}, postBody : {}", url, postBody);
+            throw new BaseException("米大师接口调用失败, 返回结果为空");
+        }
+        Map<String, String> resultMap = JsonUtil.toMap(result, Map.class, String.class, String.class);
+        //返回结果成功
+        if (Objects.equals("0", resultMap.get("errcode"))) {
+            return resultMap;
         }
         }
+        //返回结果失败
+        log.error("米大师接口调用返回结果失败, url : {}, postBody : {}, errcode : {}, errmsg : {}", url, postBody,
+                resultMap.get("errcode"), resultMap.get("errmsg"));
+        throw new BaseException("米大师接口调用返回结果失败");
+    }
+
+    private void configInit(Long gameId) {
+        //查询游戏小程序信息
+        GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
+        //支付配置赋值
+        this.config = MiPayConfigDTO.builder()
+                .appId(gameAppletDTO.getAppId())
+                .secret(gameAppletDTO.getAppSecret())
+                .offerId(gameAppletDTO.getMiPayAppId())
+                .appKey(gameAppletDTO.getMiPayAppKey())
+                .appKeyDev(gameAppletDTO.getMiPayAppKeyDev())
+                .build();
     }
     }
 
 
-    private String calcPaySig(String uri, String postBody, String appKey) throws NoSuchAlgorithmException, InvalidKeyException {
+    private String calcPaySig(String uri, String postBody, String appKey) {
         String needSignMsg = uri + "&" + postBody;
         String needSignMsg = uri + "&" + postBody;
-        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
-        SecretKeySpec secretKey = new SecretKeySpec(appKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
-        hmacSha256.init(secretKey);
-        byte[] signatureBytes = hmacSha256.doFinal(needSignMsg.getBytes(StandardCharsets.UTF_8));
-        return bytesToHex(signatureBytes);
+        return this.calcSignature(needSignMsg, appKey);
     }
     }
 
 
-    private String calcSignature(String postBody, String sessionKey) throws NoSuchAlgorithmException, InvalidKeyException {
-        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
-        SecretKeySpec secretKey = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
-        hmacSha256.init(secretKey);
-        byte[] signatureBytes = hmacSha256.doFinal(postBody.getBytes(StandardCharsets.UTF_8));
-        return bytesToHex(signatureBytes);
+    private String calcSignature(String postBody, String sessionKey) {
+        try {
+            Mac hmacSha256 = Mac.getInstance(MiPay2Service.SIGN_HMACSHA256);
+            SecretKeySpec secretKey = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), MiPay2Service.SIGN_HMACSHA256);
+            hmacSha256.init(secretKey);
+            byte[] signatureBytes = hmacSha256.doFinal(postBody.getBytes(StandardCharsets.UTF_8));
+            return bytesToHex(signatureBytes);
+        } catch (Exception e) {
+            log.error("米大师签名计算异常, postBody : {}, sessionKey : {}", postBody, sessionKey);
+            throw new BaseException("米大师签名计算异常");
+        }
     }
     }
 
 
     private String bytesToHex(byte[] bytes) {
     private String bytesToHex(byte[] bytes) {
@@ -107,27 +237,18 @@ public class MiPay2Service {
         return hexString.toString();
         return hexString.toString();
     }
     }
 
 
-    /**
-     * 获取访问令牌
-     *
-     * @param appId  应用程序id
-     * @param secret 秘密
-     * @return {@link String}
-     */
-    private String getAccessToken(String appId, String secret) {
-        Map<String, String> paramMap = new HashMap<>(4);
-        paramMap.put("appid", appId);
-        paramMap.put("secret", secret);
-        paramMap.put("grant_type", "client_credential");
-        // 发送请求
-        String url = URIUtil.fillUrlParams("https://api.weixin.qq.com/cgi-bin/token", paramMap, Boolean.FALSE);
-        RestTemplate restTemplate = new RestTemplate();
-        String sr = restTemplate.getForObject(url, String.class);
-        // 解析相应内容(转换成json对象)
-        Map<String, String> userMap = JsonUtil.toMap(sr, Map.class, String.class);
-        if (userMap == null || Strings.isBlank(userMap.get("access_token"))) {
-            throw new BaseException("获取应用token失败");
-        }
-        return userMap.get("access_token");
+    @Override
+    public String notify(HttpServletRequest request, HttpServletResponse response) {
+        throw new BaseException("米大师支付不存在异步回调");
+    }
+
+    @Override
+    public ResultVO synNotify(HttpServletRequest request) {
+        throw new BaseException("米大师支付不存在同步回调");
+    }
+
+    @Override
+    public void closeOrder(PlatformOrderDTO platformOrderDTO) {
+        log.error("米大师支付不存在取消订单");
     }
     }
 }
 }

+ 7 - 6
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/pay/MiPayService.java

@@ -111,8 +111,8 @@ public class MiPayService extends PayBaseService {
     private Long midasGetBalance(String openId) {
     private Long midasGetBalance(String openId) {
         Map<String, String> paramMap = new HashMap<>();
         Map<String, String> paramMap = new HashMap<>();
         paramMap.put("openid", openId);
         paramMap.put("openid", openId);
-        paramMap.put("appid", config.getWxAppId());
-        paramMap.put("offer_id", config.getAppId());
+        paramMap.put("appid", config.getAppId());
+        paramMap.put("offer_id", config.getOfferId());
         paramMap.put("ts", String.valueOf(System.currentTimeMillis() / 1000));
         paramMap.put("ts", String.valueOf(System.currentTimeMillis() / 1000));
         paramMap.put("zone_id", "1");
         paramMap.put("zone_id", "1");
         paramMap.put("pf", "android");
         paramMap.put("pf", "android");
@@ -123,9 +123,9 @@ public class MiPayService extends PayBaseService {
 
 
     private String midasPay(String openId, PlatformOrderDTO orderInfo) {
     private String midasPay(String openId, PlatformOrderDTO orderInfo) {
         Map<String, String> paramMap = new HashMap<>();
         Map<String, String> paramMap = new HashMap<>();
-        paramMap.put("appid", config.getWxAppId());
+        paramMap.put("appid", config.getAppId());
         paramMap.put("openid", openId);
         paramMap.put("openid", openId);
-        paramMap.put("offer_id", config.getAppId());
+        paramMap.put("offer_id", config.getOfferId());
         paramMap.put("ts", String.valueOf(System.currentTimeMillis() / 1000));
         paramMap.put("ts", String.valueOf(System.currentTimeMillis() / 1000));
         paramMap.put("pf", "android");
         paramMap.put("pf", "android");
         paramMap.put("zone_id", "1");
         paramMap.put("zone_id", "1");
@@ -208,8 +208,9 @@ public class MiPayService extends PayBaseService {
         GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
         GameAppletDTO gameAppletDTO = gameAppletService.getByGameId(gameId);
         //支付配置赋值
         //支付配置赋值
         this.config = MiPayConfigDTO.builder()
         this.config = MiPayConfigDTO.builder()
-                .wxAppId(gameAppletDTO.getAppId())
-                .appId(gameAppletDTO.getMiPayAppId())
+                .appId(gameAppletDTO.getAppId())
+                .secret(gameAppletDTO.getAppSecret())
+                .offerId(gameAppletDTO.getMiPayAppId())
                 .appKey(gameAppletDTO.getMiPayAppKey())
                 .appKey(gameAppletDTO.getMiPayAppKey())
                 .appKeyDev(gameAppletDTO.getMiPayAppKeyDev())
                 .appKeyDev(gameAppletDTO.getMiPayAppKeyDev())
                 .build();
                 .build();

+ 51 - 41
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/pay/TestService.java

@@ -4,6 +4,7 @@ import javax.crypto.Mac;
 import javax.crypto.spec.SecretKeySpec;
 import javax.crypto.spec.SecretKeySpec;
 import java.nio.charset.StandardCharsets;
 import java.nio.charset.StandardCharsets;
 import java.security.InvalidKeyException;
 import java.security.InvalidKeyException;
+import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.security.NoSuchAlgorithmException;
 
 
 /**
 /**
@@ -13,45 +14,54 @@ import java.security.NoSuchAlgorithmException;
  */
  */
 public class TestService {
 public class TestService {
 
 
-    public static String calcPaySig(String uri, String postBody, String appKey) throws NoSuchAlgorithmException, InvalidKeyException {
-        String needSignMsg = uri + "&" + postBody;
-        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
-        SecretKeySpec secretKey = new SecretKeySpec(appKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
-        hmacSha256.init(secretKey);
-        byte[] signatureBytes = hmacSha256.doFinal(needSignMsg.getBytes(StandardCharsets.UTF_8));
-        return bytesToHex(signatureBytes);
-    }
-
-    public static String calcSignature(String postBody, String sessionKey) throws NoSuchAlgorithmException, InvalidKeyException {
-        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
-        SecretKeySpec secretKey = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
-        hmacSha256.init(secretKey);
-        byte[] signatureBytes = hmacSha256.doFinal(postBody.getBytes(StandardCharsets.UTF_8));
-        return bytesToHex(signatureBytes);
-    }
-
-    private static String bytesToHex(byte[] bytes) {
-        StringBuilder hexString = new StringBuilder();
-        for (byte b : bytes) {
-            String hex = Integer.toHexString(0xff & b);
-            if (hex.length() == 1) {
-                hexString.append('0');
-            }
-            hexString.append(hex);
-        }
-        return hexString.toString();
-    }
-
-    public static void main(String[] args) throws NoSuchAlgorithmException, InvalidKeyException {
-        String uri = "/wxa/game/getbalance";
-        String appKey = "12345";
-        String postBody = "{\"offer_id\": \"12345678\", \"openid\": \"oUrsfxxxxxxxxxx\", \"ts\": 1668136271, \"zone_id\": \"1\", \"env\": 0}";
-
-        String paySig = calcPaySig(uri, postBody, appKey);
-        System.out.println("pay_sig: " + paySig);
-
-        String sessionKey = "9hAb/NEYUlkaMBEsmFgzig==";
-        String signature = calcSignature(postBody, sessionKey);
-        System.out.println("signature: " + signature);
-    }
+//    public static String calcPaySig(String uri, String postBody, String appKey) throws NoSuchAlgorithmException, InvalidKeyException {
+//        String needSignMsg = uri + "&" + postBody;
+//        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
+//        SecretKeySpec secretKey = new SecretKeySpec(appKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
+//        hmacSha256.init(secretKey);
+//        byte[] signatureBytes = hmacSha256.doFinal(needSignMsg.getBytes(StandardCharsets.UTF_8));
+//        return bytesToHex(signatureBytes);
+//    }
+//
+//    public static String calcSignature(String postBody, String sessionKey) throws NoSuchAlgorithmException, InvalidKeyException {
+//        Mac hmacSha256 = Mac.getInstance("HmacSHA256");
+//        SecretKeySpec secretKey = new SecretKeySpec(sessionKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
+//        hmacSha256.init(secretKey);
+//        byte[] signatureBytes = hmacSha256.doFinal(postBody.getBytes(StandardCharsets.UTF_8));
+//        return bytesToHex(signatureBytes);
+//    }
+//
+//    private static String bytesToHex(byte[] bytes) {
+//        StringBuilder hexString = new StringBuilder();
+//        for (byte b : bytes) {
+//            String hex = Integer.toHexString(0xff & b);
+//            if (hex.length() == 1) {
+//                hexString.append('0');
+//            }
+//            hexString.append(hex);
+//        }
+//        return hexString.toString();
+//    }
+//
+//    public static void main(String[] args) throws Exception {
+//        String a = "payKey=2d71711b38fef06b80e159a35297bcf7&userId=51&money=10.0&time=1664553600000&serverId=001&orderId=1578307332482088961";
+//        System.out.println(MD5(a));
+//    }
+//
+//
+//    /**
+//     * MD5加密
+//     *
+//     * @param data 待处理数据
+//     * @return MD5结果
+//     */
+//    public static String MD5(String data) throws Exception {
+//        java.security.MessageDigest md = MessageDigest.getInstance("MD5");
+//        byte[] array = md.digest(data.getBytes("UTF-8"));
+//        StringBuilder sb = new StringBuilder();
+//        for (byte item : array) {
+//            sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
+//        }
+//        return sb.toString().toUpperCase();
+//    }
 }
 }

+ 1 - 1
game-module/game-sdk/src/main/java/com/zanxiang/sdk/util/SignUtil.java

@@ -41,7 +41,7 @@ public class SignUtil {
         for (byte item : array) {
         for (byte item : array) {
             sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
             sb.append(Integer.toHexString((item & 0xFF) | 0x100), 1, 3);
         }
         }
-        return sb.toString();
+        return sb.toString().toUpperCase();
     }
     }
 
 
     /**
     /**

+ 1 - 1
game-module/game-sdk/src/main/java/com/zanxiang/sdk/util/WxPayUtil.java

@@ -145,7 +145,7 @@ public class WxPayUtil {
         }
         }
         sb.append("key=").append(key);
         sb.append("key=").append(key);
         if (Objects.equals(SIGN_MD5, signType)) {
         if (Objects.equals(SIGN_MD5, signType)) {
-            return SignUtil.MD5(sb.toString()).toUpperCase();
+            return SignUtil.MD5(sb.toString());
         } else if (Objects.equals(SIGN_HMACSHA256, signType)) {
         } else if (Objects.equals(SIGN_HMACSHA256, signType)) {
             return SignUtil.HMACSHA256(sb.toString(), key).toUpperCase();
             return SignUtil.HMACSHA256(sb.toString(), key).toUpperCase();
         } else {
         } else {