core

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2023 License: MulanPSL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse 校验请求是否成功

func SelectHeaderContentType

func SelectHeaderContentType(contentTypes []string) string

func SortUrlValues

func SortUrlValues(param url.Values) string

func UnMarshalResponse

func UnMarshalResponse(httpResp *http.Response, resp interface{}) error

UnMarshalResponse 将回包组织成结构化数据

Types

type APIError

type APIError struct {
	StatusCode int         // 应答报文的 HTTP 状态码
	Header     http.Header // 应答报文的 Header 信息
	Body       string      // 应答报文的 Body 原文
	Code       string      `json:"code"`             // 应答报文的 Body 解析后错误信息,仅不符合预期/发生系统错误时存在
	Message    string      `json:"message"`          // 应答报文 Body 解析后的文字说明信息,仅不符合预期/发生系统错误时存在
	Detail     interface{} `json:"detail,omitempty"` // 应答报文 Body 解析后的详细信息,仅不符合预期/发生系统错误时存在
}

func (*APIError) Error

func (e *APIError) Error() string

Error 输出 APIError

type APIResult

type APIResult struct {
	// 本次请求所使用的 HTTPRequest
	Request *http.Request
	// 本次请求所获得到 HTTPResponse
	Response *http.Response
}

APIResult 支付API请求结果

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(ctx context.Context, opts ...ClientOption) (client *Client, err error)

NewClient 初始化一个支付客户端

func (*Client) ConstructFromData

func (client *Client) ConstructFromData(ctx context.Context, apiName consts.ApiName, reqBody string) (err error, forData string)

func (*Client) GetApiPayServer

func (client *Client) GetApiPayServer() string

func (*Client) GetAppCode

func (client *Client) GetAppCode() string

func (*Client) Post

func (client *Client) Post(ctx context.Context, requestURL string, requestBody interface{}) (*APIResult, error)

Post 向支付中心发送一个 HTTP Post请求

func (*Client) Request

func (client *Client) Request(
	ctx context.Context,
	method, requestPath string,
	headerParams http.Header,
	queryParams url.Values,
	postBody interface{},
	contentType string,
) (result *APIResult, err error)

Request 向 payCenter 发送请求

相比于 Get / Post / Put / Patch / Delete 方法, 本方法可以设置更多内容 特别地,如果需要为当前请求设置 Header, 可以使用本方法

func (*Client) Sign

func (client *Client) Sign(ctx context.Context, message string) (result *auth.SignatureResult, err error)

Sign 使用 signer 对字符串进行签名

type ClientOption

type ClientOption interface {
	Apply(*DialSettings) error
}

type DialSettings

type DialSettings struct {
	HTTPClient *http.Client   // 自定义所使用 HTTPClient 实例
	Signer     auth.Signer    // 签名器
	Validator  auth.Validator // 应答包签名校验器

	ApiServerUrl string // 服务器地址

	AppCode string // 应用编号
}

func (*DialSettings) Validate

func (ds *DialSettings) Validate() error

Validate 校验请求配置是否有效

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL