package com.pj.api.jh.api;

import cn.hutool.core.util.XmlUtil;
import cn.hutool.json.JSONUtil;
import cn.hutool.log.StaticLog;
import com.pj.api.jh.bo.JhNotifyBO;
import com.pj.api.jh.service.JhService;
import com.pj.utils.sg.AjaxJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: lzm
 * @Date: 2022/04/19/19:21
 * @Description:
 */
@RequestMapping("jh")
@RestController
@Slf4j
public class JhController {

    @Resource
    JhService jhService;

    @RequestMapping(value = "init-pay")
    public AjaxJson prePay(HttpServletRequest request) throws Exception {
        return AjaxJson.getSuccessData(jhService.initPay(request));
    }
    @RequestMapping(value = "notify")
    public String notifyResult(JhNotifyBO bo) {
        StaticLog.info("聚合支付回调:{}", JSONUtil.toJsonStr(bo));
        jhService.notifyResult(bo);
        return "SUCCESS";
    }


    @RequestMapping(value = "check-pay-result")
    public AjaxJson checkPayResult(@RequestParam String outTradeNo) {
        return AjaxJson.getSuccessData(jhService.checkPayResult(outTradeNo));
    }

    @RequestMapping(value = "refund")
    public AjaxJson refund(@RequestParam String outTradeNo) {
        return AjaxJson.getSuccess();
    }

}
