KKSU
2025-02-05 0305e98e381582c66e9b929918cf5bb46989a3c5
src/main/java/cc/mrbird/febs/pay/controller/FIUUController.java
@@ -6,16 +6,19 @@
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.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
@@ -32,10 +35,11 @@
        MallOrderInfo mallOrderInfo = ValidateEntityUtils.ensureColumnReturnEntity(orderId, MallOrderInfo::getId, mallOrderInfoMapper::selectOne, "订单不存在");
        ValidateEntityUtils.ensureEqual(mallOrderInfo.getPayResult(), "1", "订单已支付");
        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 +57,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 +107,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;
    }
}