- update
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details

master v1.0.1
李光春 2 years ago
parent 4657ccd8c8
commit 81117223d2

@ -8,7 +8,7 @@ func NewParams() Params {
return p
}
func (app *App) NewParamsWith(params ...Params) Params {
func (c *Client) NewParamsWith(params ...Params) Params {
p := make(Params)
for _, v := range params {
p.SetParams(v)

@ -8,8 +8,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, //【请求】链接

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -1,10 +1,10 @@
package wikeyun
// 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
}

@ -34,12 +34,12 @@ func NewRestPowerAddCardResult(result RestPowerAddCardResponse, body []byte, htt
// RestPowerAddCard 添加电费充值卡
// https://open.wikeyun.cn/#/apiDocument/9/document/326
func (app *App) RestPowerAddCard(notMustParams ...Params) *RestPowerAddCardResult {
func (c *Client) RestPowerAddCard(notMustParams ...Params) *RestPowerAddCardResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params.Set("store_id", app.storeId) // 店铺ID
params := c.NewParamsWith(notMustParams...)
params.Set("store_id", c.config.StoreId) // 店铺ID
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/addCard", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/addCard", params)
// 定义
var response RestPowerAddCardResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -24,13 +24,13 @@ func NewRestPowerCancelResult(result RestPowerCancelResponse, body []byte, http
// RestPowerCancel 电费订单取消
// https://open.wikeyun.cn/#/apiDocument/9/document/323
func (app *App) RestPowerCancel(orderNumber string) *RestPowerCancelResult {
func (c *Client) RestPowerCancel(orderNumber string) *RestPowerCancelResult {
// 参数
param := NewParams()
param.Set("order_number", orderNumber) // 取消的单号,多个用英文逗号隔开
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/cancel", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/cancel", params)
// 定义
var response RestPowerCancelResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -2,10 +2,10 @@ package wikeyun
// PowerCardInfo 电费充值卡详情
// https://open.wikeyun.cn/#/apiDocument/9/document/333
func (app *App) PowerCardInfo(notMustParams ...Params) (body []byte, err error) {
func (c *Client) PowerCardInfo(notMustParams ...Params) (body []byte, err error) {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/cardInfo", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/cardInfo", params)
return request.ResponseBody, err
}

@ -25,13 +25,13 @@ func NewRestPowerDelCardResult(result RestPowerDelCardResponse, body []byte, htt
// RestPowerDelCard 删除电费充值卡
// https://open.wikeyun.cn/#/apiDocument/9/document/330
func (app *App) RestPowerDelCard(cardId string) *RestPowerDelCardResult {
func (c *Client) RestPowerDelCard(cardId string) *RestPowerDelCardResult {
// 参数
param := NewParams()
param.Set("card_id", cardId)
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/delCard", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/delCard", params)
// 定义
var response RestPowerDelCardResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -2,10 +2,10 @@ package wikeyun
// RestPowerEditCard 编辑电费充值卡
// https://open.wikeyun.cn/#/apiDocument/9/document/329
func (app *App) RestPowerEditCard(notMustParams ...Params) (body []byte, err error) {
func (c *Client) RestPowerEditCard(notMustParams ...Params) (body []byte, err error) {
// 参数
params := app.NewParamsWith(notMustParams...)
params := c.NewParamsWith(notMustParams...)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/editCard", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/editCard", params)
return request.ResponseBody, err
}

@ -27,12 +27,12 @@ func NewRestPowerPushOrderResult(result RestPowerPushOrderResponse, body []byte,
// RestPowerPushOrder 电费充值API
// https://open.wikeyun.cn/#/apiDocument/9/document/311
func (app *App) RestPowerPushOrder(notMustParams ...Params) *RestPowerPushOrderResult {
func (c *Client) RestPowerPushOrder(notMustParams ...Params) *RestPowerPushOrderResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params.Set("store_id", app.storeId) // 店铺ID
params := c.NewParamsWith(notMustParams...)
params.Set("store_id", c.config.StoreId) // 店铺ID
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/pushOrder", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/pushOrder", params)
// 定义
var response RestPowerPushOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -34,13 +34,13 @@ func NewRestPowerQueryResult(result RestPowerQueryResponse, body []byte, http go
// RestPowerQuery 电费订单查询
// https://open.wikeyun.cn/#/apiDocument/9/document/313
func (app *App) RestPowerQuery(orderNumber string) *RestPowerQueryResult {
func (c *Client) RestPowerQuery(orderNumber string) *RestPowerQueryResult {
// 参数
param := NewParams()
param.Set("order_number", orderNumber) // 平台单号
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Power/query", params)
request, err := c.request("https://router.wikeyun.cn/rest/Power/query", params)
// 定义
var response RestPowerQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -24,13 +24,13 @@ func NewRestRechargeCancelResult(result RestRechargeCancelResponse, body []byte,
// RestRechargeCancel 话费订单取消
// https://open.wikeyun.cn/#/apiDocument/9/document/300
func (app *App) RestRechargeCancel(orderNumber string) *RestRechargeCancelResult {
func (c *Client) RestRechargeCancel(orderNumber string) *RestRechargeCancelResult {
// 参数
param := NewParams()
param.Set("order_number", orderNumber) // 取消的单号,多个用英文逗号隔开
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Recharge/cancel", params)
request, err := c.request("https://router.wikeyun.cn/rest/Recharge/cancel", params)
// 定义
var response RestRechargeCancelResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -44,13 +44,13 @@ func NewRestRechargeMobileInfoResult(result RestRechargeMobileInfoResponse, body
// RestRechargeMobileInfo 查询手机归属地信息以及是否携号转网
// https://open.wikeyun.cn/#/apiDocument/9/document/374
func (app *App) RestRechargeMobileInfo(orderNumber string) *RestRechargeMobileInfoResult {
func (c *Client) RestRechargeMobileInfo(orderNumber string) *RestRechargeMobileInfoResult {
// 参数
param := NewParams()
param.Set("order_number", orderNumber) // 平台单号
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Recharge/mobileInfo", params)
request, err := c.request("https://router.wikeyun.cn/rest/Recharge/mobileInfo", params)
// 定义
var response RestRechargeMobileInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -26,12 +26,12 @@ func NewRestRechargePushOrderResult(result RestRechargePushOrderResponse, body [
// RestRechargePushOrder 话费充值推送
// https://open.wikeyun.cn/#/apiDocument/9/document/298
func (app *App) RestRechargePushOrder(notMustParams ...Params) *RestRechargePushOrderResult {
func (c *Client) RestRechargePushOrder(notMustParams ...Params) *RestRechargePushOrderResult {
// 参数
params := app.NewParamsWith(notMustParams...)
params.Set("store_id", app.storeId) // 店铺ID
params := c.NewParamsWith(notMustParams...)
params.Set("store_id", c.config.StoreId) // 店铺ID
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Recharge/pushOrder", params)
request, err := c.request("https://router.wikeyun.cn/rest/Recharge/pushOrder", params)
// 定义
var response RestRechargePushOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -34,13 +34,13 @@ func NewRestRechargeQueryResult(result RestRechargeQueryResponse, body []byte, h
// RestRechargeQuery 话费订单查询
// https://open.wikeyun.cn/#/apiDocument/9/document/299
func (app *App) RestRechargeQuery(orderNumber string) *RestRechargeQueryResult {
func (c *Client) RestRechargeQuery(orderNumber string) *RestRechargeQueryResult {
// 参数
param := NewParams()
param.Set("order_number", orderNumber) // 平台订单号
params := app.NewParamsWith(param)
params := c.NewParamsWith(param)
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/Recharge/query", params)
request, err := c.request("https://router.wikeyun.cn/rest/Recharge/query", params)
// 定义
var response RestRechargeQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -29,9 +29,9 @@ func NewRestUserQueryResult(result RestUserQueryResponse, body []byte, http gore
// RestUserQuery 用户信息
// https://open.wikeyun.cn/#/apiDocument/10/document/336
func (app *App) RestUserQuery() *RestUserQueryResult {
func (c *Client) RestUserQuery() *RestUserQueryResult {
// 请求
request, err := app.request("https://router.wikeyun.cn/rest/User/query", map[string]interface{}{})
request, err := c.request("https://router.wikeyun.cn/rest/User/query", map[string]interface{}{})
// 定义
var response RestUserQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -20,39 +20,39 @@ type respSign struct {
}
// 签名
func (app *App) sign(params map[string]interface{}) respSign {
func (c *Client) sign(params map[string]interface{}) respSign {
// 默认参数
v := "1.0"
format := "json"
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
params["v"] = v // 客户端接口版本目前是1.0
params["format"] = format // 默认json
params["app_key"] = app.appKey // 应用唯一表示
params["client"] = app.clientIp // 客户端请求ip
params["timestamp"] = timestamp // unix时间戳秒单位
params["v"] = v // 客户端接口版本目前是1.0
params["format"] = format // 默认json
params["app_key"] = c.config.AppKey // 应用唯一表示
params["client"] = c.clientIp // 客户端请求ip
params["timestamp"] = timestamp // unix时间戳秒单位
// 排序所有的 key
var keys []string
for key := range params {
keys = append(keys, key)
}
sort.Strings(keys)
signStr := app.appSecret
signStr := c.config.AppSecret
for _, key := range keys {
signStr += key + getString(params[key])
}
signStr += app.appSecret
signStr += c.config.AppSecret
return respSign{
AppKey: app.appKey,
AppKey: c.config.AppKey,
Timestamp: timestamp,
Client: app.clientIp,
Client: c.clientIp,
V: v,
Format: format,
Sign: app.createSign(signStr),
Sign: c.createSign(signStr),
}
}
// 签名
func (app *App) createSign(signStr string) string {
func (c *Client) createSign(signStr string) string {
h := md5.New()
h.Write([]byte(signStr))
cipherStr := h.Sum(nil)

@ -1,3 +1,3 @@
package wikeyun
const Version = "1.0.0"
const Version = "1.0.1"

@ -8,49 +8,55 @@ import (
"gorm.io/gorm"
)
type App struct {
storeId int // 店铺ID
appKey int // key
appSecret string // secret
clientIp string // Ip
pgsql *gorm.DB // pgsql数据库
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
}
// 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,
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" {
app.clientIp = xip
c.clientIp = xip
}
return app
return c
}
// 请求接口
func (app *App) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
func (c *Client) request(url string, params map[string]interface{}) (resp gorequest.Response, err error) {
// 签名
sign := app.sign(params)
sign := c.sign(params)
// 创建请求
client := app.client
client := c.client
// 设置请求地址
client.SetUri(fmt.Sprintf("%s?app_key=%d&timestamp=%s&client=%s&format=%s&v=%s&sign=%s", url, app.appKey, sign.Timestamp, sign.Client, sign.Format, sign.V, sign.Sign))
client.SetUri(fmt.Sprintf("%s?app_key=%d&timestamp=%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()
@ -65,8 +71,8 @@ func (app *App) request(url string, params map[string]interface{}) (resp goreque
}
// 日志
if app.logStatus == true {
go app.postgresqlLog(request)
if c.logStatus == true {
go c.postgresqlLog(request)
}
return request, err

Loading…
Cancel
Save