教育训练处考试制证系统后端
“djh”
2025-03-10 ea219f4389c52d0bac442c7a351767160c9814c5
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
63
64
65
package com.gkhy.exam.pay.controller;
 
import com.alibaba.fastjson2.JSONObject;
import com.gkhy.exam.pay.service.PaymentService;
import com.ruoyi.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.Base64;
import java.util.Map;
 
@Api(tags = {"支付Api"})
@RestController
@RequestMapping({"/paymentApi"})
@Slf4j
public class PaymentApiController {
 
    @Resource
    private PaymentService paymentService;
 
    @ApiOperation(value = "支付Api-回调", notes = "支付Api-回调")
    @PostMapping({"/callBack"})
    @Anonymous
    public JSONObject add(@RequestParam Map<String, Object> callBackParam) {
        String jsonStr = baseToString(callBackParam.get("reqdata").toString());
        JSONObject jsonObject = JSONObject.parseObject(jsonStr);
        log.info("财政回调接收到参数=" + jsonObject.toString());
        try {
            JSONObject jsonObject1 = new JSONObject();
            String orderNo = jsonObject.getString("orderNo");
            String status = jsonObject.getString("status");
            if ("1".equals(status)) {
                paymentService.paySuccess(orderNo, jsonObject.getDate("payTime"));
            }
            jsonObject1.put("orderNo", orderNo);
            jsonObject1.put("status", "success");
            return jsonObject1;
        } catch (Exception e) {
            log.info("财政回调处理订单发生错误");
            e.printStackTrace();
            return null;
        }
    }
 
 
    public String baseToString(String baseString) {
        byte[] byteArray = Base64.getDecoder().decode(baseString);
        String decodedString = new String(byteArray);
        return decodedString;
    }
 
 
    @GetMapping({"/confirm"})
    @ApiOperation("回调确认")
    public void notifyConfirm(String orderNo) {
        try {
            paymentService.notifyConfirm(orderNo);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}