修改部分,微信推送事件,lkl的部分配置

This commit is contained in:
liuyingfang
2023-04-20 15:29:59 +08:00
parent 73fdf1b517
commit 082896aabc
15 changed files with 361 additions and 25 deletions

View File

@@ -89,6 +89,8 @@ public class ParameterConfig {
*/
@Value("${parameter.APPLETS_APPID}")
public String APPLETS_APPID;
@Value("${parameter.APPLETS_SECRET}")
public String APPLETS_SECRET;
/**
* AppSecret
*/
@@ -272,6 +274,7 @@ public class ParameterConfig {
ParametersUtil.WECHAT_RATE = WECHAT_RATE;
ParametersUtil.APPID = APPID;
ParametersUtil.APPLETS_APPID = APPLETS_APPID;
ParametersUtil.APPLETS_SECRET = APPLETS_SECRET;
ParametersUtil.APPSECRET = APPSECRET;
ParametersUtil.PID = PID;
ParametersUtil.KEY = KEY;

View File

@@ -45,6 +45,10 @@ public class ParametersUtil {
* 小程序付款的appid
*/
public static String APPLETS_APPID;
/**
* 小程序密钥
*/
public static String APPLETS_SECRET;
/**
* AppSecret
*/

View File

@@ -113,7 +113,7 @@ public class RSAUtils {
public static PrivateKey getPrivateKey(String key) throws Exception {
byte[] keyBytes;
keyBytes = Base64.getDecoder().decode(key);
keyBytes = Base64.getMimeDecoder().decode(key);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory keyFactory = KeyFactory.getInstance(RSA);
return keyFactory.generatePrivate(keySpec);

View File

@@ -0,0 +1,161 @@
package cn.pluss.platform.util;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
import cn.pluss.platform.exception.MsgException;
import org.bouncycastle.crypto.CryptoException;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.util.encoders.Base64;
import static org.bouncycastle.util.encoders.Base64.toBase64String;
//import com.lakala.zf.idry.yzt.exception.CryptoException;
public class SM4Util {
public static final String ALGORITHM_NAME = "SM4";
public static final String ALGORITHM_NAME_ECB_PADDING = "SM4/ECB/PKCS5Padding";
// SM4算法目前只支持128位即密钥16字节
public static final int DEFAULT_KEY_SIZE = 128;
public static final String ENCODING = "UTF-8";
static {
Security.addProvider(new BouncyCastleProvider());
}
/**
* 生成Base64编码的密钥
*
* @return Base64编码的密钥
* @throws CryptoException
*/
public static String generateKeyToBase64() throws CryptoException {
return toBase64String(generateKey());
}
public static byte[] generateKey() throws CryptoException {
return generateKey(DEFAULT_KEY_SIZE);
}
/**
* 生成Base64编码的密钥
*
* @param keySize 密钥长度 单位为bit
* @return Base64编码的密钥
* @throws CryptoException
*/
public static String generateKeyToBase64(int keySize) throws CryptoException {
return toBase64String(generateKey(keySize));
}
public static byte[] generateKey(int keySize) throws CryptoException {
KeyGenerator kg = null;
try {
kg = KeyGenerator.getInstance(ALGORITHM_NAME, BouncyCastleProvider.PROVIDER_NAME);
} catch (Exception e) {
throw new CryptoException("SM4Util generateKey error:", e);
}
kg.init(keySize, new SecureRandom());
return kg.generateKey().getEncoded();
}
public static byte[] encrypt_ECB_Padding(byte[] key, byte[] data) throws CryptoException {
try {
Cipher cipher = generateECBCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.ENCRYPT_MODE, key);
return cipher.doFinal(data);
} catch (Exception e) {
throw new CryptoException("SM4Util encrypt_ECB_Padding error:", e);
}
}
/**
* ECB_PKCS5Padding 加密返回Base64编码后的密文
*
* @param key base64
* @param data 正常明文数据
* @return
* @throws MsgException
*/
public static String encrypt(String key, String data) throws CryptoException {
try {
Cipher cipher = generateECBCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.ENCRYPT_MODE, Base64.decode(key));
byte[] enData =cipher.doFinal(data.getBytes(ENCODING));
return Base64.toBase64String(enData);
} catch (Exception e) {
throw new CryptoException("SM4Util encrypt_ECB_Padding error:", e);
}
}
/**
* ECB_PKCS5Padding 解密 ,返回正常明文数据
*
* @param key base64
* @param cipherText 返回Base64编码后的密文
* @return
* @throws Exception
*/
public static String decrypt(String key, String cipherText) throws CryptoException {
try {
Cipher cipher = generateECBCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.DECRYPT_MODE, Base64.decode(key));
byte[] data =cipher.doFinal(Base64.decode(cipherText));
return new String(data,ENCODING);
} catch (Exception e) {
throw new CryptoException("SM4Util decrypt_ECB_Padding error:", e);
}
}
public static byte[] decrypt_ECB_Padding(byte[] key, byte[] cipherText) throws CryptoException {
try {
Cipher cipher = generateECBCipher(ALGORITHM_NAME_ECB_PADDING, Cipher.DECRYPT_MODE, key);
return cipher.doFinal(cipherText);
} catch (Exception e) {
throw new CryptoException("SM4Util decrypt_ECB_Padding error:", e);
}
}
private static Cipher generateECBCipher(String algorithmName, int mode, byte[] key)
throws NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException,
InvalidKeyException {
Cipher cipher = Cipher.getInstance(algorithmName, BouncyCastleProvider.PROVIDER_NAME);
Key sm4Key = new SecretKeySpec(key, ALGORITHM_NAME);
cipher.init(mode, sm4Key);
return cipher;
}
public static void main(String[] args) throws Exception {
try {
String key = "dRzPaYd7z6vYn9sL/JTZ3A==";
String data = "阿萨德哈的哦已我居然挤公交大幅度AAAADDF";
String cipherText = encrypt(key, data);
System.out.println("cipherText " + cipherText);
String deData = decrypt(key, cipherText);
System.out.println("deData " + deData);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@@ -84,13 +84,13 @@ public class WxConstants {
public static final Integer RESULT_SUCCESS_CODE = 0;
public static final Integer QR_EXPIRE_SECONDS = 2592000;
public static final Integer QR_EXPIRE_SECONDS = 25920000;
/**
* 微信会员开卡通知模板ID
* @date: 2021/12/9 18:17
*/
public static final String VIP_CARD_SUCCESS_TEMPLATE_ID = "Hf_WLVwVAc0HD4KV2_zLD0vTgiw4jpZ-OkcN4lIffUA";
public static final String VIP_CARD_SUCCESS_TEMPLATE_ID = "AEEmXqtyvSIppWOX-RWglgU8Wc8DxSNDi4xXq7iles0";
/**
* 会员卡余额变动通知模板ID