package com.jeequan.jeepay.pay.ctrl.channel;

import com.jeequan.jeepay.core.ctrls.AbstractCtrl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Enumeration;

/**
* 渠道侧自定义业务ctrl
 * 盛付通
*
* @author terrfly
*
* @date 2022/10/21 14:29
*/
@Slf4j
@Controller
@RequestMapping("/api/channelbiz/shengpay")
public class ShengpayBizController extends AbstractCtrl {

    /** 修改费率通知地址 **/
    @RequestMapping("/modifyRateNotify")
    public ResponseEntity modifyRateNotify() throws Exception {

        String logPrefix = "接收盛付通费率修改通知";

        try {

            log.info("{}， method: {}", logPrefix, request.getMethod());
            log.info("{}， QUERYSTRING: {}", logPrefix, request.getQueryString());

            // 查询到所有的header
            Enumeration<String> list = request.getHeaderNames();
            while (list.hasMoreElements()){
                String key = list.nextElement();
                log.info("{}， Header: {}={}", logPrefix, key, request.getHeader(key));
            }

            log.info("{}， reqParamJSON: {}", logPrefix, getReqParamJSON());
        } catch (Exception e) {
            log.error("{}", logPrefix, e);
        }

        HttpHeaders httpHeaders = new HttpHeaders();
        httpHeaders.setContentType(MediaType.TEXT_HTML);
        return new ResponseEntity("SUCCESS", httpHeaders, HttpStatus.OK);
    }

}
