parent
059347bf80
commit
ab681055bd
@ -0,0 +1,24 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/dtapps/go-library/utils/gohttp"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
ApiKey string
|
||||
}
|
||||
|
||||
func (app *App) request(url string, params map[string]interface{}, method string) ([]byte, error) {
|
||||
// 公共参数
|
||||
params["apikey"] = app.ApiKey
|
||||
// 请求
|
||||
if method == http.MethodGet {
|
||||
get, err := gohttp.Get(url, params)
|
||||
return get.Body, err
|
||||
} else {
|
||||
postJson, err := gohttp.PostForm(url, params)
|
||||
return postJson.Body, err
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package dingdanxia
|
||||
|
||||
// Params 请求参数
|
||||
type Params map[string]interface{}
|
||||
|
||||
func NewParams() Params {
|
||||
p := make(Params)
|
||||
return p
|
||||
}
|
||||
|
||||
func (app *App) NewParamsWith(params ...Params) Params {
|
||||
p := make(Params)
|
||||
for _, v := range params {
|
||||
p.SetParams(v)
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
func (p Params) Set(key string, value interface{}) {
|
||||
p[key] = value
|
||||
}
|
||||
|
||||
func (p Params) SetParams(params Params) {
|
||||
for key, value := range params {
|
||||
p[key] = value
|
||||
}
|
||||
}
|
Loading…
Reference in new issue