xiaoyong931011
2022-09-24 777d32df7c722eec53b8efd5863a64ee12e8a67e
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
57
58
59
60
61
62
package cc.mrbird.febs.pay.controller;
 
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.pay.properties.AliPayProperties;
import cc.mrbird.febs.pay.service.IPayService;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.ijpay.alipay.AliPayApi;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2021-09-27
 **/
@Slf4j
@RestController
@RequestMapping(value = "/api/pay")
public class PayCallBackController {
 
    @Autowired
    private IPayService payService;
 
    @Resource
    private AliPayProperties aliPayProperties;
 
    @RequestMapping("/aliCallBack")
    public String aliPayCallBack(HttpServletRequest request){
        log.info("进入支付宝回调");
        Map<String, String> params = AliPayApi.toMap(request);
 
        boolean verifyResult = false;
        try {
            verifyResult = AlipaySignature.verifyV1(params, aliPayProperties.getPublicKey(), "UTF-8", "RSA2");
        } catch (AlipayApiException e) {
            log.info("=验证失败=:{}", params);
            return "failure";
        }
 
        if (verifyResult) {
            if ("TRADE_SUCCESS".equals(params.get("trade_status")) || "TRADE_FINISHED".equals(params.get("trade_status"))) {
                payService.aliCallback(params);
                return "success";
            } else {
                log.info("支付失败:{}", params);
                return "failure";
            }
        } else {
            log.info("验证失败:{}", params);
            return "failure";
        }
    }
}