From 03fdbc9793f6180af6f2d9025f41de8169d3ff3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=85=89=E6=98=A5?= Date: Mon, 15 Aug 2022 17:36:52 +0800 Subject: [PATCH] - add ApiProductRechargeParamsCache --- api.product.recharge-params.cache.go | 45 ++++++++++++++++++++++++++++ client.go | 2 +- const.go | 2 +- request.go | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 api.product.recharge-params.cache.go diff --git a/api.product.recharge-params.cache.go b/api.product.recharge-params.cache.go new file mode 100644 index 0000000..1bfcfeb --- /dev/null +++ b/api.product.recharge-params.cache.go @@ -0,0 +1,45 @@ +package kashangwl + +import ( + "context" + "encoding/json" + "fmt" + "go.dtapp.net/gorequest" + "net/http" +) + +type ApiProductRechargeParamsCacheResponse struct { + Code int `json:"code"` + Message string `json:"message"` + Data struct { + PurchaseTips string `json:"purchase_tips"` + } `json:"data"` + Time int `json:"time"` + TraceId string `json:"trace_id"` +} + +type ApiProductRechargeParamsCacheResult struct { + Result ApiProductRechargeParamsCacheResponse // 结果 + Body []byte // 内容 + Http gorequest.Response // 请求 + Err error // 错误 +} + +func newApiProductRechargeParamsCacheResult(result ApiProductRechargeParamsCacheResponse, body []byte, http gorequest.Response, err error) *ApiProductRechargeParamsCacheResult { + return &ApiProductRechargeParamsCacheResult{Result: result, Body: body, Http: http, Err: err} +} + +// ApiProductRechargeParamsCache 接口说明 +// 获取商品的充值参数(仅支持充值类商品) +// http://doc.cqmeihu.cn/sales/ProductParams.html +func (c *Client) ApiProductRechargeParamsCache(ctx context.Context, productId int64) *ApiProductRechargeParamsCacheResult { + // 参数 + params := gorequest.NewParams() + params.Set("product_id", productId) + // 请求 + request, err := c.requestCache(ctx, fmt.Sprintf("%s/%d/goods_info_params/%d", apiUrlCache, c.GetCustomerId(), productId), params, http.MethodGet) + // 定义 + var response ApiProductRechargeParamsCacheResponse + err = json.Unmarshal(request.ResponseBody, &response) + return newApiProductRechargeParamsCacheResult(response, request.ResponseBody, request, err) +} diff --git a/client.go b/client.go index 18d5fd2..866739c 100644 --- a/client.go +++ b/client.go @@ -28,7 +28,7 @@ func NewClient(config *ConfigClient) (*Client, error) { c.requestClient = gorequest.NewHttp() - if c.config.GormClient.Db != nil { + if c.config.GormClient != nil && c.config.GormClient.Db != nil { c.logClient, err = golog.NewApiClient(&golog.ApiClientConfig{ GormClient: c.config.GormClient, TableName: logTable, diff --git a/const.go b/const.go index e03c399..fce5872 100644 --- a/const.go +++ b/const.go @@ -17,4 +17,4 @@ const ( logTable = "kashangwl" ) -const Version = "1.0.6" +const Version = "1.0.7" diff --git a/request.go b/request.go index dbae1c7..a8aea5e 100644 --- a/request.go +++ b/request.go @@ -65,7 +65,7 @@ func (c *Client) requestCache(ctx context.Context, url string, params map[string } // 日志 - if c.config.GormClient.Db != nil { + if c.config.GormClient != nil && c.config.GormClient.Db != nil { go c.logClient.GormMiddleware(ctx, request, Version) }