微信支付 - 构建商户订单
生活随笔
收集整理的這篇文章主要介紹了
微信支付 - 构建商户订单
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
// 微信支付成功 -> 支付中心 -> 吃貨平臺(tái)
// |-> 回調(diào)通知的url
String payReturnUrl = "http://api.z.xuexi.com/dev-api/orders/notifyMerchantOrderPaid";
/*** 接受商戶訂單信息,保存到自己的數(shù)據(jù)庫*/
@PostMapping("/createMerchantOrder")
public JSONResult createMerchantOrder(@RequestBody MerchantOrdersBO merchantOrdersBO, HttpServletRequest request, HttpServletResponse response) throws Exception {String merchantOrderId = merchantOrdersBO.getMerchantOrderId(); // 訂單idString merchantUserId = merchantOrdersBO.getMerchantUserId(); // 用戶idInteger amount = merchantOrdersBO.getAmount(); // 實(shí)際支付訂單金額Integer payMethod = merchantOrdersBO.getPayMethod(); // 支付方式String returnUrl = merchantOrdersBO.getReturnUrl(); // 支付成功后的回調(diào)地址(學(xué)生自定義)if (StringUtils.isBlank(merchantOrderId)) {return JSONResult.errorMsg("參數(shù)[orderId]不能為空");}if (StringUtils.isBlank(merchantUserId)) {return JSONResult.errorMsg("參數(shù)[userId]不能為空");}if (amount == null || amount < 1) {return JSONResult.errorMsg("參數(shù)[realPayAmount]不能為空并且不能小于1");}if (payMethod == null) {return JSONResult.errorMsg("參數(shù)[payMethod]不能為空并且不能小于1");}if (payMethod != PayMethod.WEIXIN.type && payMethod != PayMethod.ALIPAY.type) {return JSONResult.errorMsg("參數(shù)[payMethod]目前只支持微信支付或支付寶支付");}if (StringUtils.isBlank(returnUrl)) {return JSONResult.errorMsg("參數(shù)[returnUrl]不能為空");}// 保存?zhèn)鱽淼纳虘粲唵涡畔oolean isSuccess = false;try {isSuccess = paymentOrderService.createPaymentOrder(merchantOrdersBO);} catch (Exception e) {e.printStackTrace();JSONResult.errorException(e.getMessage());}if (isSuccess) {return JSONResult.ok("商戶訂單創(chuàng)建成功!");} else {return JSONResult.errorMsg("商戶訂單創(chuàng)建失敗,請重試...");}
}
public class MerchantOrdersBO {private String merchantOrderId; // 商戶訂單號private String merchantUserId; // 商戶方的發(fā)起用戶的用戶主鍵idprivate Integer amount; // 實(shí)際支付總金額(包含商戶所支付的訂單費(fèi)郵費(fèi)總額)private Integer payMethod; // 支付方式 1:微信 2:支付寶private String returnUrl; // 支付成功后的回調(diào)地址(學(xué)生自定義)public String getMerchantOrderId() {return merchantOrderId;}public void setMerchantOrderId(String merchantOrderId) {this.merchantOrderId = merchantOrderId;}public String getMerchantUserId() {return merchantUserId;}public void setMerchantUserId(String merchantUserId) {this.merchantUserId = merchantUserId;}public Integer getAmount() {return amount;}public void setAmount(Integer amount) {this.amount = amount;}public Integer getPayMethod() {return payMethod;}public void setPayMethod(Integer payMethod) {this.payMethod = payMethod;}public String getReturnUrl() {return returnUrl;}public void setReturnUrl(String returnUrl) {this.returnUrl = returnUrl;}
}
@Transactional(propagation=Propagation.REQUIRED)
@Override
public boolean createPaymentOrder(MerchantOrdersBO merchantOrdersBO) {String id = sid.nextShort();Orders paymentOrder = new Orders();BeanUtils.copyProperties(merchantOrdersBO, paymentOrder);paymentOrder.setId(id);paymentOrder.setPayStatus(PaymentStatus.WAIT_PAY.type);paymentOrder.setComeFrom("吃貨");paymentOrder.setIsDelete(YesOrNo.NO.type);paymentOrder.setCreatedTime(new Date());int result = ordersMapper.insert(paymentOrder);return result == 1 ? true : false;
}
// 1. 創(chuàng)建訂單
OrderVO orderVO = orderService.createOrder(submitOrderBO);
public class MerchantOrdersVO {private String merchantOrderId; // 商戶訂單號private String merchantUserId; // 商戶方的發(fā)起用戶的用戶主鍵idprivate Integer amount; // 實(shí)際支付總金額(包含商戶所支付的訂單費(fèi)郵費(fèi)總額)private Integer payMethod; // 支付方式 1:微信 2:支付寶private String returnUrl; // 支付成功后的回調(diào)地址(學(xué)生自定義)public String getMerchantOrderId() {return merchantOrderId;}public void setMerchantOrderId(String merchantOrderId) {this.merchantOrderId = merchantOrderId;}public String getMerchantUserId() {return merchantUserId;}public void setMerchantUserId(String merchantUserId) {this.merchantUserId = merchantUserId;}public Integer getAmount() {return amount;}public void setAmount(Integer amount) {this.amount = amount;}public Integer getPayMethod() {return payMethod;}public void setPayMethod(Integer payMethod) {this.payMethod = payMethod;}public String getReturnUrl() {return returnUrl;}public void setReturnUrl(String returnUrl) {this.returnUrl = returnUrl;}
}
public class OrderVO {private String orderId;private MerchantOrdersVO merchantOrdersVO;public String getOrderId() {return orderId;}public void setOrderId(String orderId) {this.orderId = orderId;}public MerchantOrdersVO getMerchantOrdersVO() {return merchantOrdersVO;}public void setMerchantOrdersVO(MerchantOrdersVO merchantOrdersVO) {this.merchantOrdersVO = merchantOrdersVO;}
}
// 4. 構(gòu)建商戶訂單,用于傳給支付中心
MerchantOrdersVO merchantOrdersVO = new MerchantOrdersVO();
merchantOrdersVO.setMerchantOrderId(orderId);
merchantOrdersVO.setMerchantUserId(userId);
merchantOrdersVO.setAmount(realPayAmount + postAmount);
merchantOrdersVO.setPayMethod(payMethod);// 5. 構(gòu)建自定義訂單vo
OrderVO orderVO = new OrderVO();
orderVO.setOrderId(orderId);
orderVO.setMerchantOrdersVO(merchantOrdersVO);
?
總結(jié)
以上是生活随笔為你收集整理的微信支付 - 构建商户订单的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信支付 - 构建商户端支付成功的回调接
- 下一篇: 微信支付 - 提供支付中心商户订单查询