You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package dingdanxia
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"go.dtapp.net/gorequest"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 请求接口
|
|
|
|
func (c *Client) request(ctx context.Context, url string, param gorequest.Params, method string) (gorequest.Response, error) {
|
|
|
|
|
|
|
|
// 公共参数
|
|
|
|
param.Set("apikey", c.GetApiKey())
|
|
|
|
|
|
|
|
// 创建请求
|
|
|
|
client := gorequest.NewHttp()
|
|
|
|
|
|
|
|
// 设置请求地址
|
|
|
|
client.SetUri(url)
|
|
|
|
|
|
|
|
// 设置方式
|
|
|
|
client.SetMethod(method)
|
|
|
|
|
|
|
|
// 设置格式
|
|
|
|
client.SetContentTypeForm()
|
|
|
|
|
|
|
|
// 设置用户代理
|
|
|
|
client.SetUserAgent(gorequest.GetRandomUserAgentSystem())
|
|
|
|
|
|
|
|
// 设置参数
|
|
|
|
client.SetParams(param)
|
|
|
|
|
|
|
|
// 发起请求
|
|
|
|
request, err := client.Request(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return gorequest.Response{}, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 记录日志
|
|
|
|
if c.gormLog.status {
|
|
|
|
go c.gormLog.client.Middleware(ctx, request)
|
|
|
|
}
|
|
|
|
|
|
|
|
return request, err
|
|
|
|
}
|