KKSU
2025-02-05 9634244f5ad3c8493fb28e3a32d7526977cdd160
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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<String, String> 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("支付参数生成失败");
        }
    }
}