微信医保授权失败,新增提示文字内容

debug
王绍全 4 days ago
parent 0654c74e44
commit c4c24b42c7
  1. 39
      src/main/java/com/ynxbd/common/helper/common/RSAHelper.java
  2. 4
      src/main/java/com/ynxbd/wx/wxfactory/WxMedHelper.java

@ -2,8 +2,10 @@ package com.ynxbd.common.helper.common;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.ObjectUtils;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.security.*; import java.security.*;
import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateKey;
@ -100,6 +102,8 @@ public class RSAHelper {
return null; return null;
} }
/** /**
* RSA私钥解密 * RSA私钥解密
* *
@ -132,11 +136,44 @@ public class RSAHelper {
return new String(cipher.doFinal(inputByte)); return new String(cipher.doFinal(inputByte));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.error("[RSA]解密失败:[{}]" + e.getMessage()); log.error("[RSA]解密失败:[{}]", e.getMessage());
}
return null;
}
public static String URLEncode(String data) {
try {
if (ObjectUtils.isEmpty(data)) return null;
return URLEncoder.encode(data, String.valueOf(StandardCharsets.UTF_8));
} catch (Exception e) {
e.printStackTrace();
} }
return null; return null;
} }
// 加密方法(PKCS#1 v1.5填充)
public static String enPKCS1Padding(String plaintext, PublicKey publicKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.ENCRYPT_MODE, publicKey);
byte[] encryptedBytes = cipher.doFinal(plaintext.getBytes(StandardCharsets.UTF_8));
return java.util.Base64.getEncoder().encodeToString(encryptedBytes);
}
// 解密方法
public static String dePKCS1Padding(String encryptedText, PrivateKey privateKey) throws Exception {
Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] decryptedBytes = cipher.doFinal(java.util.Base64.getDecoder().decode(encryptedText));
return new String(decryptedBytes, StandardCharsets.UTF_8);
}
// 去除空格、制表符、换行符等连续或多个空白符
public static String replaceKey(String key) {
if (key == null) return null;
return key.replaceAll("\\s+", "");
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {

@ -36,9 +36,9 @@ public class WxMedHelper {
log.info("[医保]获取用户信息 openid={}, qrCode={}", openid, qrCode); log.info("[医保]获取用户信息 openid={}, qrCode={}", openid, qrCode);
MedicalUserInfo info = WxFactory.Medical.Common().getUserInfo(WxMedConfig.PARTNER_URL, openid, qrCode); MedicalUserInfo info = WxFactory.Medical.Common().getUserInfo(WxMedConfig.PARTNER_URL, openid, qrCode);
if (info == null || !info.isSuccess()) { if (info == null || !info.isSuccess()) {
String message = info == null ? "授权失败" : info.getMessage(); String message = info == null ? "" : info.getMessage();
log.info("[医保授权]失败 {}", message); log.info("[医保授权]失败 {}", message);
throw new ServiceException(message); throw new ServiceException("[医保授权]失败:" + message);
} }
if (cardNo != null) { if (cardNo != null) {

Loading…
Cancel
Save