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/leshuazf/app.go

52 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package leshuazf
import (
"errors"
"go.dtapp.net/library/utils/gohttp"
"go.dtapp.net/library/utils/gomongo"
"go.dtapp.net/library/utils/gopostgresql"
"go.dtapp.net/library/utils/gorandom"
"go.dtapp.net/library/utils/gotime"
"log"
"net/http"
)
// App 乐刷
type App struct {
AgentId string // 服务商编号,由乐刷分配的接入方唯一标识,明文传输。
Environment string // 环境
KeyAgent string
Pgsql gopostgresql.App // 日志数据库
Mongo gomongo.App // 日志数据库
}
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
// 环境
if app.Environment == "test" {
url = "http://t-saas-mch.lepass.cn/" + url
} else {
url = "https://saas-mch.leshuazf.com/" + url
}
// 参数
params["agentId"] = app.AgentId // 服务商编号,由乐刷分配的接入方唯一标识,明文传输。
params["version"] = "2.0" // 目前固定值2.0
params["reqSerialNo"] = gotime.Current().SetFormat("20060102150405") + gorandom.Numeric(5) // 请求流水号(yyyyMMddHHmmssSSSXXXXX其中 XXXXX为5位顺序号,禁止使用UUID等无意义数据)
params["sign"] = app.getSign(params)
log.Println(app)
log.Println(url)
log.Println(params)
switch method {
case http.MethodGet:
// 请求
get, err := gohttp.Get(url, params)
return get.Body, err
case http.MethodPost:
postJson, err := gohttp.PostForm(url, params)
return postJson.Body, err
default:
return nil, errors.New("请求类型不支持")
}
}