日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

微信支付 - 构建商户订单

發布時間:2024/4/13 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信支付 - 构建商户订单 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
// 微信支付成功 -> 支付中心 -> 吃貨平臺 // |-> 回調通知的url String payReturnUrl = "http://api.z.xuexi.com/dev-api/orders/notifyMerchantOrderPaid"; /*** 接受商戶訂單信息,保存到自己的數據庫*/ @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(); // 實際支付訂單金額Integer payMethod = merchantOrdersBO.getPayMethod(); // 支付方式String returnUrl = merchantOrdersBO.getReturnUrl(); // 支付成功后的回調地址(學生自定義)if (StringUtils.isBlank(merchantOrderId)) {return JSONResult.errorMsg("參數[orderId]不能為空");}if (StringUtils.isBlank(merchantUserId)) {return JSONResult.errorMsg("參數[userId]不能為空");}if (amount == null || amount < 1) {return JSONResult.errorMsg("參數[realPayAmount]不能為空并且不能小于1");}if (payMethod == null) {return JSONResult.errorMsg("參數[payMethod]不能為空并且不能小于1");}if (payMethod != PayMethod.WEIXIN.type && payMethod != PayMethod.ALIPAY.type) {return JSONResult.errorMsg("參數[payMethod]目前只支持微信支付或支付寶支付");}if (StringUtils.isBlank(returnUrl)) {return JSONResult.errorMsg("參數[returnUrl]不能為空");}// 保存傳來的商戶訂單信息boolean isSuccess = false;try {isSuccess = paymentOrderService.createPaymentOrder(merchantOrdersBO);} catch (Exception e) {e.printStackTrace();JSONResult.errorException(e.getMessage());}if (isSuccess) {return JSONResult.ok("商戶訂單創建成功!");} else {return JSONResult.errorMsg("商戶訂單創建失敗,請重試...");} } public class MerchantOrdersBO {private String merchantOrderId; // 商戶訂單號private String merchantUserId; // 商戶方的發起用戶的用戶主鍵idprivate Integer amount; // 實際支付總金額(包含商戶所支付的訂單費郵費總額)private Integer payMethod; // 支付方式 1:微信 2:支付寶private String returnUrl; // 支付成功后的回調地址(學生自定義)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. 創建訂單 OrderVO orderVO = orderService.createOrder(submitOrderBO); public class MerchantOrdersVO {private String merchantOrderId; // 商戶訂單號private String merchantUserId; // 商戶方的發起用戶的用戶主鍵idprivate Integer amount; // 實際支付總金額(包含商戶所支付的訂單費郵費總額)private Integer payMethod; // 支付方式 1:微信 2:支付寶private String returnUrl; // 支付成功后的回調地址(學生自定義)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. 構建商戶訂單,用于傳給支付中心 MerchantOrdersVO merchantOrdersVO = new MerchantOrdersVO(); merchantOrdersVO.setMerchantOrderId(orderId); merchantOrdersVO.setMerchantUserId(userId); merchantOrdersVO.setAmount(realPayAmount + postAmount); merchantOrdersVO.setPayMethod(payMethod);// 5. 構建自定義訂單vo OrderVO orderVO = new OrderVO(); orderVO.setOrderId(orderId); orderVO.setMerchantOrdersVO(merchantOrdersVO);

?

總結

以上是生活随笔為你收集整理的微信支付 - 构建商户订单的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。