添加快捷支付

This commit is contained in:
韩鹏辉 2024-05-20 09:59:15 +08:00
parent 776e9076da
commit cd913643a5
10 changed files with 57 additions and 25 deletions

View File

@ -112,9 +112,9 @@ public class PayController {
public Result queryQuickPayStatus(@RequestHeader("token") String token,
@RequestHeader("loginName") String loginName,
@RequestHeader("clientType") String clientType,
@RequestParam("id") Integer id
@RequestParam("orderId") String orderId
){
return payService.queryQuickPayStatus(id);
return payService.queryQuickPayStatus(orderId);
}

View File

@ -23,4 +23,6 @@ public interface TbQuickPayMapper {
int updateByPrimaryKey(TbQuickPay record);
List<TbQuickPay> selectByShopIdAndStaffId(@Param("shopId") Integer shopId,@Param("staffId") Integer staffId);
TbQuickPay selectByOrderNo(String orderNo);
}

View File

@ -108,8 +108,8 @@ public class TbQuickPay implements Serializable {
}
public TbQuickPay(Integer id, Integer staffId, Integer shopId, String orderNo, String payType, BigDecimal amount, String status, String tradeNo, Date createTime, Date updateTime) {
this.id = id;
public TbQuickPay(Integer id,Integer staffId, Integer shopId, String orderNo, String payType, BigDecimal amount, String status, String tradeNo, Date createTime, Date updateTime) {
this.id=id;
this.staffId = staffId;
this.shopId = shopId;
this.orderNo = orderNo;

View File

@ -263,7 +263,7 @@ public class PayService {
reqbody = body.toString();
}
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), reqbody, reqbody, payment.getAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, orderInfo.getOrderNo(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), reqbody, reqbody, payment.getAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
MainScanResp mainScanResp = publicResp.getObjData();
@ -369,7 +369,7 @@ public class PayService {
}
}
} else {
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), null, orderInfo.getOrderNo(), thirdApply.getAppToken());
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), tbOrderPayment.getTradeNumber(), null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
if ("000000".equals(orderstatus.getCode())) {
if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
@ -785,11 +785,13 @@ public class PayService {
// newOrderInfo.setPayOrderNo(object.getJSONObject("data").getString("refundOrderNumber"));
}
} else {
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), null, orderInfo.getOrderNo(), "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
TbOrderPayment payment= tbOrderPaymentMapper.selectByOrderId(orderId+"");
PublicResp<OrderReturnResp> publicResp = thirdPayService.returnOrder(url, thirdApply.getAppId(), newOrderInfo.getOrderNo(), payment.getTradeNumber(), null, "订单退款", newOrderInfo.getPayAmount().setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), callBack, null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(publicResp) && ObjectUtil.isNotEmpty(publicResp)) {
if ("000000".equals(publicResp.getCode())) {
if (!publicResp.getObjData().getState().equals("ING") || "SUCCESS".equals(publicResp.getObjData().getState())) {
if (!"SUCCESS".equals(publicResp.getObjData().getState())&&!publicResp.getObjData().getState().equals("ING")) {
MsgException.check(true, "退款渠道调用失败");
}
} else {
@ -855,11 +857,13 @@ public class PayService {
String orderNo = SnowFlakeUtil.generateOrderNo();
TbQuickPay tbQuickPay = new TbQuickPay(null, Integer.valueOf(staffId), Integer.valueOf(shopId), orderNo, payType, payAmount, "1", null, new Date(), null);
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());
tbQuickPayMapper.insert(tbQuickPay);
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
} else {
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(Integer.valueOf(shopId));
@ -883,17 +887,35 @@ public class PayService {
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);
}
String status = ObjectUtil.isNotEmpty(object.getJSONObject("data")) ? object.getJSONObject("data").getString("status") : null;
if (ObjectUtil.isNotNull(status) && "7".equals(status)) {
tbQuickPayMapper.insert(tbQuickPay);
return Result.success(CodeEnum.PAYING,tbQuickPay);
}
}
} else {
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), "快捷收款", "快捷收款", payAmount.setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("wechatPay") ? thirdApply.getSmallAppid() : null, authCode, tbQuickPay.getOrderNo(), thirdApply.getStoreId(), callBack, thirdApply.getAppToken());
PublicResp<MainScanResp> publicResp = thirdPayService.mainScan(url, thirdApply.getAppId(), "快捷收款", "快捷收款", payAmount.setScale(2, RoundingMode.DOWN).multiply(new BigDecimal(100)).longValue(), payType.equals("scanCode") ? thirdApply.getSmallAppid() : null, authCode, DateUtils.getSsdfTimes(), thirdApply.getStoreId(), 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())) {
tbQuickPay.setTradeNo(mainScanResp.getPayOrderId());
tbQuickPayMapper.insert(tbQuickPay);
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
}
if ("TRADE_AWAIT".equals(mainScanResp.getState())) {
tbQuickPay.setTradeNo(mainScanResp.getPayOrderId());
log.info("ddddd:{}",tbQuickPay.getTradeNo());
tbQuickPayMapper.insert(tbQuickPay);
return Result.success(CodeEnum.PAYING,tbQuickPay);
}
}
}
@ -901,15 +923,16 @@ public class PayService {
}
tbQuickPayMapper.insert(tbQuickPay);
return Result.success(CodeEnum.SUCCESS, tbQuickPay);
return Result.fail(CodeEnum.FAIL);
}
public Result queryQuickPayStatus(Integer id) {
public Result queryQuickPayStatus(String id) {
TbQuickPay tbQuickPay = tbQuickPayMapper.selectByPrimaryKey(id);
TbQuickPay tbQuickPay = tbQuickPayMapper.selectByOrderNo(id);
MsgException.checkNull(tbQuickPay, "订单信息不存在");
if (tbQuickPay.getPayType().equals("scanpay") && "1".equals(tbQuickPay.getStatus())) {
if (tbQuickPay.getPayType().equals("scanCode") && "1".equals(tbQuickPay.getStatus())) {
TbShopInfo tbShopInfo = tbShopInfoMapper.selectByPrimaryKey(tbQuickPay.getShopId());
MsgException.checkNull(tbShopInfo, "店铺信息不存在");
@ -940,7 +963,7 @@ public class PayService {
}
}
} else {
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), null, tbQuickPay.getOrderNo(), thirdApply.getAppToken());
PublicResp<OrderStatusQueryResp> orderstatus = thirdPayService.queryOrder(url, thirdApply.getAppId(), tbQuickPay.getTradeNo(), null, thirdApply.getAppToken());
if (ObjectUtil.isNotNull(orderstatus) && ObjectUtil.isNotEmpty(orderstatus)) {
if ("000000".equals(orderstatus.getCode())) {
if ("TRADE_SUCCESS".equals(orderstatus.getObjData().getState())) {
@ -949,6 +972,8 @@ public class PayService {
tbQuickPay.setUpdateTime(new Date());
tbQuickPayMapper.updateByPrimaryKeySelective(tbQuickPay);
}
}
}
}

View File

@ -50,7 +50,7 @@ public enum CodeEnum {
CARTSPEC("100021",false,"购物车商品不存在","fail"),
CARTJH("100022",false,"暂无可激活的订单","fail"),
PAYING("100015",true,"用户支付中","fail"),
PAYING("100015",false,"用户支付中","fail"),
MEMBERINSUFFICIENTFUNDS("100016",true,"会员资金不足","fail"),
PRINTMACHINENOEXSIT("100017",true,"此店铺未配置打印机","fail"),

View File

@ -23,7 +23,7 @@ public class Result {
/**
* 加密
*/
private boolean encrypt;
private boolean encrypt=false;
/**
* 图标
@ -106,7 +106,7 @@ public class Result {
Result dto = new Result();
dto.setData(data);
dto.setMsg(enums.getMsg());
dto.setEncrypt(enums.getEncrypt());
dto.setEncrypt(false);
dto.setCode(enums.getCode());
dto.setIcon(enums.getIcon());
if(enums.getEncrypt()){

View File

@ -27,6 +27,8 @@ public class ThirdPayService {
private static String trade="/api/open/query/trade";
private static String refund="/api/open/order/refund";
/**
* 被扫接口
* @param url
@ -183,7 +185,7 @@ public class ThirdPayService {
param.setSign(sign);
String reqbody = JSONUtil.toJSONString(param);
log.info("请求参数:{}", reqbody);
String response = HttpRequest.post(url.concat(trade)).body(reqbody).execute().body();
String response = HttpRequest.post(url.concat(refund)).body(reqbody).execute().body();
log.info("返回结果:{}", response);
PublicResp<OrderReturnResp> resp =JSONUtil.parseJSONStr2T(response,PublicResp.class);
resp.setObjData(JSONUtil.parseJSONStr2T(resp.getBizData(),OrderReturnResp.class));
@ -285,7 +287,6 @@ public class ThirdPayService {
if(value==null){
continue;
}
map.put(field.getName(), value);
}
return map;
@ -295,6 +296,6 @@ public class ThirdPayService {
public static void main(String[] args) {
// mainScan("https://paymentapi.sxczgkj.cn","6639fdc9fdf6f35856a23b3c", "测试支付", "测试支付", 1L, "wx212769170d2c6b2a", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405103298", "https://", "fEu7tJgqaoPCA5QevafnSHfqHtO7rWcvhyfA0ltuab7rbpgOlab7CFCmqxMIbssUvbOnFKLdQqW5xUvhzb7FoxJNMAkIf2KDzlgDl6Diw1oBq56agSAFHhgYr3bLxXXI");
new ThirdPayService(). mainScan("https://paymentapi.sxczgkj.cn","66446e41fdf63f75318ed3f8", "测试支付", "测试支付", 1L, "wxd88fffa983758a30", "131112206836873461", "CZ".concat(String.valueOf(System.currentTimeMillis())), "S2405154485", "https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay", "vHtBsHhPc3L7dXDBSKGgB5oso061xqFJcmmvfZ7DxBdZYpJHeI9a7OdqB0tzrLidPCpcWHxrKZ5AuZIPPCrTa8RwUsHS9atzzucIwspTKGcwOXINU1gUacxAKkhqTyT0");
}
}

View File

@ -1,6 +1,6 @@
spring:
profiles:
active: prod2
active: dev
server:
servlet:
context-path: /cashier-client/
@ -39,7 +39,7 @@ gateway:
client:
backUrl: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay
thirdPay:
payType: ysk
payType: fushangtong
callBack: https://cashierclient.sxczgkj.cn/cashier-client/notify/notifyPay
url: https://paymentapi.sxczgkj.cn

View File

@ -19,7 +19,7 @@
</resultMap>
<sql id="Base_Column_List">
id, type, app_id, status, pay_password, applyment_state, created_at, updated_at,
shop_id
shop_id,small_appid,store_id
</sql>
<sql id="Blob_Column_List">
app_token

View File

@ -154,4 +154,8 @@
<select id="selectByShopIdAndStaffId" resultMap="BaseResultMap">
select * from tb_quick_pay where shop_id=#{shopId} and staff_id=#{staffId} and `status`='0' order by id desc
</select>
<select id="selectByOrderNo" resultMap="BaseResultMap">
select * from tb_quick_pay where order_no=#{orderNo}
</select>
</mapper>