package cc.mrbird.febs.pay.controller; import cc.mrbird.febs.common.entity.FebsResponse; import cc.mrbird.febs.pay.model.FIUUOrderRequest; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; @Slf4j @RestController @RequestMapping(value = "/api/fuPay") @RequiredArgsConstructor @Api(value = "FIUUPayController", tags = "FIUU支付") public class FIUUPayController { @PostMapping("/initPayment") public FebsResponse initPayment(@RequestBody FIUUOrderRequest orderRequest) { try { String merchantId = "YOUR_MERCHANT_ID"; String verifyKey = "YOUR_VERIFY_KEY"; String returnUrl = "https://your-app.com/payment/callback"; // 支付结果回调地址 // 生成 vcode(MD5(amount + merchantId + orderId + verifyKey)) String vcode = DigestUtils.md5Hex( orderRequest.getAmount() + merchantId + orderRequest.getOrderId() + verifyKey ); // 返回支付参数 Map params = new HashMap<>(); params.put("merchant_id", merchantId); params.put("orderid", orderRequest.getOrderId()); params.put("amount", orderRequest.getAmount()); params.put("bill_name", orderRequest.getBuyerName()); params.put("bill_email", orderRequest.getBuyerEmail()); params.put("bill_mobile", orderRequest.getBuyerMobile()); params.put("bill_desc", orderRequest.getDescription()); params.put("currency", "MYR"); // 默认 MYR params.put("vcode", vcode); params.put("returnurl", returnUrl); return new FebsResponse().success().data(params); } catch (Exception e) { return new FebsResponse().fail().data("支付参数生成失败"); } } }