Browse Source

Merge branch 'master' of ssh://101.201.226.163:50022/ccsens_wiki/ccsens_ptos

master
zhangsan 3 years ago
parent
commit
f60b100e80
  1. 2
      ptos_tall/src/main/java/com/ccsens/ptos_tall/service/WxUserService.java
  2. 5
      ptos_tall/src/main/java/com/ccsens/ptos_tall/util/PtOsConstant.java
  3. 48
      util/src/main/java/com/ccsens/util/SymmetricCryptoUtil.java
  4. 9
      util/src/test/java/com/ccsens/util/OtherTest.java

2
ptos_tall/src/main/java/com/ccsens/ptos_tall/service/WxUserService.java

@ -64,7 +64,7 @@ public class WxUserService implements IWxUserService {
WxOfficial wxOfficial = wxOfficialDao.getByEquipmentId(equipmentId);
if(ObjectUtil.isNotNull(wxOfficial)){
appId = wxOfficial.getAppId();
secret = wxOfficial.getAppId();
secret = wxOfficial.getSecret();
}
}
//如果appId和secret为空,使用默认的信息

5
ptos_tall/src/main/java/com/ccsens/ptos_tall/util/PtOsConstant.java

@ -25,7 +25,10 @@ public class PtOsConstant {
public static final String DEFAULT_APP_ID = "wxb3be21dcd7912555";
/**默认公众号secret*/
public static final String DEFAULT_SECRET = "9213776254878a8065f1a29d1f58a02c";
// /**默认公众号appId*/
// public static final String DEFAULT_APP_ID = "wx7af1bf1e14facf82";
// /**默认公众号secret*/
// public static final String DEFAULT_SECRET = "a6613fae11b497639c0224b820aaf6d9";
/**图片类型*/
public static final String FILE_TYPE_IMG = "bmp,jpg,jpeg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw,WMF,webp";
/**文档类型*/

48
util/src/main/java/com/ccsens/util/SymmetricCryptoUtil.java

@ -0,0 +1,48 @@
package com.ccsens.util;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.CharsetUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
/**
* @author
*/
@Slf4j
@Component
public class SymmetricCryptoUtil {
/**生成密钥*/
public static String generateKey(){
byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.AES.getValue()).getEncoded();
return Base64.encode(key);
}
/**加密*/
public static String encrypt(String key, String value){
String encryptString = null;
if(StrUtil.isNotBlank(key) && StrUtil.isNotBlank(value)){
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key));
encryptString = aes.encryptHex(value);
}
return encryptString;
}
/**解密*/
public static String decode(String key, String encryptString){
SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, Base64.decode(key));
//解密为字符串
String decodeString = null;
try {
decodeString = aes.decryptStr(encryptString, CharsetUtil.CHARSET_UTF_8);
}catch (Exception e){
log.error("解密失败");
}
return decodeString;
}
}

9
util/src/test/java/com/ccsens/util/OtherTest.java

@ -37,6 +37,15 @@ public class OtherTest {
public static final String REGEX_PHONE = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(17[013678])|(18[0,1-9]))\\d{8}$";
@Test
public void test19() {
String s = SymmetricCryptoUtil.generateKey();
String s1 = SymmetricCryptoUtil.encrypt(s, null);
String s2 = SymmetricCryptoUtil.decode(s, "测试的文字");
System.out.println(s);
System.out.println(s1);
System.out.println(s2);
}
@Test
public void test18() {

Loading…
Cancel
Save