diff --git a/service/wikeyun/app.go b/service/wikeyun/app.go deleted file mode 100644 index db22b06b..00000000 --- a/service/wikeyun/app.go +++ /dev/null @@ -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 -} diff --git a/service/wikeyun/client.go b/service/wikeyun/client.go new file mode 100644 index 00000000..087c6222 --- /dev/null +++ b/service/wikeyun/client.go @@ -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 +} diff --git a/service/wikeyun/params.go b/service/wikeyun/params.go index 4d772cc8..40464713 100644 --- a/service/wikeyun/params.go +++ b/service/wikeyun/params.go @@ -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) diff --git a/service/wikeyun/pgsql.go b/service/wikeyun/pgsql.go index 95666340..810338ce 100644 --- a/service/wikeyun/pgsql.go +++ b/service/wikeyun/pgsql.go @@ -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, //【请求】链接 diff --git a/service/wikeyun/rest.oil.add_card.go b/service/wikeyun/rest.oil.add_card.go index aeabc0a0..d1c067eb 100644 --- a/service/wikeyun/rest.oil.add_card.go +++ b/service/wikeyun/rest.oil.add_card.go @@ -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 } diff --git a/service/wikeyun/rest.oil.card_info.go b/service/wikeyun/rest.oil.card_info.go index 418906cb..ecd77521 100644 --- a/service/wikeyun/rest.oil.card_info.go +++ b/service/wikeyun/rest.oil.card_info.go @@ -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 } diff --git a/service/wikeyun/rest.oil.del_card.go b/service/wikeyun/rest.oil.del_card.go index 5c985a8e..1c5f38ef 100644 --- a/service/wikeyun/rest.oil.del_card.go +++ b/service/wikeyun/rest.oil.del_card.go @@ -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 } diff --git a/service/wikeyun/rest.oil.push_order.go b/service/wikeyun/rest.oil.push_order.go index c0a2dfb1..20730b1e 100644 --- a/service/wikeyun/rest.oil.push_order.go +++ b/service/wikeyun/rest.oil.push_order.go @@ -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 } diff --git a/service/wikeyun/rest.oil.query.go b/service/wikeyun/rest.oil.query.go index c62c16b5..38ada9bd 100644 --- a/service/wikeyun/rest.oil.query.go +++ b/service/wikeyun/rest.oil.query.go @@ -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 } diff --git a/service/wikeyun/rest.oiledit_card.go b/service/wikeyun/rest.oiledit_card.go index 93d4da2b..63a8110f 100644 --- a/service/wikeyun/rest.oiledit_card.go +++ b/service/wikeyun/rest.oiledit_card.go @@ -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 } diff --git a/service/wikeyun/rest.power.add_card.go b/service/wikeyun/rest.power.add_card.go index 234f11a1..bb88f8ad 100644 --- a/service/wikeyun/rest.power.add_card.go +++ b/service/wikeyun/rest.power.add_card.go @@ -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) diff --git a/service/wikeyun/rest.power.cancel.go b/service/wikeyun/rest.power.cancel.go index dde1a220..78369f70 100644 --- a/service/wikeyun/rest.power.cancel.go +++ b/service/wikeyun/rest.power.cancel.go @@ -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) diff --git a/service/wikeyun/rest.power.card_info.go b/service/wikeyun/rest.power.card_info.go index b94c558c..1d100351 100644 --- a/service/wikeyun/rest.power.card_info.go +++ b/service/wikeyun/rest.power.card_info.go @@ -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 } diff --git a/service/wikeyun/rest.power.del_card.go b/service/wikeyun/rest.power.del_card.go index 66ccdf42..5bad668f 100644 --- a/service/wikeyun/rest.power.del_card.go +++ b/service/wikeyun/rest.power.del_card.go @@ -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) diff --git a/service/wikeyun/rest.power.edit_card.go b/service/wikeyun/rest.power.edit_card.go index 80f4a018..64816ae3 100644 --- a/service/wikeyun/rest.power.edit_card.go +++ b/service/wikeyun/rest.power.edit_card.go @@ -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 } diff --git a/service/wikeyun/rest.power.push_order.go b/service/wikeyun/rest.power.push_order.go index bfa0dc19..078172f3 100644 --- a/service/wikeyun/rest.power.push_order.go +++ b/service/wikeyun/rest.power.push_order.go @@ -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) diff --git a/service/wikeyun/rest.power.query.go b/service/wikeyun/rest.power.query.go index e98551e9..1f0c5e8b 100644 --- a/service/wikeyun/rest.power.query.go +++ b/service/wikeyun/rest.power.query.go @@ -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) diff --git a/service/wikeyun/rest.recharge.cancel.go b/service/wikeyun/rest.recharge.cancel.go index 3540cc67..b5a8bf1b 100644 --- a/service/wikeyun/rest.recharge.cancel.go +++ b/service/wikeyun/rest.recharge.cancel.go @@ -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) diff --git a/service/wikeyun/rest.recharge.mobileInfo.go b/service/wikeyun/rest.recharge.mobileInfo.go index 87e440d0..a5e2bc77 100644 --- a/service/wikeyun/rest.recharge.mobileInfo.go +++ b/service/wikeyun/rest.recharge.mobileInfo.go @@ -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) diff --git a/service/wikeyun/rest.recharge.push_order.go b/service/wikeyun/rest.recharge.push_order.go index e70817e0..d9aa1ce8 100644 --- a/service/wikeyun/rest.recharge.push_order.go +++ b/service/wikeyun/rest.recharge.push_order.go @@ -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) diff --git a/service/wikeyun/rest.recharge.query.go b/service/wikeyun/rest.recharge.query.go index 03b7b1e8..e7ba003a 100644 --- a/service/wikeyun/rest.recharge.query.go +++ b/service/wikeyun/rest.recharge.query.go @@ -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) diff --git a/service/wikeyun/rest.user.query.go b/service/wikeyun/rest.user.query.go index 552181da..d558219e 100644 --- a/service/wikeyun/rest.user.query.go +++ b/service/wikeyun/rest.user.query.go @@ -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) diff --git a/service/wikeyun/sign.go b/service/wikeyun/sign.go index 4d4a65f4..a5727ce7 100644 --- a/service/wikeyun/sign.go +++ b/service/wikeyun/sign.go @@ -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)