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.scheduling.annotation.Scheduled;
|
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", Boolean.TRUE);
|
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("回调确认")
|
@Anonymous
|
public void notifyConfirm(String orderNo) {
|
try {
|
paymentService.notifyConfirm(orderNo);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@Scheduled(cron = "0 23 10 * * ? ")
|
// @Scheduled(cron = "0 37 17 * * ?")
|
public void checkWarning() {
|
paymentService.schedulePayment();
|
}
|
|
}
|