/**
 * 核心服务接口sdk（golang版）
 *
 * @desc 啪啪运动 核心服务接口sdk
 * ---------------------------------------------------------------------
 * @author		unphp <unphp@qq.com>
 * @date		2020-07-04
 * @copyright	core-utils
 * ---------------------------------------------------------------------
 */

package pposRequest

import (
	"errors"
	"net/url"
)

//NewCfgWxCertGet 微信退款证书获取
func (that *PPOSClient) NewCfgWxCertGet() *CfgWxCertGetRequest {
	return &CfgWxCertGetRequest{
		Request: Request{
			Client:     that,
			apiAddress: "/cfg/wxCert/get",
		},
	}
}

type CfgWxCertGetResponse struct {
	AppId     int64  `json:"app_id"`     //应用ID
	CompanyId int64  `json:"company_id"` //公司ID
	WxpayCert string `json:"wxpay_cert"` //证书
	WxpayKey  string `json:"wxpay_key"`  //证书密钥
}

//CfgWxCertGetRequest 请求
type CfgWxCertGetRequest struct {
	Request
}

//Params ...
func (that *CfgWxCertGetRequest) Params() (url.Values, error) {
	that.initParams()
	_params := that.params
	return _params, nil
}

//Do ...
func (that *CfgWxCertGetRequest) Do() (*CfgWxCertGetResponse, error) {
	//
	_data, _err := that.Client.GetData(that.apiAddress, that)
	if _err != nil {
		return nil, _err
	}
	//
	_sliceData, _ok := _data.(map[string]interface{})
	if !_ok {
		return nil, errors.New(that.apiAddress + "请求响应格式不正确")
	}
	_rs := new(CfgWxCertGetResponse)
	if _err := that.ParseResponeMp(_rs, _sliceData); _err != nil {
		return nil, errors.New(that.apiAddress + "请求响应格式化异常:" + _err.Error())
	}
	//
	return _rs, nil
}
