parent
e07a968ad0
commit
24bf959656
@ -1,73 +0,0 @@
|
|||||||
package wikeyun
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"go.dtapp.net/library/utils/goip"
|
|
||||||
"go.dtapp.net/library/utils/golog"
|
|
||||||
"go.dtapp.net/library/utils/gorequest"
|
|
||||||
"gorm.io/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
type App struct {
|
|
||||||
storeId int // 店铺ID
|
|
||||||
appKey int // key
|
|
||||||
appSecret string // secret
|
|
||||||
clientIp string // Ip
|
|
||||||
pgsql *gorm.DB // pgsql数据库
|
|
||||||
client *gorequest.App // 请求客户端
|
|
||||||
log *golog.Api // 日志服务
|
|
||||||
logTableName string // 日志表名
|
|
||||||
logStatus bool // 日志状态
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewApp 创建实例
|
|
||||||
func NewApp(storeId, appKey int, appSecret string, pgsql *gorm.DB) *App {
|
|
||||||
app := &App{storeId: storeId, appKey: appKey, appSecret: appSecret}
|
|
||||||
app.client = gorequest.NewHttp()
|
|
||||||
if pgsql != nil {
|
|
||||||
app.pgsql = pgsql
|
|
||||||
app.logStatus = true
|
|
||||||
app.logTableName = "wikeyun"
|
|
||||||
app.log = golog.NewApi(&golog.ApiConfig{
|
|
||||||
Db: pgsql,
|
|
||||||
TableName: app.logTableName,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
xip := goip.GetOutsideIp()
|
|
||||||
if xip != "" && xip != "0.0.0.0" {
|
|
||||||
app.clientIp = xip
|
|
||||||
}
|
|
||||||
return app
|
|
||||||
}
|
|
||||||
|
|
||||||
// 请求接口
|
|
||||||
func (app *App) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
|
|
||||||
|
|
||||||
// 签名
|
|
||||||
sign := app.sign(params)
|
|
||||||
|
|
||||||
// 创建请求
|
|
||||||
client := app.client
|
|
||||||
|
|
||||||
// 设置请求地址
|
|
||||||
client.SetUri(fmt.Sprintf("%s?app_key=%d×tamp=%s&client=%s&format=%s&v=%s&sign=%s", url, app.appKey, sign.Timestamp, sign.Client, sign.Format, sign.V, sign.Sign))
|
|
||||||
|
|
||||||
// 设置FORM格式
|
|
||||||
client.SetContentTypeForm()
|
|
||||||
|
|
||||||
// 设置参数
|
|
||||||
client.SetParams(params)
|
|
||||||
|
|
||||||
// 发起请求
|
|
||||||
request, err := client.Post()
|
|
||||||
if err != nil {
|
|
||||||
return gorequest.Response{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// 日志
|
|
||||||
if app.logStatus == true {
|
|
||||||
go app.postgresqlLog(request)
|
|
||||||
}
|
|
||||||
|
|
||||||
return request, err
|
|
||||||
}
|
|
@ -0,0 +1,79 @@
|
|||||||
|
package wikeyun
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"go.dtapp.net/library/utils/goip"
|
||||||
|
"go.dtapp.net/library/utils/golog"
|
||||||
|
"go.dtapp.net/library/utils/gorequest"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ConfigClient struct {
|
||||||
|
StoreId int // 店铺ID
|
||||||
|
AppKey int // key
|
||||||
|
AppSecret string // secret
|
||||||
|
PgsqlDb *gorm.DB // pgsql数据库
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
client *gorequest.App // 请求客户端
|
||||||
|
clientIp string // Ip
|
||||||
|
log *golog.Api // 日志服务
|
||||||
|
logTableName string // 日志表名
|
||||||
|
logStatus bool // 日志状态
|
||||||
|
config *ConfigClient
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClient(config *ConfigClient) *Client {
|
||||||
|
|
||||||
|
c := &Client{config: config}
|
||||||
|
c.config = config
|
||||||
|
|
||||||
|
c.client = gorequest.NewHttp()
|
||||||
|
if c.config.PgsqlDb != nil {
|
||||||
|
c.logStatus = true
|
||||||
|
c.logTableName = "wikeyun"
|
||||||
|
c.log = golog.NewApi(&golog.ApiConfig{
|
||||||
|
Db: c.config.PgsqlDb,
|
||||||
|
TableName: c.logTableName,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
xip := goip.GetOutsideIp()
|
||||||
|
if xip != "" && xip != "0.0.0.0" {
|
||||||
|
c.clientIp = xip
|
||||||
|
}
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// 请求接口
|
||||||
|
func (c *Client) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
|
||||||
|
|
||||||
|
// 签名
|
||||||
|
sign := c.sign(params)
|
||||||
|
|
||||||
|
// 创建请求
|
||||||
|
client := c.client
|
||||||
|
|
||||||
|
// 设置请求地址
|
||||||
|
client.SetUri(fmt.Sprintf("%s?app_key=%d×tamp=%s&client=%s&format=%s&v=%s&sign=%s", url, c.config.AppKey, sign.Timestamp, sign.Client, sign.Format, sign.V, sign.Sign))
|
||||||
|
|
||||||
|
// 设置FORM格式
|
||||||
|
client.SetContentTypeForm()
|
||||||
|
|
||||||
|
// 设置参数
|
||||||
|
client.SetParams(params)
|
||||||
|
|
||||||
|
// 发起请求
|
||||||
|
request, err := client.Post()
|
||||||
|
if err != nil {
|
||||||
|
return gorequest.Response{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
if c.logStatus == true {
|
||||||
|
go c.postgresqlLog(request)
|
||||||
|
}
|
||||||
|
|
||||||
|
return request, err
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilCardAdd 添加充值卡
|
// RestOilCardAdd 添加充值卡
|
||||||
func (app *App) RestOilCardAdd(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilCardAdd(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/addCard", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/addCard", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilCardInfo 油卡详情
|
// RestOilCardInfo 油卡详情
|
||||||
func (app *App) RestOilCardInfo(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilCardInfo(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/cardInfo", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/cardInfo", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilCardDel 油卡删除
|
// RestOilCardDel 油卡删除
|
||||||
func (app *App) RestOilCardDel(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilCardDel(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/delCard", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/delCard", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilOrderPush 充值下单
|
// RestOilOrderPush 充值下单
|
||||||
func (app *App) RestOilOrderPush(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilOrderPush(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/pushOrder", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/pushOrder", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilOrderQuery 订单查询
|
// RestOilOrderQuery 订单查询
|
||||||
func (app *App) RestOilOrderQuery(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilOrderQuery(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/query", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/query", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package wikeyun
|
package wikeyun
|
||||||
|
|
||||||
// RestOilCardEdit 编辑充值卡
|
// RestOilCardEdit 编辑充值卡
|
||||||
func (app *App) RestOilCardEdit(notMustParams ...Params) (body []byte, err error) {
|
func (c *Client) RestOilCardEdit(notMustParams ...Params) (body []byte, err error) {
|
||||||
// 参数
|
// 参数
|
||||||
params := app.NewParamsWith(notMustParams...)
|
params := c.NewParamsWith(notMustParams...)
|
||||||
// 请求
|
// 请求
|
||||||
request, err := app.request("https://router.wikeyun.cn/rest/Oil/editCard", params)
|
request, err := c.request("https://router.wikeyun.cn/rest/Oil/editCard", params)
|
||||||
return request.ResponseBody, err
|
return request.ResponseBody, err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue