应用中心
-存酒 团购卷退款
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package cn.ysk.cashier.thirdpay.constants;
|
||||
|
||||
public enum SignTypeEnum {
|
||||
|
||||
MD5("MD5"),RSA2("RSA2");
|
||||
|
||||
private final String value;
|
||||
|
||||
SignTypeEnum(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.ysk.cashier.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@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,18 @@
|
||||
package cn.ysk.cashier.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,18 @@
|
||||
package cn.ysk.cashier.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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 cn.ysk.cashier.thirdpay.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,36 @@
|
||||
package cn.ysk.cashier.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class OderReturnQueyResp 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,33 @@
|
||||
package cn.ysk.cashier.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,49 @@
|
||||
package cn.ysk.cashier.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,22 @@
|
||||
package cn.ysk.cashier.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
@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,206 @@
|
||||
package cn.ysk.cashier.thirdpay.service;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
|
||||
import cn.ysk.cashier.thirdpay.constants.SignTypeEnum;
|
||||
import cn.ysk.cashier.thirdpay.req.OrderRefundReq;
|
||||
import cn.ysk.cashier.thirdpay.req.OrderReturnQueryReq;
|
||||
import cn.ysk.cashier.thirdpay.req.OrderStatusQueryReq;
|
||||
import cn.ysk.cashier.thirdpay.req.PublicParam;
|
||||
import cn.ysk.cashier.thirdpay.resp.OrderReturnResp;
|
||||
import cn.ysk.cashier.thirdpay.resp.OrderStatusQueryResp;
|
||||
import cn.ysk.cashier.thirdpay.resp.PublicResp;
|
||||
import cn.ysk.cashier.utils.JSONUtil;
|
||||
import cn.ysk.cashier.utils.MD5Utils;
|
||||
import com.dianguang.cloud.ossservice.model.DateUtils;
|
||||
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;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ThirdPayService {
|
||||
|
||||
|
||||
private static String trade="/api/open/query/trade";
|
||||
|
||||
/**
|
||||
* 查询订单状态
|
||||
* @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 = MD5Utils.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 = MD5Utils.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 = MD5Utils.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) {
|
||||
// mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user