添加银收客支付参数
This commit is contained in:
parent
52d2393ac8
commit
258859714c
|
|
@ -0,0 +1,8 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
package com.sqx.modules.pay.controller;
|
||||
|
||||
import com.sqx.common.utils.Result;
|
||||
import com.sqx.modules.app.annotation.Login;
|
||||
import com.sqx.modules.yskPay.resp.PublicResp;
|
||||
import com.sqx.modules.yskPay.resp.WxScanPayResp;
|
||||
import com.sqx.modules.yskPay.service.ThirdPayService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@RestController
|
||||
@Api(value = "用户支付", tags = {"用户支付"})
|
||||
@RequestMapping("/app/pay")
|
||||
@Slf4j
|
||||
public class ThirdPayController {
|
||||
final private ThirdPayService thirdPayService;
|
||||
|
||||
public ThirdPayController(ThirdPayService thirdPayService) {
|
||||
this.thirdPayService = thirdPayService;
|
||||
}
|
||||
|
||||
// @Login
|
||||
@ApiOperation("微信支付宝支付订单")
|
||||
@PostMapping("/wxPayJsApiOrder")
|
||||
// public Result wxPayJsApiOrder(@RequestAttribute("userId") Long userId, Long parentId, Integer type, Long addressId, Integer orderType) throws Exception {
|
||||
public Result wxPayJsApiOrder() {
|
||||
|
||||
PublicResp<WxScanPayResp> scanpay = thirdPayService.scanpay("https://paymentapi.sxczgkj.cn", "66691a6afdf641f0bf1dc701",
|
||||
"外卖订单", "外卖订单", 1L,
|
||||
"WECHAT", "wxd88fffa983758a30", "or1l869Gqm3jUeqbmuL1TFKK4XrM", "1.80.169.5",
|
||||
"202407310944110001", "S2406120331",
|
||||
"https://paymentapi.sxczgkj.cn", null,
|
||||
"jikd52TefZcSPI5hRWrfPSpQcXZrbqshbnLmqH6UattqspIDEzjbGvZmfwTW58RMf1XuPhN4zE1GbIjKy3b1oabgOx5n79faT93Si6i7g2IPSQJAln2NNsCSNynHIJ8p");
|
||||
|
||||
System.out.println(scanpay);
|
||||
|
||||
return new Result();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package com.sqx.modules.yskPay.constants;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public enum SignTypeEnum {
|
||||
|
||||
MD5("MD5"),RSA2("RSA2");
|
||||
|
||||
private final String value;
|
||||
|
||||
SignTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class MainScanReq implements Serializable {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String subAppid;
|
||||
|
||||
private String currency;
|
||||
|
||||
private String authCode;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
public MainScanReq(String subject, String body, Long amount, String subAppid, String currency, String authCode, String mchOrderNo, String storeId, String notifyUrl) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.subAppid = subAppid;
|
||||
this.currency = currency;
|
||||
this.authCode = authCode;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OrderRefundReq implements Serializable {
|
||||
|
||||
private String mchRefundNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String refundReason;
|
||||
|
||||
private Long refundAmount;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String extParam;
|
||||
|
||||
public OrderRefundReq(String mchRefundNo, String payOrderId, String mchOrderNo, String refundReason, Long refundAmount, String notifyUrl, String extParam) {
|
||||
this.mchRefundNo = mchRefundNo;
|
||||
this.payOrderId = payOrderId;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.refundReason = refundReason;
|
||||
this.refundAmount = refundAmount;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.extParam = extParam;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OrderReturnQueryReq implements Serializable {
|
||||
|
||||
private String mchRefundNo;
|
||||
|
||||
private String refundOrderId;
|
||||
|
||||
public OrderReturnQueryReq(String mchRefundNo, String refundOrderId) {
|
||||
this.mchRefundNo = mchRefundNo;
|
||||
this.refundOrderId = refundOrderId;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OrderStatusQueryReq implements Serializable {
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
public OrderStatusQueryReq(String payOrderId, String mchOrderNo) {
|
||||
this.payOrderId = payOrderId;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class PublicParam implements Serializable {
|
||||
|
||||
private String appId;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String signType;
|
||||
|
||||
private String bizData;
|
||||
|
||||
private String reqTime;
|
||||
|
||||
private String version;
|
||||
|
||||
private String reqId;
|
||||
|
||||
public PublicParam(String appId, String sign, String signType, String bizData, String reqTime, String version, String reqId) {
|
||||
this.appId = appId;
|
||||
this.sign = sign;
|
||||
this.signType = signType;
|
||||
this.bizData = bizData;
|
||||
this.reqTime = reqTime;
|
||||
this.version = version;
|
||||
this.reqId = reqId;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package com.sqx.modules.yskPay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class WxScanPayReq implements Serializable {
|
||||
|
||||
private String subject;
|
||||
|
||||
private String body;
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String currency;
|
||||
|
||||
private String payType;
|
||||
|
||||
|
||||
private String subAppid;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String clientIp;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
private String returnUrl;
|
||||
|
||||
private String extParam;
|
||||
|
||||
public WxScanPayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.payType = payType;
|
||||
this.subAppid = subAppid;
|
||||
this.userId = userId;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.returnUrl = returnUrl;
|
||||
}
|
||||
|
||||
public WxScanPayReq(String subject, String body, Long amount, String currency, String payType, String subAppid, String userId, String clientIp, String mchOrderNo, String storeId, String notifyUrl, String returnUrl, String extParam) {
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
this.amount = amount;
|
||||
this.currency = currency;
|
||||
this.payType = payType;
|
||||
this.subAppid = subAppid;
|
||||
this.userId = userId;
|
||||
this.clientIp = clientIp;
|
||||
this.mchOrderNo = mchOrderNo;
|
||||
this.storeId = storeId;
|
||||
this.notifyUrl = notifyUrl;
|
||||
this.returnUrl = returnUrl;
|
||||
this.extParam = extParam;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class MainScanResp implements Serializable {
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private Long refundAmt;
|
||||
|
||||
private Integer refundState;
|
||||
|
||||
private Long cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OderReturnQueryResp implements Serializable {
|
||||
|
||||
|
||||
private String mchRefundNo;
|
||||
|
||||
private String refundOrderId;
|
||||
|
||||
private String state;
|
||||
|
||||
private String oriPayOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private Long oriAmount;
|
||||
|
||||
private Long refundAmt;
|
||||
|
||||
private String refundReason;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String note;
|
||||
|
||||
private String refundTime;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payType;
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OrderReturnResp implements Serializable {
|
||||
|
||||
private String mchRefundNo;
|
||||
|
||||
private String refundOrderId;
|
||||
|
||||
private String state;
|
||||
|
||||
private String oriPayOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private Long oriAmount;
|
||||
|
||||
private Long refundAmt;
|
||||
|
||||
private String refundReason;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String refundTime;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payType;
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class OrderStatusQueryResp implements Serializable {
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payTime;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String userId;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class PublicResp <T> implements Serializable {
|
||||
|
||||
private String code;
|
||||
|
||||
private String msg;
|
||||
|
||||
private String sign;
|
||||
|
||||
private String bizData;
|
||||
|
||||
private T objData;
|
||||
|
||||
private String signType;
|
||||
|
||||
private String timestamp;
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.sqx.modules.yskPay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Data
|
||||
public class WxScanPayResp implements Serializable {
|
||||
|
||||
private Long amount;
|
||||
|
||||
private String mchOrderNo;
|
||||
|
||||
private String payOrderId;
|
||||
|
||||
private String mercNo;
|
||||
|
||||
private String channelSendNo;
|
||||
|
||||
private String channelTradeNo;
|
||||
|
||||
private String state;
|
||||
|
||||
private String payType;
|
||||
|
||||
private String ifCode;
|
||||
|
||||
private String extParam;
|
||||
|
||||
private String payInfo;
|
||||
|
||||
private String liteInfo;
|
||||
|
||||
private String note;
|
||||
|
||||
private String tradeFee;
|
||||
|
||||
private String storeId;
|
||||
|
||||
private String subject;
|
||||
|
||||
private String drType;
|
||||
|
||||
private String refundAmt;
|
||||
|
||||
private String refundState;
|
||||
|
||||
private String cashFee;
|
||||
|
||||
private String settlementType;
|
||||
}
|
||||
|
|
@ -0,0 +1,315 @@
|
|||
package com.sqx.modules.yskPay.service;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.sqx.modules.yskPay.constants.SignTypeEnum;
|
||||
import com.sqx.modules.yskPay.req.*;
|
||||
import com.sqx.modules.yskPay.resp.*;
|
||||
import com.sqx.modules.yskPay.utils.DateUtils;
|
||||
import com.sqx.modules.yskPay.utils.JSONUtil;
|
||||
import com.sqx.modules.yskPay.utils.MD5Util;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
/**
|
||||
* @author GYJ
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ThirdPayService {
|
||||
|
||||
private static String micropay="/api/open/payment/micropay";
|
||||
|
||||
private static String ltpay="/api/open/payment/ltpay";
|
||||
|
||||
private static String trade="/api/open/query/trade";
|
||||
|
||||
/**
|
||||
* 被扫接口
|
||||
*/
|
||||
public PublicResp<MainScanResp> mainScan(String url, String appId, String subject, String body, Long amount, String subAppId, String authCode, String orderNo, String storeId, String notifyUrl,
|
||||
String key
|
||||
) {
|
||||
|
||||
MainScanReq mainScanReq = new MainScanReq(subject, body, amount, subAppId, "cny", authCode, orderNo, storeId, notifyUrl);
|
||||
PublicParam param = new PublicParam(appId, "", SignTypeEnum.MD5.getValue(), null, DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(mainScanReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(micropay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<MainScanResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),MainScanResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 主扫接口(小程序)
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param payType
|
||||
* @param subAppId
|
||||
* @param userId
|
||||
* @param clinetIp
|
||||
* @param orderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param returnUrl
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
|
||||
public PublicResp<WxScanPayResp> scanpay(String url, String appId, String subject, String body, Long amount, String payType, String subAppId, String userId,
|
||||
String clinetIp, String orderNo, String storeId, String notifyUrl, String returnUrl,
|
||||
String key){
|
||||
WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,notifyUrl,returnUrl);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(scanPayReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(ltpay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<WxScanPayResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),WxScanPayResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
public PublicResp<WxScanPayResp> scanpay(String url,String appId, String subject, String body, Long amount,String payType, String subAppId, String userId,
|
||||
String clinetIp,String orderNo, String storeId, String notifyUrl,String returnUrl,
|
||||
String key, String extParam){
|
||||
WxScanPayReq scanPayReq=new WxScanPayReq(subject,body,amount,"cny",payType,subAppId,userId,clinetIp,orderNo,storeId,notifyUrl,returnUrl, extParam);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(),null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
|
||||
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(scanPayReq));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(ltpay)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<WxScanPayResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),WxScanPayResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单状态
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param payOrderId
|
||||
* @param mchOrderNo
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<OrderStatusQueryResp> queryOrder(String url, String appId, String payOrderId, String mchOrderNo, String key){
|
||||
OrderStatusQueryReq req=new OrderStatusQueryReq(payOrderId,mchOrderNo);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(req));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<OrderStatusQueryResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderStatusQueryResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 退款
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param mchRefundNo
|
||||
* @param payOrderId
|
||||
* @param mchOrderNo
|
||||
* @param refundReason
|
||||
* @param refundAmount
|
||||
* @param notifyUrl
|
||||
* @param extParam
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<OrderReturnResp> returnOrder(String url, String appId, String mchRefundNo, String payOrderId, String mchOrderNo, String refundReason, Long refundAmount, String notifyUrl, String extParam, String key){
|
||||
OrderRefundReq req=new OrderRefundReq(mchRefundNo, payOrderId, mchOrderNo, refundReason, refundAmount, notifyUrl, extParam);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(req));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<OrderReturnResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderReturnResp.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询退款订单
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param mchRefundNo
|
||||
* @param refundOrderId
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public PublicResp<OrderReturnQueryReq> returnOrderQuery(String url,String appId,String mchRefundNo, String refundOrderId,String key){
|
||||
OrderReturnQueryReq req=new OrderReturnQueryReq(mchRefundNo,refundOrderId);
|
||||
PublicParam param=new PublicParam(appId,null,SignTypeEnum.MD5.getValue(), null,DateUtils.getSdfTimes(), "1.0", String.valueOf(System.currentTimeMillis()));
|
||||
try {
|
||||
String str = JSONUtil.toJSONString(sortFields(req));
|
||||
param.setBizData(str);
|
||||
String tt = sortFieldsAndPrint(param);
|
||||
String MD5 = tt.concat("appSecret=" + key);
|
||||
log.info("加签原传:{}", MD5);
|
||||
String sign = MD5Util.encrypt(MD5);
|
||||
param.setSign(sign);
|
||||
String reqbody = JSONUtil.toJSONString(param);
|
||||
log.info("请求参数:{}", reqbody);
|
||||
String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body();
|
||||
log.info("返回结果:{}", response);
|
||||
PublicResp<OrderReturnQueryReq> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
|
||||
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderReturnQueryReq.class));
|
||||
return resp;
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static String sortFieldsAndPrint(Object obj) throws IllegalAccessException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
Class<?> clazz = obj.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
|
||||
// 按字段名称排序
|
||||
Arrays.sort(fields, Comparator.comparing(Field::getName));
|
||||
|
||||
for (Field field : fields) {
|
||||
// 可能需要设置访问权限
|
||||
field.setAccessible(true);
|
||||
if ("sign".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
Object value = field.get(obj);
|
||||
|
||||
|
||||
StringBuffer param = new StringBuffer();
|
||||
param.append(field.getName());
|
||||
param.append("=");
|
||||
if (value instanceof String) {
|
||||
param.append(value);
|
||||
|
||||
} else if (value instanceof Integer) {
|
||||
param.append(value);
|
||||
} else if (value instanceof Long) {
|
||||
param.append(value);
|
||||
}
|
||||
|
||||
param.append("&");
|
||||
sb.append(param);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static LinkedHashMap<String, Object> sortFields(Object obj) throws IllegalAccessException {
|
||||
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<>();
|
||||
Class<?> clazz = obj.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
|
||||
// 按字段名称排序
|
||||
Arrays.sort(fields, Comparator.comparing(Field::getName));
|
||||
|
||||
for (Field field : fields) {
|
||||
// 可能需要设置访问权限
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(obj);
|
||||
if(value==null){
|
||||
continue;
|
||||
}
|
||||
|
||||
map.put(field.getName(), value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
new ThirdPayService().mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "132933158610062686", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://cashierclient.sxczgkj.cn/cashierService/notify/fstmemberInCallBack", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,205 @@
|
|||
package com.sqx.modules.yskPay.utils;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.PropertyUtilsBean;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
public class BeanUtil {
|
||||
|
||||
// Map --> Bean 2: 利用org.apache.commons.beanutils 工具类实现 Map --> Bean
|
||||
public static void transMap2Bean2(Map<String, Object> map, Object obj) {
|
||||
if (map == null || obj == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
BeanUtils.populate(obj, map);
|
||||
} catch (Exception e) {
|
||||
System.out.println("transMap2Bean2 Error " + e);
|
||||
}
|
||||
}
|
||||
|
||||
// Map --> Bean 1: 利用Introspector,PropertyDescriptor实现 Map --> Bean
|
||||
public static void transMap2Bean(Map<String, Object> map, Object obj) {
|
||||
try {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
|
||||
PropertyDescriptor[] propertyDescriptors = beanInfo
|
||||
.getPropertyDescriptors();
|
||||
|
||||
for (PropertyDescriptor property : propertyDescriptors) {
|
||||
String key = property.getName();
|
||||
|
||||
if (map.containsKey(key)) {
|
||||
Object value = map.get(key);
|
||||
// 得到property对应的setter方法
|
||||
Method setter = property.getWriteMethod();
|
||||
setter.invoke(obj, value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("transMap2Bean Error " + e);
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
// Bean --> Map 1: 利用Introspector和PropertyDescriptor 将Bean --> Map
|
||||
public static Map<String, Object> transBean2Map(Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
try {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
|
||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||
for (PropertyDescriptor property : propertyDescriptors) {
|
||||
String key = property.getName();
|
||||
|
||||
// 过滤class属性
|
||||
if (!key.equals("class")) {
|
||||
// 得到property对应的getter方法
|
||||
Method getter = property.getReadMethod();
|
||||
Object value = getter.invoke(obj);
|
||||
if(null !=value && !"".equals(value))
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("transBean2Map Error " + e);
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static LinkedHashMap<String, Object> transBeanMap(Object obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
try {
|
||||
BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
|
||||
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
|
||||
for (PropertyDescriptor property : propertyDescriptors) {
|
||||
String key = property.getName();
|
||||
|
||||
// 过滤class属性
|
||||
if (!key.equals("class")) {
|
||||
// 得到property对应的getter方法
|
||||
Method getter = property.getReadMethod();
|
||||
Object value = getter.invoke(obj);
|
||||
if(null !=value && !"".equals(value))
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("transBean2Map Error " + e);
|
||||
}
|
||||
return map;
|
||||
|
||||
}
|
||||
|
||||
public static String mapOrderStr(Map<String, Object> map) {
|
||||
List<Entry<String, Object>> list = new ArrayList<Entry<String, Object>>(map.entrySet());
|
||||
Collections.sort(list, new Comparator<Entry<String, Object>>() {
|
||||
public int compare(Entry<String, Object> o1, Entry<String, Object> o2) {
|
||||
return o1.getKey().compareTo(o2.getKey());
|
||||
}
|
||||
});
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Entry<String, Object> mapping : list) {
|
||||
sb.append(mapping.getKey() + "=" + mapping.getValue() + "&");
|
||||
}
|
||||
return sb.substring(0, sb.length() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* 将源的属性复制到目标属性上去
|
||||
* @param src
|
||||
* @param dest
|
||||
* @lastModified
|
||||
* @history
|
||||
*/
|
||||
public static void copyProperties(Object dest,Object src) {
|
||||
if (src == null || dest == null) {
|
||||
return;
|
||||
}
|
||||
// 获取所有的get/set 方法对应的属性
|
||||
PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
|
||||
PropertyDescriptor[] descriptors = propertyUtilsBean.getPropertyDescriptors(src);
|
||||
|
||||
for (int i = 0; i < descriptors.length; i++) {
|
||||
PropertyDescriptor propItem = descriptors[i];
|
||||
// 过滤setclass/getclass属性
|
||||
if ("class".equals(propItem.getName())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
Method method = propItem.getReadMethod();
|
||||
// 通过get方法获取对应的值
|
||||
Object val = method.invoke(src);
|
||||
// 如果是空,不做处理
|
||||
if (null == val) {
|
||||
continue;
|
||||
}
|
||||
if(val instanceof String) {
|
||||
if(StringUtils.isBlank(val.toString())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 值复制
|
||||
PropertyDescriptor prop = propertyUtilsBean.getPropertyDescriptor(dest, propItem.getName());
|
||||
// 调用写方法,设置值
|
||||
if (null != prop && prop.getWriteMethod() != null) {
|
||||
prop.getWriteMethod().invoke(dest, val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static <T> T mapToEntity(Map<String, Object> map, Class<T> entity) {
|
||||
T t = null;
|
||||
try {
|
||||
t = entity.newInstance();
|
||||
for(Field field : entity.getDeclaredFields()) {
|
||||
if (map.containsKey(field.getName())) {
|
||||
boolean flag = field.isAccessible();
|
||||
field.setAccessible(true);
|
||||
Object object = map.get(field.getName());
|
||||
if (object!= null && field.getType().isAssignableFrom(object.getClass())) {
|
||||
field.set(t, object);
|
||||
}
|
||||
field.setAccessible(flag);
|
||||
}
|
||||
}
|
||||
return t;
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return t;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,430 @@
|
|||
package com.sqx.modules.yskPay.utils;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
/**
|
||||
* Created by SEELE on 2018/4/19.
|
||||
*/
|
||||
public class DateUtils {
|
||||
|
||||
private final static SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");
|
||||
private final static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
|
||||
private final static SimpleDateFormat sdfDays = new SimpleDateFormat("yyyyMMdd");
|
||||
private final static SimpleDateFormat sdfTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
private final static SimpleDateFormat sdfTimeM = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
private final static SimpleDateFormat sdfTimeSS = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
private final static SimpleDateFormat sdfTimes = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
|
||||
private final static SimpleDateFormat sdfTimesSS = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
|
||||
private final static SimpleDateFormat sdfday = new SimpleDateFormat("MM-dd HH:mm");
|
||||
|
||||
|
||||
public static Date getNewDate(Date date, Integer type, Integer interval) throws ParseException {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setTime(date);
|
||||
switch (type) {
|
||||
case 1:
|
||||
c.set(Calendar.YEAR, (c.get(Calendar.YEAR) + interval));
|
||||
break;
|
||||
case 2:
|
||||
c.set(Calendar.MONTH, (c.get(Calendar.MONTH) + interval));
|
||||
break;
|
||||
case 3:
|
||||
c.set(Calendar.DATE, (c.get(Calendar.DATE) + interval));
|
||||
break;
|
||||
case 4:
|
||||
c.set(Calendar.HOUR, (c.get(Calendar.HOUR) + interval));
|
||||
break;
|
||||
case 5:
|
||||
c.set(Calendar.MINUTE, (c.get(Calendar.MINUTE) + interval));
|
||||
break;
|
||||
default:
|
||||
c.set(Calendar.SECOND, (c.get(Calendar.SECOND) + interval));
|
||||
break;
|
||||
}
|
||||
Date newDate = c.getTime();
|
||||
return sdfTime.parse(sdfTime.format(newDate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getTimes(Date date){
|
||||
return sdfday.format(date);
|
||||
}
|
||||
public static String getTimeM(Date date){
|
||||
return sdfTimeM.format(date);
|
||||
}
|
||||
public static String getSdfDayTimes(Date date){
|
||||
return sdfDay.format(date);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取YYYY格式
|
||||
* @return
|
||||
*/
|
||||
public static String getSdfTimes() {
|
||||
return sdfTimes.format(new Date());
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static String getsdfTimesSS(){
|
||||
return sdfTimesSS.format(new Date());
|
||||
}
|
||||
|
||||
|
||||
public static String getNextSdfTimes(Date date){
|
||||
return sdfTimes.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY格式
|
||||
* @return
|
||||
*/
|
||||
public static String getYear() {
|
||||
return sdfYear.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY-MM-DD格式
|
||||
* @return
|
||||
*/
|
||||
public static String getDay() {
|
||||
return sdfDay.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYYMMDD格式
|
||||
* @return
|
||||
*/
|
||||
public static String getDays(){
|
||||
return sdfDays.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取YYYY-MM-DD HH:mm:ss格式
|
||||
* @return
|
||||
*/
|
||||
public static String getTime() {
|
||||
return sdfTime.format(new Date());
|
||||
}
|
||||
public static String getStrTime(Date date) {
|
||||
return sdfTime.format(date);
|
||||
}
|
||||
/**
|
||||
* @Title: compareDate
|
||||
* @Description: TODO(日期比较,如果s>=e 返回true 否则返回false)
|
||||
* @param s
|
||||
* @param e
|
||||
* @return boolean
|
||||
* @throws
|
||||
* @author fh
|
||||
*/
|
||||
public static boolean compareDate(String s, String e) {
|
||||
if(fomatDate(s)==null||fomatDate(e)==null){
|
||||
return false;
|
||||
}
|
||||
return fomatDate(s).getTime() >=fomatDate(e).getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期
|
||||
* @return
|
||||
*/
|
||||
public static Date fomatDate(String date) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
return fmt.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验日期是否合法
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDate(String s) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
fmt.parse(s);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param startTime
|
||||
* @param endTime
|
||||
* @return
|
||||
*/
|
||||
public static int getDiffYear(String startTime,String endTime) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
|
||||
try {
|
||||
//long aa=0;
|
||||
int years=(int) (((fmt.parse(endTime).getTime()-fmt.parse(startTime).getTime())/ (1000 * 60 * 60 * 24))/365);
|
||||
return years;
|
||||
} catch (Exception e) {
|
||||
// 如果throw java.text.ParseException或者NullPointerException,就说明格式不对
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <li>功能描述:时间相减得到天数
|
||||
* @param beginDateStr
|
||||
* @param endDateStr
|
||||
* @return
|
||||
* long
|
||||
* @author Administrator
|
||||
*/
|
||||
public static long getDaySub(String beginDateStr,String endDateStr){
|
||||
long day=0;
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = null;
|
||||
Date endDate = null;
|
||||
|
||||
try {
|
||||
beginDate = format.parse(beginDateStr);
|
||||
endDate= format.parse(endDateStr);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
day=(endDate.getTime()-beginDate.getTime())/(24*60*60*1000);
|
||||
//System.out.println("相隔的天数="+day);
|
||||
|
||||
return day;
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到n天之后的日期
|
||||
* @param days
|
||||
* @return
|
||||
*/
|
||||
public static String getAfterDayDate(String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
|
||||
Calendar canlendar = Calendar.getInstance(); // java.util包
|
||||
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
|
||||
Date date = canlendar.getTime();
|
||||
|
||||
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateStr = sdfd.format(date);
|
||||
|
||||
return dateStr;
|
||||
}
|
||||
/**
|
||||
* 得到n天之后的日期
|
||||
* @param days
|
||||
* @return
|
||||
*/
|
||||
public static String getAfterDate(Date openDate,String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
|
||||
Calendar canlendar = Calendar.getInstance(); // java.util包
|
||||
canlendar.setTime(openDate);
|
||||
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
|
||||
Date date = canlendar.getTime();
|
||||
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateStr = sdfd.format(date);
|
||||
return dateStr;
|
||||
}
|
||||
public static String getAfterDate1(Date openDate,String year) {
|
||||
int daysInt = Integer.parseInt(year);
|
||||
|
||||
Calendar canlendar = Calendar.getInstance(); // java.util包
|
||||
canlendar.setTime(openDate);
|
||||
canlendar.add(Calendar.YEAR, daysInt); // 日期减 如果不够减会将月变动
|
||||
Date date = canlendar.getTime();
|
||||
SimpleDateFormat sdfd = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String dateStr = sdfd.format(date);
|
||||
return dateStr;
|
||||
}
|
||||
public static Date getAfterDateStr(Date openDate,String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
|
||||
Calendar canlendar = Calendar.getInstance(); // java.util包
|
||||
canlendar.setTime(openDate);
|
||||
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
|
||||
Date date = canlendar.getTime();
|
||||
return date;
|
||||
}
|
||||
|
||||
/**
|
||||
* 今天结束时间
|
||||
* @return
|
||||
*/
|
||||
public static Date getDayEnd() {
|
||||
Calendar cal = new GregorianCalendar();
|
||||
cal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
cal.set(Calendar.MINUTE, 59);
|
||||
cal.set(Calendar.SECOND, 59);
|
||||
cal.set(Calendar.MILLISECOND, 999);
|
||||
return cal.getTime();
|
||||
}
|
||||
|
||||
public static Long getDayStartLong() {
|
||||
// 获取今天的日期和时间(00:00:00)
|
||||
LocalDateTime todayStart = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
// 转换为UTC时间戳(毫秒)
|
||||
long timestampInMillis = todayStart.toInstant(ZoneOffset.UTC).toEpochMilli();
|
||||
|
||||
return timestampInMillis;
|
||||
}
|
||||
|
||||
public static Long getDayEndLong() {
|
||||
// 获取今天的日期和时间(00:00:00)
|
||||
LocalDateTime todayStart = LocalDateTime.now().toLocalDate().atStartOfDay();
|
||||
|
||||
// 将时间设置为今天的结束时间(23:59:59.999999999)
|
||||
LocalDateTime endOfDay = todayStart.plusDays(1).minusNanos(1);
|
||||
|
||||
// 转换为UTC时间戳(毫秒)
|
||||
long timestampInMillis = endOfDay.toInstant(ZoneOffset.UTC).toEpochMilli();
|
||||
|
||||
return timestampInMillis;
|
||||
}
|
||||
|
||||
public static String getTodayEndTimeAsString() {
|
||||
// 获取今天的日期
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
// 创建今天的结束时间(23:59:59.999)
|
||||
LocalTime endTime = LocalTime.of(23, 59, 59, 999_000_000);
|
||||
|
||||
// 组合日期和时间
|
||||
LocalDateTime todayEndTime = LocalDateTime.of(today, endTime);
|
||||
|
||||
// 格式化时间
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
|
||||
|
||||
// 转换为字符串
|
||||
return todayEndTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到n天之后是周几
|
||||
* @param days
|
||||
* @return
|
||||
*/
|
||||
public static String getAfterDayWeek(String days) {
|
||||
int daysInt = Integer.parseInt(days);
|
||||
Calendar canlendar = Calendar.getInstance(); // java.util包
|
||||
canlendar.add(Calendar.DATE, daysInt); // 日期减 如果不够减会将月变动
|
||||
Date date = canlendar.getTime();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("E");
|
||||
String dateStr = sdf.format(date);
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期为时分秒
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static Date fomatDateTime(String date) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
try {
|
||||
return fmt.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Date fomatDateTime1(String date) {
|
||||
DateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
try {
|
||||
return fmt.parse(date);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Date parse(String dateString, String dateFormat) {
|
||||
if ("".equals(dateString.trim()) || dateString == null) {
|
||||
return null;
|
||||
}
|
||||
DateFormat sdf = new SimpleDateFormat(dateFormat);
|
||||
Date date = null;
|
||||
try {
|
||||
date = sdf.parse(dateString);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return date;
|
||||
}
|
||||
|
||||
|
||||
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
public static Date convertDate(String date) {
|
||||
try {
|
||||
return sdf.parse(date);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private final static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public static Date convertDateByString(String str){
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append(str.substring(0,4));
|
||||
sb.append("-");
|
||||
sb.append(str.substring(4,6));
|
||||
sb.append("-");
|
||||
sb.append(str.substring(6,8));
|
||||
sb.append(" ");
|
||||
sb.append(str.substring(8,10));
|
||||
sb.append(":");
|
||||
sb.append(str.substring(10,12));
|
||||
sb.append(":");
|
||||
sb.append(str.substring(12,14));
|
||||
|
||||
return convertDate1(sb.toString());
|
||||
}
|
||||
|
||||
public static Date convertDate1(String date) {
|
||||
try {
|
||||
return sdf1.parse(date);
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String getTime(Date date) {
|
||||
return sdfTime.format(date);
|
||||
}
|
||||
|
||||
|
||||
public static String formatDateToStr(Date date) {
|
||||
return sdfTime.format(date);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,263 @@
|
|||
package com.sqx.modules.yskPay.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stone
|
||||
* @version V1.0.0
|
||||
* @date 2020/2/12
|
||||
*/
|
||||
public class JSONUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 将对象转为JSON字符串
|
||||
*
|
||||
* @param obj 被转的对象
|
||||
* @param dateFormat 日期格式,当传null或空串时,则被格式化为时间戳,否则返回指定的格式。例子:yyyy-MM-dd HH:mm:ss(不合法的日期格式会格式化出错)
|
||||
* @param ignoreNull 是否忽略null字段。true时,且当字段的值是null,则不输出该字段
|
||||
* @param noRef 是否不转换成ref。例如false,当字段间是相同的引用之时,则将出现$ref之类的符号替代冗余的值
|
||||
* @param pretty 是否格式化JSON字符串以便有更好的可读性
|
||||
* @return JSON字符串,出异常时抛出
|
||||
*/
|
||||
public static String toJSONString0(Object obj,
|
||||
String dateFormat,
|
||||
boolean ignoreNull,
|
||||
boolean noRef,
|
||||
boolean pretty) {
|
||||
try {
|
||||
List<SerializerFeature> featureList = new ArrayList<>();
|
||||
|
||||
// 当传null时,则返回默认的时间戳,否则则返回指定的格式
|
||||
if (dateFormat != null && dateFormat.length() > 0) {
|
||||
featureList.add(SerializerFeature.WriteDateUseDateFormat);
|
||||
}
|
||||
if (!ignoreNull) {
|
||||
// 当字段的值是null时,依然出现这个字段,即不忽略
|
||||
featureList.add(SerializerFeature.WriteMapNullValue);
|
||||
}
|
||||
if (noRef) {
|
||||
featureList.add(SerializerFeature.DisableCircularReferenceDetect);
|
||||
}
|
||||
if (pretty) {
|
||||
featureList.add(SerializerFeature.PrettyFormat);
|
||||
}
|
||||
|
||||
SerializerFeature[] featureArr = featureList.toArray(new SerializerFeature[featureList.size()]);
|
||||
return JSONObject.toJSONString(obj, SerializeConfig.globalInstance, null, dateFormat,
|
||||
JSON.DEFAULT_GENERATE_FEATURE, featureArr);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Convert object to JSON string, error[" + obj + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为JSON字符串。
|
||||
* 日期转为特别的格式,不忽略null值的字段,不格式化JSON字符串
|
||||
*
|
||||
* @param obj 被转换的对象
|
||||
* @return JSON字符串,发送异常时抛出
|
||||
*/
|
||||
public static String toJSONString(Object obj) {
|
||||
return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", false, true, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象转为JSON字符串。不抛出异常,专用于日志打印
|
||||
*
|
||||
* @param obj 被转换的对象
|
||||
* @return JSON字符串,出异常时返回null
|
||||
*/
|
||||
public static String toJSONStringNoThrows(Object obj) {
|
||||
try {
|
||||
return toJSONString0(obj, "yyyy-MM-dd HH:mm:ss", false, true, false);
|
||||
} catch (Exception e) {
|
||||
logError(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析JSON字符串成为一个Object,结果可能是JSONArray(多个)或JSONObject(单个)
|
||||
* (该方法可用于对json字符串不知道是对象还是列表的时候之用)
|
||||
* (假设json字符串多了某个字段,可能是新加上去的,显然转换成JSONEntity会有这个字段)
|
||||
*
|
||||
* @param jsonStr 要解析的JSON字符串
|
||||
* @return 返回JSONEntity,当jsonArrayFlag 为true,表示它是 JSONArray,否则是JSONObject
|
||||
*/
|
||||
public static JSONEntity parseJSONStr2JSONEntity(String jsonStr) {
|
||||
try {
|
||||
Object value = JSON.parse(jsonStr);
|
||||
boolean jsonArrayFlag = false;
|
||||
if (value instanceof JSONArray) {
|
||||
jsonArrayFlag = true;
|
||||
}
|
||||
return new JSONEntity(jsonArrayFlag, value);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转为JSON对象,注意数组类型会抛异常[{name:\"Stone\"}]
|
||||
* (假设json字符串多了某个字段,可能是新加上去的,显然转换成JSONObject时会有这个字段,因为JSONObject就相当于map)
|
||||
*
|
||||
* @param jsonStr 传入的JSON字串
|
||||
* @return 返回转换结果。传入的JSON字串必须是对象而非数组,否则会抛出异常
|
||||
* @author Stone
|
||||
*/
|
||||
public static JSONObject parseJSONStr2JSONObject(String jsonStr) {
|
||||
try {
|
||||
return (JSONObject) JSONObject.parse(jsonStr);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:\"Stone\"}
|
||||
* (假设json字符串多了某个字段,可能是新加上去的,显然转换成JSONArray时,其元素会有这个字段,因为JSONArray的元素JSONObject就相当于map)
|
||||
*
|
||||
* @param jsonStr 传入的JSON字串
|
||||
* @return 返回转换结果。当传入的JSON字串是非数组形式时,会抛出异常
|
||||
* @author Stone
|
||||
*/
|
||||
public static JSONArray parseJSONStr2JSONArray(String jsonStr) {
|
||||
try {
|
||||
return (JSONArray) JSONArray.parse(jsonStr);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转为某个类
|
||||
* (日期字段不管是时间戳形式还是yyyy-MM-dd HH:mm:ss的形式都能成功转换)
|
||||
* (假设json字符串多了某个字段,可能是新加上去的,T类没有,转换成T对象的时候,不会抛出异常)
|
||||
*
|
||||
* @param jsonStr 传入的JSON字串
|
||||
* @param clazz 转为什么类型
|
||||
* @return 返回转换结果。当传入的JSON字串是数组形式时,会抛出异常
|
||||
* @author Stone
|
||||
*/
|
||||
public static <T> T parseJSONStr2T(String jsonStr, Class<T> clazz) {
|
||||
try {
|
||||
return JSONObject.parseObject(jsonStr, clazz);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转为某个类的列表
|
||||
* (日期字段不管是时间戳形式还是yyyy-MM-dd HH:mm:ss的形式都能成功转换)
|
||||
* (假设json字符串多了某个字段,可能是新加上去的,T类没有,转换成T对象的时候,不会抛出异常)
|
||||
*
|
||||
* @param jsonStr 传入的JSON字串
|
||||
* @param clazz List里装的元素的类型
|
||||
* @return 返回转换结果。当传入的JSON字串是非数组的形式时会抛出异常
|
||||
* @author Stone
|
||||
*/
|
||||
public static <T> List<T> parseJSONStr2TList(String jsonStr, Class<T> clazz) {
|
||||
try {
|
||||
return JSONObject.parseArray(jsonStr, clazz);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list 某集合
|
||||
* @param clazz 要转成的实体
|
||||
* 需要在目标实体增加注解 忽略未知属性 @JsonIgnoreProperties(ignoreUnknown = true)
|
||||
* @return
|
||||
* @param <T>
|
||||
*/
|
||||
public static <T> List<T> parseListTNewList(List<?> list, Class<T> clazz) {
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器
|
||||
try {
|
||||
// 将List<?>转换为JSON字符串
|
||||
String json = objectMapper.writeValueAsString(list);
|
||||
// 将JSON字符串转换为List<T>
|
||||
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> List<T> parseListTNewList(String json, Class<T> clazz) {
|
||||
ObjectMapper objectMapper = new ObjectMapper(); // 创建JSON转换器
|
||||
try {
|
||||
// 将JSON字符串转换为List<T>
|
||||
return objectMapper.readValue(json, objectMapper.getTypeFactory().constructCollectionType(List.class, clazz));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class JSONEntity {
|
||||
public JSONEntity() {
|
||||
}
|
||||
|
||||
public JSONEntity(boolean jsonArrayFlag, Object value) {
|
||||
this.jsonArrayFlag = jsonArrayFlag;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private boolean jsonArrayFlag;
|
||||
private Object value;
|
||||
|
||||
public boolean getJsonArrayFlag() {
|
||||
return jsonArrayFlag;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JSONEntity{" +
|
||||
"jsonArrayFlag=" + jsonArrayFlag +
|
||||
", value=" + value +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
private static void logError(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject sortJSONObject(JSONObject jsonObject, Map<String, String> keyMap) {
|
||||
// 提取JSONObject中的键值对到一个列表中
|
||||
// List<Map.Entry<String, Object>> list = new ArrayList<>(jsonObject.toJavaObject(Map.class).entrySet());
|
||||
List<String> list = new ArrayList<>(jsonObject.keySet());
|
||||
|
||||
// 对键值对列表按照键的ASCII顺序进行排序
|
||||
// list.sort(Map.Entry.comparingByKey());
|
||||
Collections.sort(list);
|
||||
// 遍历排序后的列表,将键值对转换为字符串并拼接起来
|
||||
TreeMap<String, Object> sortedMap = new TreeMap<>();
|
||||
for (String key : list) {
|
||||
if (!keyMap.containsKey(key)) {
|
||||
sortedMap.put(key, jsonObject.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
// 返回排序后的字符串
|
||||
return new JSONObject(sortedMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
package com.sqx.modules.yskPay.utils;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MD5Util {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MD5Util.class);
|
||||
|
||||
private static final String hexDigIts[] = {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
|
||||
|
||||
public static String encrypt(String plainText) {
|
||||
try {
|
||||
return encrypt(plainText,true);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
log.error("MD5加密异常:",e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: encrypt
|
||||
* @Description: TODO(16位或32位密码)
|
||||
* @param @param
|
||||
* plainText
|
||||
* @param @param
|
||||
* flag true为32位,false为16位
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String encrypt(String plainText, boolean flag) throws UnsupportedEncodingException {
|
||||
try {
|
||||
if (StringUtils.isEmpty(plainText)) {
|
||||
return null;
|
||||
}
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
String encrStr = byteArrayToHexString(md.digest(plainText.getBytes("UTF-8")));
|
||||
if (flag)
|
||||
return encrStr;
|
||||
else
|
||||
return encrStr.substring(8, 24);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static String encrypt(Object obj,String privateKey){
|
||||
if(obj==null){
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> map = new HashMap<String,Object>();
|
||||
if(obj instanceof Map){
|
||||
map=(Map<String, Object>) obj;
|
||||
}else{
|
||||
map = BeanUtil.transBean2Map(obj);
|
||||
}
|
||||
return encrypt(map,privateKey,true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Title: encrypt
|
||||
* @Description: TODO(16位或32位密码)
|
||||
* @param @param
|
||||
* plainText
|
||||
* @param @param
|
||||
* flag true为32位,false为16位
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public static String encrypt(Map<String, Object> map, String privateKey,boolean flag) {
|
||||
String param = null;
|
||||
map.remove("sign");
|
||||
map.remove("encrypt");
|
||||
String result = BeanUtil.mapOrderStr(map);
|
||||
if (StringUtils.isEmpty(result)) {
|
||||
return null;
|
||||
}
|
||||
param = encrypt(encrypt(result)+privateKey);
|
||||
if (flag) {
|
||||
return param;
|
||||
} else {
|
||||
param = param.substring(8, 24);
|
||||
}
|
||||
return param;
|
||||
}
|
||||
|
||||
public static Map<String, Object> resultMap = new HashMap<String, Object>();
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, Object> mapFn(Map<String, Object> map) {
|
||||
for (String key : map.keySet()) {
|
||||
if (map.get(key) != null && map.get(key) != "" && (!key.equals("BTYPE") && !key.equals("SIGN"))) {
|
||||
if (key.equals("INPUT")) {
|
||||
if (map.get(key) != null) {
|
||||
mapFn((Map<String, Object>) map.get(key));
|
||||
}
|
||||
} else {
|
||||
resultMap.put(key, map.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static boolean check(Object obj,String privateKey){
|
||||
Map<String,Object> map=new HashMap<String,Object>();
|
||||
if(obj==null){
|
||||
return false;
|
||||
}
|
||||
if(obj instanceof Map){
|
||||
map=(Map<String, Object>) obj;
|
||||
}else{
|
||||
map = BeanUtil.transBean2Map(obj);
|
||||
}
|
||||
System.out.println("check:"+ JSONUtil.toJsonStr(map));
|
||||
String sign=(String)map.get("sign");
|
||||
if(sign==null){
|
||||
return false;
|
||||
}
|
||||
String str=encrypt(obj,privateKey);
|
||||
System.out.println("check: "+str);
|
||||
|
||||
return sign.equals(str)?true:false;
|
||||
}
|
||||
|
||||
public static String byteArrayToHexString(byte b[]){
|
||||
StringBuffer resultSb = new StringBuffer();
|
||||
for(int i = 0; i < b.length; i++){
|
||||
resultSb.append(byteToHexString(b[i]));
|
||||
}
|
||||
return resultSb.toString();
|
||||
}
|
||||
|
||||
public static String byteToHexString(byte b){
|
||||
int n = b;
|
||||
if(n < 0){
|
||||
n += 256;
|
||||
}
|
||||
int d1 = n / 16;
|
||||
int d2 = n % 16;
|
||||
return hexDigIts[d1] + hexDigIts[d2];
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue