'提交代码'

dev-discount
= 3 years ago
parent 4d5a46b87e
commit 56898f741e
  1. 3
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  2. 178
      hai-service/src/main/java/com/hai/config/HuiLianTongConfig.java

@ -7,6 +7,7 @@ import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.*; import com.hai.common.utils.*;
import com.hai.config.HuiLianTongConfig;
import com.hai.config.QianZhuConfig; import com.hai.config.QianZhuConfig;
import com.hai.config.TuanYouConfig; import com.hai.config.TuanYouConfig;
import com.hai.entity.*; import com.hai.entity.*;
@ -173,7 +174,7 @@ public class HighTestController {
@ApiOperation(value = "测试") @ApiOperation(value = "测试")
public ResponseData test2() { public ResponseData test2() {
try { try {
return ResponseMsgUtil.success(QianZhuConfig.getMobileOrderByOrderNo("20210724214153991091751")); return ResponseMsgUtil.success(HuiLianTongConfig.getToken());
} catch (Exception e) { } catch (Exception e) {
log.error("HighOrderController --> getOrderById() error!", e); log.error("HighOrderController --> getOrderById() error!", e);
return ResponseMsgUtil.exception(e); return ResponseMsgUtil.exception(e);

@ -0,0 +1,178 @@
package com.hai.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.MD5Util;
import com.hai.common.utils.WxUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.*;
/**
* @author hurui
* @version 1.0
* @ClassName QianZhuConfig
* @description: 汇联通接口配置
* @date 2021/7/5 14:18
*/
public class HuiLianTongConfig {
/**
* 获取token
* @return
* @throws Exception
*/
public static JSONObject getToken() throws Exception {
Map<String,Object> map = new HashMap<>();
map.put("appNo", "gzhltcs");
map.put("appKey", MD5Util.encode("3SCg%2BNnjR54YSUWM2iKgb5Hmdqg0ze4ciZ5kUTzVduWgasPdO3g5egbLYZMAIA3obS7f6Q7hycqkEBNQ2fx8i5qlGAoZcYtiqdBrofYPtqXpLexLrhg%2Bcqti%2BcpOd0xDc2VWEWvFJbxJ1%2Fd82A9x9hg2kYV7CTK9jdZsDL1eoZln0lcCuuaqYpTsfCnZ9pi86jC6rBii4POp4YOHITOA4ryGQGwzoQQt".getBytes()));
return HttpsUtils.doPost("https://gzapitest.deepermobile.com.cn:441/api/api/auth/getAccessToken", JSON.toJSONString(map));
}
public static String get3DESEncryptECB(String src,String secretKey) {
try {
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(build3DesKey(secretKey), "DESede"));
String base64Encode = getBase64Encode(cipher.doFinal(src.getBytes("UTF-8")));
return filter(base64Encode);
} catch (Exception ex) {
//加密失败,打日志
// //logger.error(ex,ex);
}
return null;
}
public static String get3DESDecryptECB(String src,String secretKey){
try {
Cipher cipher = Cipher.getInstance("DESede/ECB/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(build3DesKey(secretKey), "DESede"));
byte[] base64DValue = getBase64Decode(src);
byte ciphertext[] = cipher.doFinal(base64DValue);
return new String(ciphertext, "UTF-8");
} catch (Exception e) {
//解密失败,打日志
// //logger.error(e,e);
}
return null;
}
/*
* 根据字符串生成密钥字节数组
* @param keyStr 密钥字符串
* @return
* @throws UnsupportedEncodingException
*/
public static byte[] build3DesKey(String keyStr) throws UnsupportedEncodingException {
byte[] key = new byte[24]; //声明一个24位的字节数组,默认里面都是0
byte[] temp = keyStr.getBytes("UTF-8"); //将字符串转成字节数组
/*
* 执行数组拷贝
* System.arraycopy(源数组从源数组哪里开始拷贝目标数组拷贝多少位)
*/
if(key.length > temp.length){
//如果temp不够24位,则拷贝temp数组整个长度的内容到key数组中
System.arraycopy(temp, 0, key, 0, temp.length);
}else{
//如果temp大于24位,则拷贝temp数组24个长度的内容到key数组中
System.arraycopy(temp, 0, key, 0, key.length);
}
return key;
}
/**
* 对字符串进行Base64编码
*
*
* @return String 进行编码后的字符串
*/
public static String getBase64Encode(byte[] src) {
String requestValue = "";
try {
BASE64Encoder base64en = new BASE64Encoder();
requestValue = filter(base64en.encode(src));
// //logger.debug(requestValue);
} catch (Exception e) {
e.printStackTrace();
}
return requestValue;
}
public static byte[] getBase64Decode(String str) {
byte[] src = null;
try {
BASE64Decoder base64de = new BASE64Decoder();
src = base64de.decodeBuffer(str);
} catch (Exception var3) {
var3.printStackTrace();
}
return src;
}
private static String filter(String str) {
String output = null;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < str.length(); i++) {
int asc = str.charAt(i);
if (asc != 10 && asc != 13)
sb.append(str.subSequence(i, i + 1));
}
output = new String(sb);
return output;
}
/**
* 大写
* @param s
* @return
*/
public static String md5Capital(String s){
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
try {
byte[] strTemp = s.getBytes();
//使用MD5创建MessageDigest对象
MessageDigest mdTemp = MessageDigest.getInstance("MD5");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte b = md[i];
////logger.debug((int)b);
//将没个数(int)b进行双字节加密
str[k++] = hexDigits[b >> 4 & 0xf];
str[k++] = hexDigits[b & 0xf];
}
return new String(str);
} catch (Exception e) {return null;}
}
/*
测试实例
String appkey = "q[*^%]#%675f";
String param = "{\"phone\":\"18550231381\"}";
String secretKey = "7EFD6D5D7052E29B4FBC4AD75CA737ED";
String jsonData = Coder.get3DESEncryptECB(param, appkey);
System.out.println("jsonData:" + jsonData);
StringJoiner joiner = new StringJoiner("&");
joiner.add("jsonData=" + param);
joiner.add("secretKey=" + secretKey);
String sign = Coder.md5Capital(joiner.toString());
System.out.println("sign:" + sign);
jsonData:aOF3MZAENbJE/t+r4P0+RQGfhSEa5Hyq
sign:835A267FCA8D36C6F79E308F18AECEE8*/
}
Loading…
Cancel
Save