diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/cache/DataCache.java b/src/main/java/com/chaozhanggui/system/cashierservice/cache/DataCache.java index daedf69..f697aa7 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/cache/DataCache.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/cache/DataCache.java @@ -40,7 +40,7 @@ public class DataCache { @Bean public void init(){ - log.info("加载店铺信息"); +// log.info("加载店铺信息"); shopInfo(); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java index ed7b41b..0f4961c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/PayController.java @@ -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); + } + + + + + /** * 会员扫码支付 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java index 5960a16..c953ed5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/PayService.java @@ -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 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 map = BeanUtil.transBean2Map(scanPayReq); - scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + Map map = BeanUtil.transBean2Map(scanPayReq); + scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); - ResponseEntity 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 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 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 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 map = BeanUtil.transBean2Map(scanPayReq); + scanPayReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + ResponseEntity 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 map = BeanUtil.transBean2Map(tradeQueryReq); + tradeQueryReq.setSign(MD5Util.encrypt(map, thirdApply.getAppToken(), true)); + ResponseEntity 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 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(); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java new file mode 100644 index 0000000..142bfdf --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/constants/SignTypeEnum.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java new file mode 100644 index 0000000..502d535 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/MainScanReq.java @@ -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; + } + + +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java new file mode 100644 index 0000000..9bdbbb8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderRefundReq.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java new file mode 100644 index 0000000..d39dba3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderReturnQueryReq.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java new file mode 100644 index 0000000..c47a593 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/OrderStatusQueryReq.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java new file mode 100644 index 0000000..855ceac --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/PublicParam.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java new file mode 100644 index 0000000..0e6eab3 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/req/WxScanPayReq.java @@ -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; + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java new file mode 100644 index 0000000..46a1636 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/MainScanResp.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java new file mode 100644 index 0000000..b481b15 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OderReturnQueyResp.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java new file mode 100644 index 0000000..1a930f8 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderReturnResp.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java new file mode 100644 index 0000000..0afc145 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/OrderStatusQueryResp.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java new file mode 100644 index 0000000..d911c21 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/PublicResp.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.thirdpay.resp; + +import lombok.Data; + +import java.io.Serializable; +@Data +public class PublicResp implements Serializable { + + private String code; + + private String msg; + + private String sign; + + private String bizData; + + private T objData; + + private String signType; + + private String timestamp; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java new file mode 100644 index 0000000..af8b012 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/resp/WxScanPayResp.java @@ -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; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java new file mode 100644 index 0000000..2c0f05b --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/thirdpay/service/ThirdPayService.java @@ -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 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 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 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 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 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 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 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 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 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 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 sortFields(Object obj) throws IllegalAccessException { + + LinkedHashMap 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"); + } +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java index 9f33248..5dfd79f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JSONUtil.java @@ -3,6 +3,7 @@ package com.chaozhanggui.system.cashierservice.util; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; import com.alibaba.fastjson.serializer.SerializeConfig; import com.alibaba.fastjson.serializer.SerializerFeature; @@ -117,7 +118,7 @@ public class JSONUtil { } /** - * 字符串转为JSON对象,注意数组类型会抛异常[{name:\"Stone\"}] + * 字符串转为JSON对象,注意数组类型会抛异常[{name:"Stone"}] * (假设json字符串多了某个字段,可能是新加上去的,显然转换成JSONObject时会有这个字段,因为JSONObject就相当于map) * * @param jsonStr 传入的JSON字串 @@ -133,7 +134,7 @@ public class JSONUtil { } /** - * 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:\"Stone\"} + * 字符串转为JSON数组,注意对象类型,非数组的会抛异常{name:"Stone"} * (假设json字符串多了某个字段,可能是新加上去的,显然转换成JSONArray时,其元素会有这个字段,因为JSONArray的元素JSONObject就相当于map) * * @param jsonStr 传入的JSON字串 @@ -165,6 +166,14 @@ public class JSONUtil { throw new RuntimeException("Invalid jsonStr,parse error:" + jsonStr, e); } } + public static T jsonStrToObject(String jsonStr, Class clazz) { + Object obj = JSONArray.parseObject(jsonStr, clazz); + return (T) obj; + } + + public static T jsonstrtoObject(String str,TypeReference tTypeReference ){ + return JSON.parseObject(str, tTypeReference); + } /** * 字符串转为某个类的列表 diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/util/JsonUtils.java b/src/main/java/com/chaozhanggui/system/cashierservice/util/JsonUtils.java new file mode 100644 index 0000000..124e140 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/util/JsonUtils.java @@ -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 the type parameter + * @param obj the obj + * @return the string + */ + public static 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 the type parameter + * @param str the str + * @param clazz the clazz + * @return the t + */ + public static T str2Obj(String str, Class 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 the type parameter + * @param str the str + * @param typeReference the type reference + * @return the t + */ + public static T str2Obj(String str, TypeReference 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 the type parameter + * @param fromValue the from value + * @param toValueType the to value type + * @return the t + */ + public static T convertValue(@NonNull Object fromValue, @NonNull Class toValueType) { + try { + return objectMapper.convertValue(fromValue, toValueType); + } catch (Exception e) { + log.error("str2Obj fail"); + return null; + } + } + + /** + * 对象互转泛型模式 + * + * @param the type parameter + * @param fromValue the from value + * @param toValueTypeRef the to value type ref + * @return the t + */ + public static T convertValue(@NonNull Object fromValue, @NonNull TypeReference toValueTypeRef) { + try { + return objectMapper.convertValue(fromValue, toValueTypeRef); + } catch (Exception e) { + log.error("str2Obj fail"); + return null; + } + } +} \ No newline at end of file diff --git a/src/main/resources/application-hph.yml b/src/main/resources/application-hph.yml index 3eec8e5..05a59d3 100644 --- a/src/main/resources/application-hph.yml +++ b/src/main/resources/application-hph.yml @@ -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访问密码(默认为空) diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 71de68e..a34de52 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -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 + + diff --git a/src/main/resources/generator-mapper/generatorConfig.xml b/src/main/resources/generator-mapper/generatorConfig.xml index 1650fcb..2a849d4 100644 --- a/src/main/resources/generator-mapper/generatorConfig.xml +++ b/src/main/resources/generator-mapper/generatorConfig.xml @@ -6,7 +6,7 @@ - + @@ -19,8 +19,8 @@ - + @@ -52,7 +52,7 @@ -