parent
0e39809c43
commit
a0e6bcb331
@ -0,0 +1,35 @@
|
||||
package qq
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
)
|
||||
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
key string
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
c := &Client{}
|
||||
|
||||
c.config.key = config.Key
|
||||
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package qq
|
||||
|
||||
const (
|
||||
apiUrl = "https://apis.map.qq.com"
|
||||
)
|
||||
|
||||
const (
|
||||
LogTable = "qq"
|
||||
)
|
@ -0,0 +1,11 @@
|
||||
package qq
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetKey() string {
|
||||
return c.config.key
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package qq
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
)
|
||||
|
||||
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
|
||||
|
||||
// 创建请求
|
||||
client := c.requestClient
|
||||
|
||||
// 设置请求地址
|
||||
client.SetUri(url)
|
||||
|
||||
// 设置方式
|
||||
client.SetMethod(method)
|
||||
|
||||
// 设置格式
|
||||
client.SetContentTypeJson()
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 传入SDk版本
|
||||
client.AfferentSdkUserVersion(go_library.Version())
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Request(ctx)
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
if c.log.status {
|
||||
go c.log.client.Middleware(ctx, request, go_library.Version())
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
Loading…
Reference in new issue