Ver código fonte

feat : 米大师支付2.0调试修改

bilingfeng 1 ano atrás
pai
commit
06cb5e6564

+ 14 - 0
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/pay/MiPay2Service.java

@@ -128,10 +128,18 @@ public class MiPay2Service extends PayBaseService {
         String postBody = JsonUtil.toString(postBodyMap);
         String postBody = JsonUtil.toString(postBodyMap);
         //接口token
         //接口token
         String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
         String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
+
         //登录签名
         //登录签名
         String signature = calcSignature(postBody, sessionKey);
         String signature = calcSignature(postBody, sessionKey);
+        log.error("余额 : 登录签名计算参数, postBody : {}, sessionKey : {}, signature : {}", postBody, sessionKey, signature);
+
+
         //支付签名
         //支付签名
         String paySig = calcPaySig(MiPay2Service.BALANCE_URL, postBody, config.getAppKeyByIsSand(this.isSand));
         String paySig = calcPaySig(MiPay2Service.BALANCE_URL, postBody, config.getAppKeyByIsSand(this.isSand));
+
+        log.error("余额 : 支付签名计算参数, url : {}, postBody : {}, appKey : {}, paySig : {}", MiPay2Service.BALANCE_URL, postBody, config.getAppKeyByIsSand(this.isSand), paySig);
+
+
         //请求头参数
         //请求头参数
         Map<String, String> headParamMap = new HashMap<>(3);
         Map<String, String> headParamMap = new HashMap<>(3);
         headParamMap.put("access_token", accessToken);
         headParamMap.put("access_token", accessToken);
@@ -158,8 +166,14 @@ public class MiPay2Service extends PayBaseService {
         String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
         String accessToken = wxApiService.getAccessToken(config.getAppId(), config.getSecret());
         //登录签名
         //登录签名
         String signature = this.calcSignature(postBody, sessionKey);
         String signature = this.calcSignature(postBody, sessionKey);
+
+        log.error("支付 : 登录签名计算参数, postBody : {}, sessionKey : {}, signature : {}", postBody, sessionKey, signature);
+
         //支付签名
         //支付签名
         String paySig = this.calcPaySig(MiPay2Service.PAY_URL, postBody, config.getAppKeyByIsSand(this.isSand));
         String paySig = this.calcPaySig(MiPay2Service.PAY_URL, postBody, config.getAppKeyByIsSand(this.isSand));
+
+        log.error("支付 : 支付签名计算参数, url : {}, postBody : {}, appKey : {}, paySig : {}", MiPay2Service.BALANCE_URL, postBody, config.getAppKeyByIsSand(this.isSand), paySig);
+
         //请求头参数
         //请求头参数
         Map<String, String> headParamMap = new HashMap<>(3);
         Map<String, String> headParamMap = new HashMap<>(3);
         headParamMap.put("access_token", accessToken);
         headParamMap.put("access_token", accessToken);

+ 28 - 50
game-module/game-sdk/src/main/java/com/zanxiang/sdk/service/pay/TestService.java

@@ -14,54 +14,32 @@ 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 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();
-//    }
+    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();
+    }
 }
 }