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.
go-library/service/wechatunion/app.go

36 lines
875 B

3 years ago
package wechatunion
import (
"encoding/json"
"go.uber.org/zap"
3 years ago
"gopkg.in/dtapps/go-library.v3/utils/gohttp"
3 years ago
"net/http"
)
type App struct {
AppId string // 小程序唯一凭证,即 AppID
AppSecret string // 小程序唯一凭证密钥,即 AppSecret
AccessToken string // 接口调用凭证
ZapLog *zap.Logger // 日志服务
3 years ago
}
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
if method == http.MethodGet {
get, err := gohttp.Get(url, params)
// 日志
if app.ZapLog != nil {
app.ZapLog.Sugar().Info(get)
}
3 years ago
return get.Body, err
} else {
// 请求参数
paramsStr, err := json.Marshal(params)
postJson, err := gohttp.PostJson(url, paramsStr)
// 日志
if app.ZapLog != nil {
app.ZapLog.Sugar().Info(postJson)
}
3 years ago
return postJson.Body, err
}
}