- update ejiaofei

master
李光春 2 years ago
parent bf43a718d3
commit 3b2b68e1f4

@ -1,76 +0,0 @@
package ejiaofei
import (
"fmt"
"go.dtapp.net/library/utils/golog"
"go.dtapp.net/library/utils/gomd5"
"go.dtapp.net/library/utils/gomongo"
"go.dtapp.net/library/utils/gorequest"
"gorm.io/gorm"
)
type App struct {
userId string
pwd string
key string
signStr string
mongo *gomongo.Client // 日志数据库
pgsql *gorm.DB // pgsql数据库
client *gorequest.App // 请求客户端
log *golog.Api // 日志服务
logTableName string // 日志表名
logStatus bool // 日志状态
}
func NewApp(userId string, pwd string, key string, pgsql *gorm.DB) *App {
app := &App{userId: userId, pwd: pwd, key: key}
app.client = gorequest.NewHttp()
if pgsql != nil {
app.pgsql = pgsql
app.logStatus = true
app.logTableName = "ejiaofei"
app.log = golog.NewApi(&golog.ApiConfig{
Db: pgsql,
TableName: app.logTableName,
})
}
return app
}
func (app *App) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
// 公共参数
params["userid"] = app.userId
params["pwd"] = app.pwd
// 签名
params["userkey"] = gomd5.ToUpper(fmt.Sprintf("%s%s", app.signStr, app.key))
// 创建请求
client := app.client
// 设置请求地址
client.SetUri(url)
// 设置方式
client.SetMethod(method)
// 设置格式
client.SetContentTypeForm()
// 设置参数
client.SetParams(params)
// 发起请求
request, err := client.Request()
if err != nil {
return gorequest.Response{}, err
}
// 日志
if app.logStatus == true {
go app.postgresqlLog(request)
}
return request, err
}

@ -28,15 +28,15 @@ func NewCheckCostResult(result CheckCostResponse, body []byte, http gorequest.Re
}
// CheckCost 会员订单成本价查询接口
func (app *App) CheckCost(orderId string) *CheckCostResult {
func (c *Client) CheckCost(orderId string) *CheckCostResult {
// 参数
param := NewParams()
param := gorequest.NewParams()
param.Set("orderid", orderId)
params := app.NewParamsWith(param)
params := gorequest.NewParamsWith(param)
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", app.userId, app.pwd, orderId)
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", c.getUserId(), c.getPwd(), orderId)
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/checkCost.do", params, http.MethodGet)
request, err := c.request(apiUrl+"/checkCost.do", params, http.MethodGet)
// 定义
var response CheckCostResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -36,18 +36,18 @@ func NewChOngZhiJkOrdersResult(result ChOngZhiJkOrdersResponse, body []byte, htt
// orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
// face 充值面值 以元为单位包含10、20、30、50、100、200、300、500 移动联通电信
// account 手机号码 需要充值的手机号码
func (app *App) ChOngZhiJkOrders(orderID string, face int, account string) *ChOngZhiJkOrdersResult {
func (c *Client) ChOngZhiJkOrders(orderID string, face int, account string) *ChOngZhiJkOrdersResult {
// 参数
param := NewParams()
param := gorequest.NewParams()
param.Set("orderid", orderID)
param.Set("face", face)
param.Set("account", account)
param.Set("amount", 1)
params := app.NewParamsWith(param)
params := gorequest.NewParamsWith(param)
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%vface%vaccount%vamount1", app.userId, app.pwd, orderID, face, account)
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%vface%vaccount%vamount1", c.getUserId(), c.getPwd(), orderID, face, account)
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/chongzhi_jkorders.do", params, http.MethodGet)
request, err := c.request(apiUrl+"/chongzhi_jkorders.do", params, http.MethodGet)
// 定义
var response ChOngZhiJkOrdersResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -0,0 +1,44 @@
package ejiaofei
import (
"go.dtapp.net/library/utils/golog"
"go.dtapp.net/library/utils/gomongo"
"go.dtapp.net/library/utils/gorequest"
"gorm.io/gorm"
)
type ConfigClient struct {
UserId string
Pwd string
Key string
MongoDb *gomongo.Client // 日志数据库
PgsqlDb *gorm.DB // pgsql数据库
}
type Client struct {
client *gorequest.App // 请求客户端
log *golog.ApiClient // 日志服务
logStatus bool // 日志状态
signStr string // 加密信息
config *ConfigClient // 配置
}
func NewClient(config *ConfigClient) (*Client, error) {
var err error
c := &Client{config: config}
c.client = gorequest.NewHttp()
if c.config.PgsqlDb != nil {
c.logStatus = true
c.log, err = golog.NewApiClient(&golog.ConfigApiClient{
Db: c.config.PgsqlDb,
TableName: logTable,
})
if err != nil {
return nil, err
}
}
return c, err
}

@ -0,0 +1,9 @@
package ejiaofei
const (
apiUrl = "http://api.ejiaofei.net:11140"
)
const (
logTable = "ejiaofei"
)

@ -0,0 +1,13 @@
package ejiaofei
func (c *Client) getUserId() string {
return c.config.UserId
}
func (c *Client) getPwd() string {
return c.config.Pwd
}
func (c *Client) getKey() string {
return c.config.Key
}

@ -46,13 +46,13 @@ func NewGprsChOngZhiAdvanceResult(result GprsChOngZhiAdvanceResponse, body []byt
}
// GprsChOngZhiAdvance 流量充值接口
func (app *App) GprsChOngZhiAdvance(notMustParams ...Params) *GprsChOngZhiAdvanceResult {
func (c *Client) GprsChOngZhiAdvance(notMustParams ...gorequest.Params) *GprsChOngZhiAdvanceResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := gorequest.NewParamsWith(notMustParams...)
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%vaccount%vgprs%varea%veffecttime%vvalidity%vtimes%v", app.userId, app.pwd, params["orderid"], params["account"], params["gprs"], params["area"], params["effecttime"], params["validity"], params["times"])
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%vaccount%vgprs%varea%veffecttime%vvalidity%vtimes%v", c.getUserId(), c.getPwd(), params["orderid"], params["account"], params["gprs"], params["area"], params["effecttime"], params["validity"], params["times"])
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/gprsChongzhiAdvance.do", params, http.MethodGet)
request, err := c.request(apiUrl+"/gprsChongzhiAdvance.do", params, http.MethodGet)
// 定义
var response GprsChOngZhiAdvanceResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -9,8 +9,8 @@ import (
)
// 记录日志
func (app *App) postgresqlLog(request gorequest.Response) {
app.log.Record(golog.ApiPostgresqlLog{
func (c *Client) postgresqlLog(request gorequest.Response) {
c.log.Record(golog.ApiPostgresqlLog{
RequestTime: golog.TimeString{Time: request.RequestTime}, //【请求】时间
RequestUri: request.RequestUri, //【请求】链接
RequestUrl: gorequest.UriParse(request.RequestUri).Url, //【请求】链接

@ -26,11 +26,11 @@ func NewMoneyJkUserResult(result MoneyJkUserResponse, body []byte, http goreques
}
// MoneyJkUser 用户余额查询
func (app *App) MoneyJkUser() *MoneyJkUserResult {
func (c *Client) MoneyJkUser() *MoneyJkUserResult {
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%v", app.userId, app.pwd)
c.signStr = fmt.Sprintf("userid%vpwd%v", c.getUserId(), c.getPwd())
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/money_jkuser.do", map[string]interface{}{}, http.MethodGet)
request, err := c.request(apiUrl+"/money_jkuser.do", map[string]interface{}{}, http.MethodGet)
// 定义
var response MoneyJkUserResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,27 +0,0 @@
package ejiaofei
// 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
}
}

@ -34,15 +34,15 @@ func NewQueryJkOrdersResult(result QueryJkOrdersResponse, body []byte, http gore
// QueryJkOrders 通用查询接口
// orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
func (app *App) QueryJkOrders(orderId string) *QueryJkOrdersResult {
func (c *Client) QueryJkOrders(orderId string) *QueryJkOrdersResult {
// 参数
param := NewParams()
param := gorequest.NewParams()
param.Set("orderid", orderId)
params := app.NewParamsWith(param)
params := gorequest.NewParamsWith(param)
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", app.userId, app.pwd, orderId)
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", c.getUserId(), c.getPwd(), orderId)
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/query_jkorders.do", params, http.MethodGet)
request, err := c.request(apiUrl+"/query_jkorders.do", params, http.MethodGet)
// 定义
var response QueryJkOrdersResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -24,11 +24,11 @@ func NewQueryTxProductResult(result QueryTxProductResponse, body []byte, http go
}
// QueryTxProduct 可充值腾讯产品查询
func (app *App) QueryTxProduct() *QueryTxProductResult {
func (c *Client) QueryTxProduct() *QueryTxProductResult {
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%v", app.userId, app.pwd)
c.signStr = fmt.Sprintf("userid%vpwd%v", c.getUserId(), c.getPwd())
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/queryTXproduct.do", map[string]interface{}{}, http.MethodGet)
request, err := c.request(apiUrl+"/queryTXproduct.do", map[string]interface{}{}, http.MethodGet)
// 定义
var response QueryTxProductResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -0,0 +1,45 @@
package ejiaofei
import (
"fmt"
"go.dtapp.net/library/utils/gomd5"
"go.dtapp.net/library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (resp gorequest.Response, err error) {
// 公共参数
params["userid"] = c.getUserId()
params["pwd"] = c.getPwd()
// 签名
params["userkey"] = gomd5.ToUpper(fmt.Sprintf("%s%s", c.signStr, c.getKey()))
// 创建请求
client := c.client
// 设置请求地址
client.SetUri(url)
// 设置方式
client.SetMethod(method)
// 设置格式
client.SetContentTypeForm()
// 设置参数
client.SetParams(params)
// 发起请求
request, err := client.Request()
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.logStatus == true {
go c.postgresqlLog(request)
}
return request, err
}

@ -42,13 +42,13 @@ func NewTxChOngZhiResult(result TxChOngZhiResponse, body []byte, http gorequest.
}
// TxChOngZhi 流量充值接口
func (app *App) TxChOngZhi(notMustParams ...Params) *TxChOngZhiResult {
func (c *Client) TxChOngZhi(notMustParams ...gorequest.Params) *TxChOngZhiResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params := gorequest.NewParamsWith(notMustParams...)
// 签名
app.signStr = fmt.Sprintf("userid%vpwd%vorderid%vaccount%vproductid%vamount%vip%vtimes%v", app.userId, app.pwd, params["orderid"], params["account"], params["productid"], params["amount"], params["ip"], params["times"])
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%vaccount%vproductid%vamount%vip%vtimes%v", c.getUserId(), c.getPwd(), params["orderid"], params["account"], params["productid"], params["amount"], params["ip"], params["times"])
// 请求
request, err := app.request("http://api.ejiaofei.net:11140/txchongzhi.do", params, http.MethodGet)
request, err := c.request(apiUrl+"/txchongzhi.do", params, http.MethodGet)
// 定义
var response TxChOngZhiResponse
err = xml.Unmarshal(request.ResponseBody, &response)

Loading…
Cancel
Save