package com.keao.edu.thirdparty.yqpay;

import feign.Logger;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.support.SpringEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


import java.util.Map;

@FeignClient(value = "YqPayFeignService",url = "https://qyfquery.95epay.com",configuration = YqPayFeignService.FormSupportConfig.class)
public interface YqPayFeignService {

    @PostMapping(name = "订单查询", value = "/query/trade/tradeQuery",
            consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE},
            produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}
    )
    Msg orderQuery(RsqMsg rsqMsg);

    @RequestMapping(name = "用户信息查询", value = "/query/account/queryAccount", method = RequestMethod.POST)
    String queryAccount(@RequestParam Map<String, Object> map);

    @RequestMapping(name = "对账查询", value = "/query/bill/billQuery", method = RequestMethod.POST)
    String billQuery(@RequestParam Map<String, Object> map);


    class FormSupportConfig {


        @Autowired
        private ObjectFactory<HttpMessageConverters> messageConverters;
        // new一个form编码器，实现支持form表单提交
        @Bean
        public Encoder feignFormEncoder() {
            return new SpringFormEncoder(new SpringEncoder(messageConverters));
        }
        // 开启Feign的日志
        @Bean
        public Logger.Level logger() {
            return Logger.Level.FULL;
        }
    }

    }