From 362eae9328167e3557996056f42b7bdbc92978ec Mon Sep 17 00:00:00 2001 From: KKSU <15274802129@163.com> Date: Wed, 05 Feb 2025 16:37:20 +0800 Subject: [PATCH] feat(pay): 为 FIUUController 添加 Swagger API 注解 --- src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java b/src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java index d28300e..ab90931 100644 --- a/src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java +++ b/src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java @@ -6,20 +6,25 @@ import cc.mrbird.febs.common.exception.FebsException; import cc.mrbird.febs.common.utils.ValidateEntityUtils; import cc.mrbird.febs.mall.entity.MallOrderInfo; +import cc.mrbird.febs.mall.entity.MallOrderItem; import cc.mrbird.febs.mall.mapper.MallOrderInfoMapper; import cc.mrbird.febs.pay.model.FIUUInitPayRequest; import cn.hutool.core.date.DateUtil; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.collections.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.HashMap; +import java.util.List; import java.util.Map; @Slf4j @RestController +@Api(value = "FIUUController", tags = "FIUU支付") @RequestMapping(value = "/api/fuPay") public class FIUUController { @@ -30,12 +35,13 @@ public FebsResponse initPayment(@RequestBody FIUUInitPayRequest orderRequest) { Long orderId = orderRequest.getOrderId(); MallOrderInfo mallOrderInfo = ValidateEntityUtils.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在"); - ValidateEntityUtils.ensureEqual(mallOrderInfo.getPayResult(), "1", "订单已支付"); + ValidateEntityUtils.ensureEqual("1", mallOrderInfo.getPayResult(), "订单已支付"); String amount = mallOrderInfo.getAmount().toString(); + String productNames = getProductNames(mallOrderInfo.getMemberId(), mallOrderInfo.getId()); try { String merchantId = "e2umart01"; String verifyKey = "4e3a4ed58e62ddbfacf41f6d5ec56bf2"; - String returnUrl = "https://www.mye2u.com/api/fuPay/callback"; // 支付结果回调地址 + String returnUrl = "https://api.mye2u.com/api/fuPay/callback"; // 支付结果回调地址 // 生成 vcode(MD5(amount + merchantId + orderId + verifyKey)) String vcode = DigestUtils.md5Hex( @@ -53,7 +59,7 @@ params.put("bill_name", orderRequest.getBuyerName()); params.put("bill_email", orderRequest.getBuyerEmail()); params.put("bill_mobile", orderRequest.getBuyerMobile()); - params.put("bill_desc", mallOrderInfo.getOrderNo()); + params.put("bill_desc", productNames); params.put("currency", "MYR"); // 默认 MYR params.put("vcode", vcode); params.put("returnurl", returnUrl); @@ -103,4 +109,42 @@ return new FebsResponse().fail().message("Internal Error"); } } + + /** + * 根据用户ID和订单ID获取所购买商品名称 + * @return 所含商品名称(多个以","隔开) + */ + public String getProductNames(Long memberId, Long orderId) { + MallOrderInfo mallOrderInfo = mallOrderInfoMapper.selectOrderByMemberIdAndId(memberId, orderId); + List<MallOrderItem> details = mallOrderInfo.getItems(); + if (CollectionUtils.isEmpty(details)) { + return ""; + } + StringBuffer productNameBuffer = new StringBuffer(); + Integer maxLength = 30; + for (int i = 0; i< details.size(); i++) { + MallOrderItem mallOrderItem = details.get(i); + String goodsName = mallOrderItem.getGoodsName(); + if (goodsName == null) { + continue; + } + if (i == 0 && goodsName.length() > maxLength) { + productNameBuffer.append(goodsName.substring(0, maxLength) + "..."); + break; + } + if ((productNameBuffer.length() + goodsName.length()) > maxLength) { + productNameBuffer.append("等"); + break; + } + productNameBuffer.append(goodsName + ","); + } + String productNames = productNameBuffer.toString(); + if (productNames.endsWith(",")) { + productNames = productNames.substring(0, productNames.length() - 1); + } + if (productNames.endsWith(",等")) { + productNames = productNames.substring(0, productNames.length() - 2) + "等"; + } + return productNames; + } } -- Gitblit v1.9.1