Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/resources/generator-mapper/generatorConfig.xml
This commit is contained in:
@@ -40,7 +40,7 @@ public class DataCache {
|
||||
|
||||
@Bean
|
||||
public void init(){
|
||||
log.info("加载店铺信息");
|
||||
// log.info("加载店铺信息");
|
||||
shopInfo();
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +78,69 @@ public class PayController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 快捷收款
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
* @param amount
|
||||
* @param authCode
|
||||
* @param payType cash 现金 scanpay 扫码
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("quickPay")
|
||||
public Result quickPay(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("amount") String amount,
|
||||
@RequestParam("authCode") String authCode,
|
||||
@RequestParam("payType") String payType
|
||||
){
|
||||
return payService.quickPay(token,amount,authCode,payType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询快捷订单状态
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("queryQuickPayStatus")
|
||||
public Result queryQuickPayStatus(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("id") Integer id
|
||||
){
|
||||
return payService.queryQuickPayStatus(id);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取快捷收款信息
|
||||
* @param token
|
||||
* @param loginName
|
||||
* @param clientType
|
||||
* @param page
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("queryQuickPay")
|
||||
public Result queryQuickPay(@RequestHeader("token") String token,
|
||||
@RequestHeader("loginName") String loginName,
|
||||
@RequestHeader("clientType") String clientType,
|
||||
@RequestParam("page") Integer page,
|
||||
@RequestParam("pageSize") Integer pageSize
|
||||
){
|
||||
return payService.queryQuickPay(token,page,pageSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 会员扫码支付
|
||||
|
||||
@@ -14,7 +14,13 @@ import com.chaozhanggui.system.cashierservice.model.TradeQueryReq;
|
||||
import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer;
|
||||
import com.chaozhanggui.system.cashierservice.sign.CodeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.sign.Result;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.MainScanResp;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.OrderStatusQueryResp;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.PublicResp;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.service.ThirdPayService;
|
||||
import com.chaozhanggui.system.cashierservice.util.*;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
@@ -77,6 +83,22 @@ public class PayService {
|
||||
@Value("${client.backUrl}")
|
||||
private String backUrl;
|
||||
|
||||
@Value("${thirdPay.payType}")
|
||||
private String thirdPayType;
|
||||
|
||||
|
||||
@Value("${thirdPay.url}")
|
||||
private String url;
|
||||
|
||||
|
||||
|
||||
@Value("${thirdPay.callBack}")
|
||||
private String callBack;
|
||||
|
||||
|
||||
@Autowired
|
||||
ThirdPayService thirdPayService;
|
||||
|
||||
|
||||
public Result queryPayType(String shopId) {
|
||||
return Result.success(CodeEnum.SUCCESS, tbShopPayTypeMapper.selectByShopId(shopId));
|
||||
@@ -100,6 +122,16 @@ public class PayService {
|
||||
return Result.fail(CodeEnum.ORDERSTATUSERROR);
|
||||
}
|
||||
|
||||
|
||||
List<TbCashierCart> cashierCarts= tbCashierCartMapper.selectByOrderId(orderId,"create");
|
||||
if(ObjectUtil.isEmpty(cashierCarts)||ObjectUtil.isNull(cashierCarts)){
|
||||
return Result.fail(CodeEnum.CARTEXIST);
|
||||
}
|
||||
|
||||
StringBuffer body=new StringBuffer();
|
||||
for (TbCashierCart cashierCart : cashierCarts) {
|
||||
body.append(cashierCart.getName());
|
||||
}
|
||||
if (ObjectUtil.isNull(orderInfo.getMerchantId()) || ObjectUtil.isEmpty(orderInfo.getMerchantId())) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
@@ -163,68 +195,126 @@ public class PayService {
|
||||
orderInfo.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
if("ysk".equals(thirdPayType)){
|
||||
|
||||
ScanPayReq scanPayReq = new ScanPayReq();
|
||||
scanPayReq.setAppId(thirdApply.getAppId());
|
||||
scanPayReq.setTimestamp(System.currentTimeMillis());
|
||||
scanPayReq.setAuthCode(authCode);
|
||||
scanPayReq.setNotifyUrl(backUrl);
|
||||
scanPayReq.setConsumeFee(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
||||
ScanPayReq scanPayReq = new ScanPayReq();
|
||||
scanPayReq.setAppId(thirdApply.getAppId());
|
||||
scanPayReq.setTimestamp(System.currentTimeMillis());
|
||||
scanPayReq.setAuthCode(authCode);
|
||||
scanPayReq.setNotifyUrl(backUrl);
|
||||
scanPayReq.setConsumeFee(payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).toPlainString());
|
||||
|
||||
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
||||
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
||||
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
||||
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
if (object.get("code").equals("0")) {
|
||||
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(object.getJSONObject("data").get("orderNumber").toString());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderId);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
|
||||
} else {
|
||||
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
|
||||
if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
|
||||
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
||||
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
if (object.get("code").equals("0")) {
|
||||
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(object.getJSONObject("data").get("orderNumber").toString());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderId);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, object.getJSONObject("data"));
|
||||
} else {
|
||||
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
|
||||
if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
|
||||
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
payment.setTradeNumber(object.getJSONObject("data").get("orderNumber").toString());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
// orderInfo.setStatus("fail");
|
||||
// orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
// tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
return Result.fail(object.getString("msg"));
|
||||
return Result.fail(object.getString("msg"));
|
||||
}
|
||||
}
|
||||
}else {
|
||||
|
||||
String reqbody="";
|
||||
|
||||
if(body.length()>15){
|
||||
reqbody=body.substring(0,6).concat("....").concat(body.substring(body.length()-6,body.length())).toString();
|
||||
}else {
|
||||
reqbody=body.toString();
|
||||
}
|
||||
|
||||
PublicResp<MainScanResp> publicResp= thirdPayService.mainScan(url,thirdApply.getAppId(),reqbody,reqbody,payment.getAmount().setScale(2, BigDecimal.ROUND_DOWN).multiply(new BigDecimal(100)).longValue(),payType.equals("wechatPay")?"wx212769170d2c6b2a":null,authCode,orderInfo.getOrderNo(),"S2405103298",callBack,thirdApply.getAppToken());
|
||||
if(ObjectUtil.isNotNull(publicResp)&&ObjectUtil.isNotEmpty(publicResp)){
|
||||
if("000000".equals(publicResp.getCode())){
|
||||
MainScanResp mainScanResp= publicResp.getObjData();
|
||||
if("TRADE_SUCCESS".equals(mainScanResp.getState())){
|
||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
|
||||
//处理支付成功的订单
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(mainScanResp.getPayOrderId());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
//更新子单状态
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderId);
|
||||
|
||||
return Result.success(CodeEnum.SUCCESS, mainScanResp);
|
||||
}else if("TRADE_AWAIT".equals(mainScanResp.getState())){
|
||||
orderInfo.setStatus("paying");
|
||||
orderInfo.setPayOrderNo(payment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
payment.setTradeNumber(mainScanResp.getPayOrderId());
|
||||
payment.setUpdatedAt(System.currentTimeMillis());
|
||||
tbOrderPaymentMapper.updateByPrimaryKeySelective(payment);
|
||||
return Result.success(CodeEnum.PAYING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return Result.fail("失败");
|
||||
}
|
||||
|
||||
@@ -249,6 +339,7 @@ public class PayService {
|
||||
|
||||
TbOrderPayment tbOrderPayment = tbOrderPaymentMapper.selectByOrderId(orderId);
|
||||
if (ObjectUtil.isNotEmpty(tbOrderPayment)) {
|
||||
if("ysk".equals(thirdPayType)){
|
||||
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
||||
tradeQueryReq.setAppId(thirdApply.getAppId());
|
||||
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
||||
@@ -283,6 +374,33 @@ public class PayService {
|
||||
}
|
||||
}
|
||||
}
|
||||
}else {
|
||||
PublicResp<OrderStatusQueryResp> orderstatus=thirdPayService.queryOrder(url,thirdApply.getAppId(),orderInfo.getOrderNo(),null,thirdApply.getAppToken());
|
||||
if(ObjectUtil.isNotNull(orderstatus)&&ObjectUtil.isNotEmpty(orderstatus)){
|
||||
if("000000".equals(orderstatus.getCode())){
|
||||
if("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())){
|
||||
orderInfo.setStatus("closed");
|
||||
orderInfo.setPayOrderNo(tbOrderPayment.getTradeNumber());
|
||||
tbOrderInfoMapper.updateByPrimaryKeySelective(orderInfo);
|
||||
|
||||
//更新购物车状态
|
||||
int cartCount = tbCashierCartMapper.updateByOrderId(orderId, "final");
|
||||
log.info("更新购物车:{}", cartCount);
|
||||
|
||||
tbOrderDetailMapper.updateStatusByOrderIdAndStatus(Integer.valueOf(orderId), "closed");
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("token", token);
|
||||
jsonObject.put("type", "create");
|
||||
jsonObject.put("orderId", orderId);
|
||||
|
||||
producer.putOrderCollect(jsonObject.toJSONString());
|
||||
|
||||
producer.printMechine(orderId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,6 +838,122 @@ public class PayService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
TbShopInfoMapper tbShopInfoMapper;
|
||||
|
||||
@Autowired
|
||||
TbQuickPayMapper tbQuickPayMapper;
|
||||
|
||||
public Result quickPay(String token,String amount,String authCode,String payType){
|
||||
|
||||
JSONObject info= TokenUtil.parseParamFromToken(token);
|
||||
MsgException.checkNull(info,"获取信息失败");
|
||||
|
||||
String shopId=info.getString("shopId");
|
||||
String staffId=info.getString("staffId");
|
||||
|
||||
BigDecimal payAmount=new BigDecimal(amount).setScale(2, BigDecimal.ROUND_DOWN);
|
||||
|
||||
|
||||
String orderNo=SnowFlakeUtil.generateOrderNo();
|
||||
|
||||
TbQuickPay tbQuickPay= new TbQuickPay(null,Integer.valueOf(staffId),Integer.valueOf(shopId),orderNo,payType,payAmount,"1",null,new Date(),null);
|
||||
|
||||
if("cash".equals(payType)){
|
||||
tbQuickPay.setStatus("0");
|
||||
tbQuickPay.setUpdateTime(new Date());
|
||||
|
||||
}else {
|
||||
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
|
||||
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
|
||||
|
||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbShopInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
ScanPayReq scanPayReq = new ScanPayReq();
|
||||
scanPayReq.setAppId(thirdApply.getAppId());
|
||||
scanPayReq.setTimestamp(System.currentTimeMillis());
|
||||
scanPayReq.setAuthCode(authCode);
|
||||
scanPayReq.setNotifyUrl(backUrl);
|
||||
scanPayReq.setConsumeFee(payAmount.toPlainString());
|
||||
|
||||
Map<String, Object> map = BeanUtil.transBean2Map(scanPayReq);
|
||||
scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/scanPay"), scanPayReq, String.class);
|
||||
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
if (object.get("code").equals("0")) {
|
||||
tbQuickPay.setTradeNo(object.getJSONObject("data").get("orderNumber").toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tbQuickPayMapper.insert(tbQuickPay);
|
||||
return Result.success(CodeEnum.SUCCESS,tbQuickPay);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public Result queryQuickPayStatus(Integer id){
|
||||
|
||||
TbQuickPay tbQuickPay= tbQuickPayMapper.selectByPrimaryKey(id);
|
||||
MsgException.checkNull(tbQuickPay,"订单信息不存在");
|
||||
if(tbQuickPay.getPayType().equals("scanpay")&&"1".equals(tbQuickPay.getStatus())) {
|
||||
|
||||
TbShopInfo tbShopInfo= tbShopInfoMapper.selectByPrimaryKey(tbQuickPay.getShopId());
|
||||
MsgException.checkNull(tbShopInfo,"店铺信息不存在");
|
||||
|
||||
TbMerchantThirdApply thirdApply = tbMerchantThirdApplyMapper.selectByPrimaryKey(Integer.valueOf(tbShopInfo.getMerchantId()));
|
||||
if (ObjectUtil.isEmpty(thirdApply) || ObjectUtil.isNull(thirdApply)) {
|
||||
return Result.fail(CodeEnum.NOCUSTOMER);
|
||||
}
|
||||
TradeQueryReq tradeQueryReq = new TradeQueryReq();
|
||||
tradeQueryReq.setAppId(thirdApply.getAppId());
|
||||
tradeQueryReq.setTimestamp(System.currentTimeMillis());
|
||||
tradeQueryReq.setOrderNumber(tbQuickPay.getTradeNo());
|
||||
|
||||
Map<String, Object> map = BeanUtil.transBean2Map(tradeQueryReq);
|
||||
tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true));
|
||||
ResponseEntity<String> response = restTemplate.postForEntity(gateWayUrl.concat("merchantOrder/tradeQuery"), tradeQueryReq, String.class);
|
||||
if (response.getStatusCodeValue() == 200 && ObjectUtil.isNotEmpty(response.getBody())) {
|
||||
JSONObject object = JSONObject.parseObject(response.getBody());
|
||||
if (object.get("code").equals("0")) {
|
||||
JSONObject data = object.getJSONObject("data");
|
||||
if ("1".equals(data.getString("status"))) {
|
||||
|
||||
tbQuickPay.setStatus("0");
|
||||
tbQuickPay.setUpdateTime(new Date());
|
||||
tbQuickPayMapper.updateByPrimaryKeySelective(tbQuickPay);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success(CodeEnum.SUCCESS,tbQuickPay);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Result queryQuickPay(String token,int pageNo,int pageSize){
|
||||
JSONObject info= TokenUtil.parseParamFromToken(token);
|
||||
MsgException.checkNull(info,"获取信息失败");
|
||||
|
||||
String shopId=info.getString("shopId");
|
||||
String staffId=info.getString("staffId");
|
||||
PageHelper.startPage(pageNo, pageSize);
|
||||
|
||||
|
||||
List<TbQuickPay> list= tbQuickPayMapper.selectByShopIdAndStaffId(Integer.valueOf(shopId),Integer.valueOf(staffId));
|
||||
PageInfo pageInfo=new PageInfo(list);
|
||||
return Result.success(CodeEnum.SUCCESS,pageInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String generateReturnOrderNumber() {
|
||||
String date = DateUtils.getSdfTimes();
|
||||
Random random = new Random();
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.chaozhanggui.system.cashierservice.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,41 @@
|
||||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,32 @@
|
||||
package com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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,49 @@
|
||||
package com.chaozhanggui.system.cashierservice.thirdpay.req;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,36 @@
|
||||
package com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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 com.chaozhanggui.system.cashierservice.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,51 @@
|
||||
package com.chaozhanggui.system.cashierservice.thirdpay.resp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@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,300 @@
|
||||
package com.chaozhanggui.system.cashierservice.thirdpay.service;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.constants.SignTypeEnum;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.req.*;
|
||||
import com.chaozhanggui.system.cashierservice.thirdpay.resp.*;
|
||||
import com.chaozhanggui.system.cashierservice.util.DateUtils;
|
||||
import com.chaozhanggui.system.cashierservice.util.JSONUtil;
|
||||
import com.chaozhanggui.system.cashierservice.util.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;
|
||||
|
||||
@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";
|
||||
|
||||
/**
|
||||
* 被扫接口
|
||||
* @param url
|
||||
* @param appId
|
||||
* @param subject
|
||||
* @param body
|
||||
* @param amount
|
||||
* @param subAppId
|
||||
* @param authCode
|
||||
* @param orderNo
|
||||
* @param storeId
|
||||
* @param notifyUrl
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订单状态
|
||||
* @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) {
|
||||
// mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI");
|
||||
}
|
||||
}
|
||||
@@ -166,6 +166,14 @@ public class JSONUtil {
|
||||
throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e);
|
||||
}
|
||||
}
|
||||
public static <T> T jsonStrToObject(String jsonStr, Class<T> clazz) {
|
||||
Object obj = JSONArray.parseObject(jsonStr, clazz);
|
||||
return (T) obj;
|
||||
}
|
||||
|
||||
public static <T> T jsonstrtoObject(String str,TypeReference<T> tTypeReference ){
|
||||
return JSON.parseObject(str, tTypeReference);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String sss = "{\"bizData\":{\"amount\":1,\"currency\":\"cny\",\"ifCode\":\"sxfpay\",\"mchOrderNo\":\"CZ1715744291232\",\"mercNo\":\"B240510702030\",\"note\":\"等待用户付款\",\"payOrderId\":\"O1790587460614225921\",\"payType\":\"WECHAT\",\"settlementType\":\"D1\",\"state\":\"TRADE_AWAIT\",\"storeId\":\"S2405103298\",\"subject\":\"测试支付\",\"tradeFee\":0},\"code\":\"000000\",\"msg\":\"请求成功\",\"sign\":\"40710a3c293eeac3c7f4a1b0696a2bf6\",\"signType\":\"MD5\",\"timestamp\":\"20240515113813\"}";
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
package com.chaozhanggui.system.cashierservice.util;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
|
||||
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* The type Json operator.
|
||||
*
|
||||
* @author tianmaolin004
|
||||
* @date 2023 /3/18
|
||||
*/
|
||||
@Slf4j
|
||||
public class JsonUtils {
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
private static final String LOCAL_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
static {
|
||||
// 1 序列化及反序列化的时间配置
|
||||
JavaTimeModule timeModule = new JavaTimeModule();
|
||||
timeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
timeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ISO_LOCAL_DATE));
|
||||
timeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ISO_LOCAL_TIME));
|
||||
timeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ISO_LOCAL_TIME));
|
||||
timeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(LOCAL_DATE_TIME_PATTERN)));
|
||||
timeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(LOCAL_DATE_TIME_PATTERN)));
|
||||
objectMapper.registerModule(timeModule);
|
||||
objectMapper.setDateFormat(new SimpleDateFormat(LOCAL_DATE_TIME_PATTERN));
|
||||
|
||||
//2 忽略反序列化时,对象不存在对应属性的错误,如果不存在该属性,则设置值为null
|
||||
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
|
||||
|
||||
//3 忽略序列化时值为Null元素,不存在该元素,则字符串中无该元素,而不是展示为null
|
||||
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转字符串
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param obj the obj
|
||||
* @return the string
|
||||
*/
|
||||
public static <T> String obj2Str(T obj) {
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return obj instanceof String ? (String) obj : objectMapper.writeValueAsString(obj);
|
||||
} catch (Exception e) {
|
||||
log.error("obj2Str fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转对象
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param str the str
|
||||
* @param clazz the clazz
|
||||
* @return the t
|
||||
*/
|
||||
public static <T> T str2Obj(String str, Class<T> clazz) {
|
||||
if (StringUtils.isEmpty(str) || clazz == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return clazz.equals(String.class) ? (T) str : objectMapper.readValue(str, clazz);
|
||||
} catch (Exception e) {
|
||||
log.error("str2Obj fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转对象:泛型模式,一般用于集合
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param str the str
|
||||
* @param typeReference the type reference
|
||||
* @return the t
|
||||
*/
|
||||
public static <T> T str2Obj(String str, TypeReference<T> typeReference) {
|
||||
if (StringUtils.isEmpty(str) || typeReference == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return (T) (typeReference.getType().equals(String.class) ? str : objectMapper.readValue(str, typeReference));
|
||||
} catch (Exception e) {
|
||||
log.error("str2Obj fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转JsonNode
|
||||
*
|
||||
* @param str the str
|
||||
* @return the json node
|
||||
*/
|
||||
public static JsonNode str2JsonNode(String str) {
|
||||
if (StringUtils.isEmpty(str)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return objectMapper.readTree(str);
|
||||
} catch (Exception e) {
|
||||
log.error("str2Obj fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象互转
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param fromValue the from value
|
||||
* @param toValueType the to value type
|
||||
* @return the t
|
||||
*/
|
||||
public static <T> T convertValue(@NonNull Object fromValue, @NonNull Class<T> toValueType) {
|
||||
try {
|
||||
return objectMapper.convertValue(fromValue, toValueType);
|
||||
} catch (Exception e) {
|
||||
log.error("str2Obj fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象互转泛型模式
|
||||
*
|
||||
* @param <T> the type parameter
|
||||
* @param fromValue the from value
|
||||
* @param toValueTypeRef the to value type ref
|
||||
* @return the t
|
||||
*/
|
||||
public static <T> T convertValue(@NonNull Object fromValue, @NonNull TypeReference<T> toValueTypeRef) {
|
||||
try {
|
||||
return objectMapper.convertValue(fromValue, toValueTypeRef);
|
||||
} catch (Exception e) {
|
||||
log.error("str2Obj fail");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,9 +15,9 @@ spring:
|
||||
com.chaozhanggui.system.openness: info
|
||||
redis:
|
||||
# redis数据库索引(默认为0),我们使用索引为3的数据库,避免和其他数据库冲突
|
||||
database: 0
|
||||
database: 5
|
||||
# redis服务器地址(默认为localhost)
|
||||
host: 121.40.128.145
|
||||
host: 101.37.12.135
|
||||
# redis端口(默认为6379)
|
||||
port: 6379
|
||||
# redis访问密码(默认为空)
|
||||
|
||||
@@ -38,4 +38,10 @@ gateway:
|
||||
url: https://gateway.api.sxczgkj.cn/gate-service/
|
||||
client:
|
||||
backUrl: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay
|
||||
thirdPay:
|
||||
payType: ysk
|
||||
callBack: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay
|
||||
url: https://paymentapi.sxczgkj.cn
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<generatorConfiguration>
|
||||
<!-- 需要指明数据库连接器的绝对路径 -->
|
||||
<!-- <classPathEntry location="C:\Users\admin\.m1\repository\mysql\mysql-connector-java\8.0.20\mysql-connector-java-8.0.20.jar" />-->
|
||||
<classPathEntry location="/Users/wangguocheng/Desktop/app/maven/repository/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar"/>
|
||||
<classPathEntry location="E:\app\maven\repository\mysql\mysql-connector-java\8.0.17\mysql-connector-java-8.0.17.jar"/>
|
||||
<context id="msqlTables" targetRuntime="MyBatis3">
|
||||
<!-- 生成的pojo,将implements Serializable-->
|
||||
<plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
|
||||
@@ -19,8 +19,8 @@
|
||||
|
||||
<!-- 数据库链接URL、用户名、密码 -->
|
||||
|
||||
<jdbcConnection connectionURL="jdbc:mysql://101.37.12.135:3306/fycashier?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8"
|
||||
driverClass="com.mysql.cj.jdbc.Driver" password="Twc6MrzzjBiWSsjh" userId="fycashier" >
|
||||
<jdbcConnection connectionURL="jdbc:mysql://121.40.128.145:3306/fycashier?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8"
|
||||
driverClass="com.mysql.cj.jdbc.Driver" password="mysqlroot@123" userId="root" >
|
||||
|
||||
<property name="nullCatalogMeansCurrent" value="true"/>
|
||||
</jdbcConnection>
|
||||
@@ -37,31 +37,28 @@
|
||||
也可以使用“MAVEN”来自动生成,这样生成的代码会在target/generatord-source目录下
|
||||
-->
|
||||
<!--<javaModelGenerator targetPackage="com.forezp.entity" targetProject="MAVEN">-->
|
||||
<javaModelGenerator targetPackage="com.chaozhanggui.system.cashierservice.entity" targetProject="src/main/java">
|
||||
<javaModelGenerator targetPackage="com.chaozhanggui.system.cashierservice.entity" targetProject="src\main\java">
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
<!-- 从数据库返回的值被清理前后的空格 -->
|
||||
<property name="trimStrings" value="true" />
|
||||
</javaModelGenerator>
|
||||
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
|
||||
<sqlMapGenerator targetPackage="mapper" targetProject="src\main\resources">
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
</sqlMapGenerator>
|
||||
<javaClientGenerator type="XMLMAPPER" targetPackage="com.chaozhanggui.system.cashierservice.dao" targetProject="src/main/java">
|
||||
<javaClientGenerator type="XMLMAPPER" targetPackage="com.chaozhanggui.system.cashierservice.dao" targetProject="src\main\java">
|
||||
<property name="enableSubPackages" value="true"/>
|
||||
</javaClientGenerator>
|
||||
|
||||
|
||||
<!-- 要生成的表tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
|
||||
<!-- <table tableName="%" schema="fycashier" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" ></table>-->
|
||||
<table tableName="tb_order_child_info" domainObjectName="OrderChildInfo"
|
||||
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
|
||||
enableSelectByExample="false" selectByExampleQueryId="false" >
|
||||
</table>
|
||||
<table tableName="tb_order_child_detail" domainObjectName="OrderChildDetail"
|
||||
<table tableName="tb_shop_user_duty_pay" domainObjectName="ShopUserDutyPay"
|
||||
enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
|
||||
enableSelectByExample="false" selectByExampleQueryId="false" >
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
</context>
|
||||
</generatorConfiguration>
|
||||
Reference in New Issue
Block a user