临时提交

dev-discount
胡锐 2 years ago
parent 42bc1db51d
commit f5955cea14
  1. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  2. 21
      hai-cweb/src/main/resources/dev/logback.xml
  3. 126
      hai-service/src/main/java/com/hai/common/utils/AESTool.java
  4. 134
      hai-service/src/main/java/com/hai/config/ChongQingCNPCService.java
  5. 38
      hai-service/src/main/java/com/hai/config/CommonSysConfig.java
  6. 6
      hai-service/src/main/resources/dev/commonConfig.properties

File diff suppressed because one or more lines are too long

@ -69,4 +69,25 @@
<logger name="com.hai" level="ERROR"> <logger name="com.hai" level="ERROR">
<appender-ref ref="errorlog" /> <appender-ref ref="errorlog" />
</logger> </logger>
<appender name="ChongQingCNPC" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>log/ChongQingCNPCService.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>log/ChongQingCNPCService.log.%d.%i</fileNamePattern>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the file size reaches 64 MB -->
<maxFileSize>64 MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>
%d %p (%file:%line\)- %m%n
</pattern>
<charset>UTF-8</charset> <!-- 此处设置字符集 -->
</encoder>
</appender>
<logger name="com.hai.config.ChongQingCNPCService" level="INFO">
<appender-ref ref="ChongQingCNPC" />
</logger>
</configuration> </configuration>

@ -0,0 +1,126 @@
package com.hai.common.utils;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Calendar;
/**
* @className: AESTool
* @author: HuRui
* @date: 2022/9/27
**/
public class AESTool {
public static String Encrypt(String sSrc, String sKey)
{
try
{
return toHex(encryptBytes(sSrc.getBytes("utf-8"), sKey));
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public static byte[] encrypt(byte[] sSrc, String sKey) {
try {
return encryptBytes(sSrc, sKey);
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public static byte[] encryptBytes(byte[] sSrc, String sKey) throws Exception
{
if (sKey == null) {
throw new Exception("Key为空null");
}
if (sKey.length() != 16) {
throw new Exception("Key长度不是16位");
}
byte[] raw = sKey.getBytes("utf-8");
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(1, skeySpec);
byte[] encrypted = cipher.doFinal(sSrc);
return encrypted;
}
public static String Decrypt(String sSrc, String sKey)
{
try {
return new String(decryptBytes(toBytes(sSrc), sKey), "utf-8");
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public static byte[] decrypt(byte[] sSrc, String sKey) {
try {
return decryptBytes(sSrc, sKey);
} catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public static byte[] decryptBytes(byte[] sSrc, String sKey)
throws Exception
{
if (sKey == null) {
throw new Exception("Key为空null");
}
if (sKey.length() != 16) {
throw new Exception("Key长度不是16位");
}
byte[] raw = sKey.getBytes("utf-8");
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(2, skeySpec);
byte[] original = cipher.doFinal(sSrc);
return original;
}
public static String toHex(byte[] buf)
{
if (buf == null)
return "";
StringBuffer result = new StringBuffer(2 * buf.length);
for (int i = 0; i < buf.length; i++) {
appendHex(result, buf[i]);
}
return result.toString();
}
private static void appendHex(StringBuffer sb, byte b) {
sb.append("0123456789ABCDEF".charAt(b >> 4 & 0xF)).append("0123456789ABCDEF".charAt(b & 0xF));
}
public static byte[] toBytes(String hexString)
{
int len = hexString.length() / 2;
byte[] result = new byte[len];
for (int i = 0; i < len; i++)
result[i] = Integer.valueOf(hexString.substring(2 * i, 2 * i + 2),
16).byteValue();
return result;
}
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(5, 10);
String str = "1,13439676580," + cal.getTimeInMillis();
String key = "0123456789ABCDEF";
String token = Encrypt(str, key);
System.out.println(token);
System.out.println(Decrypt(token, key));
}
}

@ -0,0 +1,134 @@
package com.hai.config;
import com.alibaba.fastjson.JSONObject;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.utils.AESTool;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.MD5Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
/**
* 重庆中石油
* @className: CqPetroChina
* @author: HuRui
* @date: 2022/9/26
**/
public class ChongQingCNPCService {
private static Logger log = LoggerFactory.getLogger(ChongQingCNPCService.class);
/**
* 发放电子券
* @param requestCode
* @param tradeId
* @param ticketSum
* @param phone
*/
public static JSONObject sendCNPCTicket(String requestCode, String tradeId, Integer ticketSum, String phone) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("requestCode", requestCode);
map.put("tradeId", tradeId);
map.put("ticketSum", ticketSum);
map.put("phone", phone);
return request("sendCNPCTicket", map);
}
/**
* 获取中石油跨界券核销码
* @param couponNo
* @param tradeId
* @return
*/
public static JSONObject getCNPCCheckCode(String couponNo, String tradeId) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("couponNo", couponNo);
map.put("tradeId", tradeId);
return request("getCNPCCheckCode", map);
}
/**
* 获取电子券详情
* @param couponNo
* @return
*/
public static JSONObject queryCoupon(String couponNo) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("couponNo", couponNo);
map.put("random", String.valueOf(new Random().nextInt(899999) + 100000));
return request("queryCoupon", map);
}
/**
* 请求
* @param actionType 接口类型
* @param param 参数
* @return
* @throws Exception
*/
public static JSONObject request(String actionType, Map<String,Object> param) throws Exception {
String verifyCode = AESTool.Encrypt(JSONObject.toJSONString(param), CommonSysConst.getSysConfig().getChongQingCnpcMerKey());
JSONObject header = new JSONObject();
header.put("strVendorCode", CommonSysConst.getSysConfig().getChongQingCnpcMerNo());
header.put("strActionType", actionType);
header.put("verifyCode", MD5Util.encode((verifyCode + CommonSysConst.getSysConfig().getChongQingCnpcMerKey()).getBytes()).toLowerCase());
JSONObject msg = new JSONObject();
msg.put("head", header);
msg.put("body", verifyCode);
Map<String, Object> reqParam = new HashMap<>();
reqParam.put("sendMessage", msg);
log.info("============start============");
log.info("请求接口:" + actionType);
log.info("参数:" + JSONObject.toJSONString(param));
log.info("请求参数:" + JSONObject.toJSONString(reqParam));
JSONObject response = HttpsUtils.doPost(CommonSysConst.getSysConfig().getChongQingCnpcUrl(), reqParam, new HashMap<>());
log.info("响应参数:" + response.toJSONString());
log.info("============end============");
JSONObject postMessage = response.getJSONObject("postMessage");
if (postMessage == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请求失败!");
}
// 解密body
JSONObject body = decryptBody(response.getJSONObject("postMessage").getString("body"));
if (!body.getInteger("status").equals(1)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, body.getString("info"));
}
return body;
}
/**
* 解密body
* @param bodyStr body加密字符串
* @return
*/
public static JSONObject decryptBody(String bodyStr) {
// 解密body
String decryptBody = AESTool.Decrypt(bodyStr, CommonSysConst.getSysConfig().getChongQingCnpcMerKey());
return JSONObject.parseObject(decryptBody, JSONObject.class);
}
/**
* 解密电子券码
* @param couponCode 券码加密字符串
* @return 核销码
*/
public static String decryptCouponCode(String couponCode) {
return AESTool.Decrypt(couponCode, CommonSysConst.getSysConfig().getChongQingCnpcCouponSignKey());
}
public static void main(String[] args) {
//System.out.println(AESTool.Decrypt("A9D356D4614F874586EAF8678C8C3E7D8CD0EEF031ADA44DDAA3B342CE4BBE44F115AABE27324A6A1F049619139A1A889FCA0FB48EB6E1EA4B1B50F041961B2D686FE8B9696C02DF95BA99B342747D67ECC7847646C87993CF924F33C1308829","n2j30jxhl3rhuoci"));
System.out.println(AESTool.Decrypt("12AEA963896A18F78D0AD9A1103BD0C07E5F6ED88477C49F59192296FC59A07CB046D702CFC72522258A3097138B88F6FBDBEA1130F0D2D72F8C7351A6BA6A17DEAF3605450202D746BFCD6B35373A7BCF10101966AB79E118BDE0155B982299A76614DDCB885158A18C1AE672DE3CB912AEA963896A18F78D0AD9A1103BD0C07E5F6ED88477C49F59192296FC59A07CB046D702CFC72522258A3097138B88F6FBDBEA1130F0D2D72F8C7351A6BA6A17DEAF3605450202D746BFCD6B35373A7BCF10101966AB79E118BDE0155B982299A76614DDCB885158A18C1AE672DE3CB9","n2j30jxhl3rhuoci"));
//System.out.println(AESTool.Decrypt("3549AD565800370205265D7518D26E5F40C90A61FDEB5DD73966126A5D25F5E9","5ojldakiz343a6yk"));
}
}

@ -15,6 +15,12 @@ public class CommonSysConfig {
// 加油站默认图片 // 加油站默认图片
private String gasDefaultOilStationImg; private String gasDefaultOilStationImg;
// 重庆壳牌
private String ChongQingCnpcUrl; // 请求地址
private String ChongQingCnpcMerNo; // 商户号
private String ChongQingCnpcMerKey; // 商户秘钥
private String ChongQingCnpcCouponSignKey; // 电子券签名秘钥
private String tuanYouUrl; private String tuanYouUrl;
private String tuanYouAppKey; private String tuanYouAppKey;
private String tuanYouAppSecret; private String tuanYouAppSecret;
@ -101,6 +107,38 @@ public class CommonSysConfig {
private String fileUrl; private String fileUrl;
public String getChongQingCnpcUrl() {
return ChongQingCnpcUrl;
}
public void setChongQingCnpcUrl(String chongQingCnpcUrl) {
ChongQingCnpcUrl = chongQingCnpcUrl;
}
public String getChongQingCnpcMerNo() {
return ChongQingCnpcMerNo;
}
public void setChongQingCnpcMerNo(String chongQingCnpcMerNo) {
ChongQingCnpcMerNo = chongQingCnpcMerNo;
}
public String getChongQingCnpcMerKey() {
return ChongQingCnpcMerKey;
}
public void setChongQingCnpcMerKey(String chongQingCnpcMerKey) {
ChongQingCnpcMerKey = chongQingCnpcMerKey;
}
public String getChongQingCnpcCouponSignKey() {
return ChongQingCnpcCouponSignKey;
}
public void setChongQingCnpcCouponSignKey(String chongQingCnpcCouponSignKey) {
ChongQingCnpcCouponSignKey = chongQingCnpcCouponSignKey;
}
public String getJzAppId() { public String getJzAppId() {
return jzAppId; return jzAppId;
} }

@ -1,6 +1,12 @@
hsgDomainName=https://hsgcs.dctpay.com hsgDomainName=https://hsgcs.dctpay.com
gasDefaultOilStationImg=https://hsgcs.dctpay.com/filesystem/default/default_oil_station.jpg gasDefaultOilStationImg=https://hsgcs.dctpay.com/filesystem/default/default_oil_station.jpg
# ChongQingCNPC configuration parameters
ChongQingCnpcUrl=http://121.40.235.135:9083/d/cross/api
ChongQingCnpcMerNo=toywqvi14wenrhb3d9
ChongQingCnpcMerKey=n2j30jxhl3rhuoci
ChongQingCnpcCouponSignKey=5ojldakiz343a6yk
# TuanYou configuration parameters # TuanYou configuration parameters
tuanYouUrl=https://test05-motorcade-hcs.czb365.com tuanYouUrl=https://test05-motorcade-hcs.czb365.com
tuanYouAppKey=231599775566496 tuanYouAppKey=231599775566496

Loading…
Cancel
Save