- add context

master
李光春 2 years ago
parent dc5bfdaee0
commit 86f481910b

@ -1,5 +1,5 @@
package go_library
func Version() string {
return "v1.0.50"
return "1.0.51"
}

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -39,11 +40,11 @@ func newJdJyOrderDetailsResult(result JdJyOrderDetailsResponse, body []byte, htt
}
// JdJyOrderDetails 【官方不维护】 京佣订单
func (c *Client) JdJyOrderDetails(notMustParams ...gorequest.Params) *JdJyOrderDetailsResult {
func (c *Client) JdJyOrderDetails(ctx context.Context, notMustParams ...gorequest.Params) *JdJyOrderDetailsResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/jd/jy_order_details", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/jd/jy_order_details", params, http.MethodPost)
// 定义
var response JdJyOrderDetailsResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -8,11 +9,11 @@ import (
// JdOrderDetails2 【官方不维护】 京东联盟订单行查询
// https://www.dingdanxia.com/doc/180/94
func (c *Client) JdOrderDetails2(notMustParams ...gorequest.Params) *JdJyOrderDetailsResult {
func (c *Client) JdOrderDetails2(ctx context.Context, notMustParams ...gorequest.Params) *JdJyOrderDetailsResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/jd/order_details2", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/jd/order_details2", params, http.MethodPost)
// 定义
var response JdJyOrderDetailsResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,9 +1,13 @@
package dingdanxia
import "github.com/dtapps/go-library/utils/gorequest"
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
// 请求接口
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 公共参数
params["apikey"] = c.config.ApiKey
@ -24,17 +28,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -49,13 +50,13 @@ func newWaiMaiMeituanOrderIdResult(result WaiMaiMeituanOrderIdResponse, body []b
// WaiMaiMeituanOrderId 美团联盟外卖/闪购/优选/酒店订单查询API订单号版
// https://www.dingdanxia.com/doc/179/173
func (c *Client) WaiMaiMeituanOrderId(orderId string) *WaiMaiMeituanOrderIdResult {
func (c *Client) WaiMaiMeituanOrderId(ctx context.Context, orderId string) *WaiMaiMeituanOrderIdResult {
// 参数
param := gorequest.NewParams()
param.Set("order_id", orderId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/waimai/meituan_orderid", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/waimai/meituan_orderid", params, http.MethodPost)
// 定义
var response WaiMaiMeituanOrderIdResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -40,11 +41,11 @@ func newWaiMaiMeituanOrdersResult(result WaiMaiMeituanOrdersResponse, body []byt
// WaiMaiMeituanOrders 美团联盟外卖/闪购/优选/酒店订单查询API
// https://www.dingdanxia.com/doc/176/173
func (c *Client) WaiMaiMeituanOrders(notMustParams ...gorequest.Params) *WaiMaiMeituanOrdersResult {
func (c *Client) WaiMaiMeituanOrders(ctx context.Context, notMustParams ...gorequest.Params) *WaiMaiMeituanOrdersResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/waimai/meituan_orders", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/waimai/meituan_orders", params, http.MethodPost)
// 定义
var response WaiMaiMeituanOrdersResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -37,7 +38,7 @@ func newWaiMaiMeituanPrivilegeResult(result WaiMaiMeituanPrivilegeResponse, body
// WaiMaiMeituanPrivilege 美团外卖CPS推广API接口
// https://www.dingdanxia.com/doc/174/173
func (c *Client) WaiMaiMeituanPrivilege(sid string, generateWeApp, qrcode bool) *WaiMaiMeituanPrivilegeResult {
func (c *Client) WaiMaiMeituanPrivilege(ctx context.Context, sid string, generateWeApp, qrcode bool) *WaiMaiMeituanPrivilegeResult {
// 参数
param := gorequest.NewParams()
param.Set("sid", sid)
@ -45,7 +46,7 @@ func (c *Client) WaiMaiMeituanPrivilege(sid string, generateWeApp, qrcode bool)
param.Set("qrcode", qrcode)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/waimai/meituan_privilege", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/waimai/meituan_privilege", params, http.MethodPost)
// 定义
var response WaiMaiMeituanPrivilegeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package dingdanxia
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -36,7 +37,7 @@ func newWaiMaiMeituanSgPrivilegeResult(result WaiMaiMeituanSgPrivilegeResponse,
// WaiMaiMeituanSgPrivilege 美团闪购CPS推广API接口
// https://www.dingdanxia.com/doc/195/173
func (c *Client) WaiMaiMeituanSgPrivilege(sid string, generateWeApp, qrcode bool) *WaiMaiMeituanSgPrivilegeResult {
func (c *Client) WaiMaiMeituanSgPrivilege(ctx context.Context, sid string, generateWeApp, qrcode bool) *WaiMaiMeituanSgPrivilegeResult {
// 参数
param := gorequest.NewParams()
param.Set("sid", sid)
@ -44,7 +45,7 @@ func (c *Client) WaiMaiMeituanSgPrivilege(sid string, generateWeApp, qrcode bool
param.Set("qrcode", qrcode)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/waimai/meituan_sg_privilege", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/waimai/meituan_sg_privilege", params, http.MethodPost)
// 定义
var response WaiMaiMeituanSgPrivilegeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,8 +1,12 @@
package dingtalk
import "github.com/dtapps/go-library/utils/gorequest"
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
@ -20,17 +24,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package dingtalk
import (
"context"
"encoding/json"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -26,13 +27,13 @@ func newRobotSendResult(result RobotSendResponse, body []byte, http gorequest.Re
// RobotSend 自定义机器人
// https://open.dingtalk.com/document/group/custom-robot-access
func (c *Client) RobotSend(notMustParams ...gorequest.Params) *RobotSendResult {
func (c *Client) RobotSend(ctx context.Context, notMustParams ...gorequest.Params) *RobotSendResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 时间
timestamp := time.Now().UnixNano() / 1e6
// 请求
request, err := c.request(apiUrl+fmt.Sprintf("/robot/send?access_token=%s&timestamp=%d&sign=%s", c.config.AccessToken, timestamp, c.sign(timestamp)), params, http.MethodPost)
request, err := c.request(ctx, apiUrl+fmt.Sprintf("/robot/send?access_token=%s&timestamp=%d&sign=%s", c.config.AccessToken, timestamp, c.sign(timestamp)), params, http.MethodPost)
// 定义
var response RobotSendResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package douyin
import (
"context"
"encoding/json"
"errors"
"github.com/dtapps/go-library/utils/gorequest"
@ -184,7 +185,7 @@ func newAnalysisResult(result AnalysisResponse, body []byte, http gorequest.Resp
}
// Analysis 抖音解析
func (c *Client) Analysis(content string) *AnalysisResult {
func (c *Client) Analysis(ctx context.Context, content string) *AnalysisResult {
// 提取url
var url string
@ -209,7 +210,7 @@ func (c *Client) Analysis(content string) *AnalysisResult {
}
// 请求
request, err := c.request("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+itemIds[0], map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, "https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+itemIds[0], map[string]interface{}{}, http.MethodGet)
// 定义
var response AnalysisResponse

@ -1,10 +1,12 @@
package douyin
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
@ -25,17 +27,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -34,13 +35,13 @@ func newIotApiQueryOrderedPkgInfoResult(result IotApiQueryOrderedPkgInfoResponse
// IotApiQueryOrderedPkgInfo 查询流量卡已订购流量包
// https://www.showdoc.com.cn/916774523755909/5092045889939625
func (c *Client) IotApiQueryOrderedPkgInfo(simId string) *IotApiQueryOrderedPkgInfoResult {
func (c *Client) IotApiQueryOrderedPkgInfo(ctx context.Context, simId string) *IotApiQueryOrderedPkgInfoResult {
// 参数
param := gorequest.NewParams()
param.Set("simId", simId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/queryOrderedPkgInfo", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/queryOrderedPkgInfo", params, http.MethodPost)
// 定义
var response IotApiQueryOrderedPkgInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -40,14 +41,14 @@ func newIotApiQuerySimPkgInfoResult(result IotApiQuerySimPkgInfoResponse, body [
// IotApiQuerySimPkgInfo 流量卡可用流量包查询
// https://www.showdoc.com.cn/916774523755909/4880284631482420
func (c *Client) IotApiQuerySimPkgInfo(simId string, sd int) *IotApiQuerySimPkgInfoResult {
func (c *Client) IotApiQuerySimPkgInfo(ctx context.Context, simId string, sd int) *IotApiQuerySimPkgInfoResult {
// 参数
param := gorequest.NewParams()
param.Set("simId", simId)
param.Set("sd", sd)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/querySimPkgInfo", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/querySimPkgInfo", params, http.MethodPost)
// 定义
var response IotApiQuerySimPkgInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -39,9 +40,9 @@ func newIotApiQueryUserPkgInfoResult(result IotApiQueryUserPkgInfoResponse, body
// IotApiQueryUserPkgInfo 账户可用流量包查询
// https://www.showdoc.com.cn/916774523755909/4850094776758927
func (c *Client) IotApiQueryUserPkgInfo() *IotApiQueryUserPkgInfoResult {
func (c *Client) IotApiQueryUserPkgInfo(ctx context.Context) *IotApiQueryUserPkgInfoResult {
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/queryUserPkgInfo", map[string]interface{}{}, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/queryUserPkgInfo", map[string]interface{}{}, http.MethodPost)
// 定义
var response IotApiQueryUserPkgInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -24,11 +25,11 @@ func newIotApiRechargeSimResult(result IotApiRechargeSimResponse, body []byte, h
// IotApiRechargeSim 单卡流量充值
// https://www.showdoc.com.cn/916774523755909/4880284631482420
func (c *Client) IotApiRechargeSim(notMustParams ...gorequest.Params) *IotApiRechargeSimResult {
func (c *Client) IotApiRechargeSim(ctx context.Context, notMustParams ...gorequest.Params) *IotApiRechargeSimResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/rechargeSim", params, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/rechargeSim", params, http.MethodPost)
// 定义
var response IotApiRechargeSimResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -29,9 +30,9 @@ func newIotApiGetAllSimTypeResult(result IotApiGetAllSimTypeResponse, body []byt
// IotApiGetAllSimType 卡类型列表查询
// https://www.showdoc.com.cn/916774523755909/4858492092033167
func (c *Client) IotApiGetAllSimType() *IotApiGetAllSimTypeResult {
func (c *Client) IotApiGetAllSimType(ctx context.Context) *IotApiGetAllSimTypeResult {
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/getAllSimType", map[string]interface{}{}, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/getAllSimType", map[string]interface{}{}, http.MethodPost)
// 定义
var response IotApiGetAllSimTypeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package eastiot
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -27,9 +28,9 @@ func newIotApiQueryUserBalanceResult(result IotApiQueryUserBalanceResponse, body
// IotApiQueryUserBalance 余额查询
// https://www.showdoc.com.cn/916774523755909/4857910459512420
func (c *Client) IotApiQueryUserBalance() *IotApiQueryUserBalanceResult {
func (c *Client) IotApiQueryUserBalance(ctx context.Context) *IotApiQueryUserBalanceResult {
// 请求
request, err := c.request(apiUrl+"/Api/IotApi/queryUserBalance", map[string]interface{}{}, http.MethodPost)
request, err := c.request(ctx, apiUrl+"/Api/IotApi/queryUserBalance", map[string]interface{}{}, http.MethodPost)
// 定义
var response IotApiQueryUserBalanceResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,11 +1,13 @@
package eastiot
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"time"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 公共参数
params["appId"] = c.config.AppId
@ -30,17 +32,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -28,7 +29,7 @@ func newCheckCostResult(result CheckCostResponse, body []byte, http gorequest.Re
}
// CheckCost 会员订单成本价查询接口
func (c *Client) CheckCost(orderId string) *CheckCostResult {
func (c *Client) CheckCost(ctx context.Context, orderId string) *CheckCostResult {
// 参数
param := gorequest.NewParams()
param.Set("orderid", orderId)
@ -36,7 +37,7 @@ func (c *Client) CheckCost(orderId string) *CheckCostResult {
// 签名
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", c.getUserId(), c.getPwd(), orderId)
// 请求
request, err := c.request(apiUrl+"/checkCost.do", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/checkCost.do", params, http.MethodGet)
// 定义
var response CheckCostResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -36,7 +37,7 @@ func newChOngZhiJkOrdersResult(result ChOngZhiJkOrdersResponse, body []byte, htt
// orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
// face 充值面值 以元为单位包含10、20、30、50、100、200、300、500 移动联通电信
// account 手机号码 需要充值的手机号码
func (c *Client) ChOngZhiJkOrders(orderID string, face int, account string) *ChOngZhiJkOrdersResult {
func (c *Client) ChOngZhiJkOrders(ctx context.Context, orderID string, face int, account string) *ChOngZhiJkOrdersResult {
// 参数
param := gorequest.NewParams()
param.Set("orderid", orderID)
@ -47,7 +48,7 @@ func (c *Client) ChOngZhiJkOrders(orderID string, face int, account string) *ChO
// 签名
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%vface%vaccount%vamount1", c.getUserId(), c.getPwd(), orderID, face, account)
// 请求
request, err := c.request(apiUrl+"/chongzhi_jkorders.do", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/chongzhi_jkorders.do", params, http.MethodGet)
// 定义
var response ChOngZhiJkOrdersResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -46,13 +47,13 @@ func newGprsChOngZhiAdvanceResult(result GprsChOngZhiAdvanceResponse, body []byt
}
// GprsChOngZhiAdvance 流量充值接口
func (c *Client) GprsChOngZhiAdvance(notMustParams ...gorequest.Params) *GprsChOngZhiAdvanceResult {
func (c *Client) GprsChOngZhiAdvance(ctx context.Context, notMustParams ...gorequest.Params) *GprsChOngZhiAdvanceResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 签名
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 := c.request(apiUrl+"/gprsChongzhiAdvance.do", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/gprsChongzhiAdvance.do", params, http.MethodGet)
// 定义
var response GprsChOngZhiAdvanceResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -26,11 +27,11 @@ func newMoneyJkUserResult(result MoneyJkUserResponse, body []byte, http goreques
}
// MoneyJkUser 用户余额查询
func (c *Client) MoneyJkUser() *MoneyJkUserResult {
func (c *Client) MoneyJkUser(ctx context.Context) *MoneyJkUserResult {
// 签名
c.signStr = fmt.Sprintf("userid%vpwd%v", c.getUserId(), c.getPwd())
// 请求
request, err := c.request(apiUrl+"/money_jkuser.do", map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/money_jkuser.do", map[string]interface{}{}, http.MethodGet)
// 定义
var response MoneyJkUserResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -34,7 +35,7 @@ func newQueryJkOrdersResult(result QueryJkOrdersResponse, body []byte, http gore
// QueryJkOrders 通用查询接口
// orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
func (c *Client) QueryJkOrders(orderId string) *QueryJkOrdersResult {
func (c *Client) QueryJkOrders(ctx context.Context, orderId string) *QueryJkOrdersResult {
// 参数
param := gorequest.NewParams()
param.Set("orderid", orderId)
@ -42,7 +43,7 @@ func (c *Client) QueryJkOrders(orderId string) *QueryJkOrdersResult {
// 签名
c.signStr = fmt.Sprintf("userid%vpwd%vorderid%v", c.getUserId(), c.getPwd(), orderId)
// 请求
request, err := c.request(apiUrl+"/query_jkorders.do", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/query_jkorders.do", params, http.MethodGet)
// 定义
var response QueryJkOrdersResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -24,11 +25,11 @@ func newQueryTxProductResult(result QueryTxProductResponse, body []byte, http go
}
// QueryTxProduct 可充值腾讯产品查询
func (c *Client) QueryTxProduct() *QueryTxProductResult {
func (c *Client) QueryTxProduct(ctx context.Context) *QueryTxProductResult {
// 签名
c.signStr = fmt.Sprintf("userid%vpwd%v", c.getUserId(), c.getPwd())
// 请求
request, err := c.request(apiUrl+"/queryTXproduct.do", map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/queryTXproduct.do", map[string]interface{}{}, http.MethodGet)
// 定义
var response QueryTxProductResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,12 +1,14 @@
package ejiaofei
import (
"context"
"fmt"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gomd5"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 公共参数
params["userid"] = c.getUserId()
@ -31,17 +33,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddlewareXml(request)
go c.log.GormMiddlewareXml(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddlewareXml(request)
go c.log.MongoMiddlewareXml(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package ejiaofei
import (
"context"
"encoding/xml"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -42,13 +43,13 @@ func newTxChOngZhiResult(result TxChOngZhiResponse, body []byte, http gorequest.
}
// TxChOngZhi 流量充值接口
func (c *Client) TxChOngZhi(notMustParams ...gorequest.Params) *TxChOngZhiResult {
func (c *Client) TxChOngZhi(ctx context.Context, notMustParams ...gorequest.Params) *TxChOngZhiResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 签名
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 := c.request(apiUrl+"/txchongzhi.do", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/txchongzhi.do", params, http.MethodGet)
// 定义
var response TxChOngZhiResponse
err = xml.Unmarshal(request.ResponseBody, &response)

@ -1,8 +1,12 @@
package feishu
import "github.com/dtapps/go-library/utils/gorequest"
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}) (gorequest.Response, error) {
// 创建请求
client := c.client
@ -17,17 +21,17 @@ func (c *Client) request(url string, params map[string]interface{}) (gorequest.R
client.SetParams(params)
// 发起请求
request, err := client.Post()
request, err := client.Post(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package feishu
import (
"context"
"encoding/json"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
@ -26,11 +27,11 @@ func newWebhookSendResult(result WebhookSendResponse, body []byte, http goreques
}
// WebhookSend https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN
func (c *Client) WebhookSend(notMustParams ...gorequest.Params) *WebhookSendResult {
func (c *Client) WebhookSend(ctx context.Context, notMustParams ...gorequest.Params) *WebhookSendResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+fmt.Sprintf("/open-apis/bot/v2/hook/%s", c.config.Key), params)
request, err := c.request(ctx, apiUrl+fmt.Sprintf("/open-apis/bot/v2/hook/%s", c.config.Key), params)
// 定义
var response WebhookSendResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -61,11 +62,11 @@ func newUnionOpenActivityQueryResult(responce UnionOpenActivityQueryResultRespon
// UnionOpenActivityQuery 活动查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.activity.query
func (c *Client) UnionOpenActivityQuery(notMustParams ...Params) *UnionOpenActivityQueryResult {
func (c *Client) UnionOpenActivityQuery(ctx context.Context, notMustParams ...Params) *UnionOpenActivityQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.activity.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenActivityQueryResultResponse
var result UnionOpenActivityQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -38,11 +39,11 @@ func newUnionOpenCategoryGoodsGetResult(responce UnionOpenCategoryGoodsGetResult
// UnionOpenCategoryGoodsGet 商品类目查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.category.goods.get
func (c *Client) UnionOpenCategoryGoodsGet(notMustParams ...Params) *UnionOpenCategoryGoodsGetResult {
func (c *Client) UnionOpenCategoryGoodsGet(ctx context.Context, notMustParams ...Params) *UnionOpenCategoryGoodsGetResult {
// 参数
params := NewParamsWithType("jd.union.open.category.goods.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenCategoryGoodsGetResultResponse
var result UnionOpenCategoryGoodsGetQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -58,11 +59,11 @@ func newUnionOpenGoodsBigfieldQueryResult(responce UnionOpenGoodsBigfieldQueryRe
// UnionOpenGoodsBigfieldQuery 商品详情查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.bigfield.query
func (c *Client) UnionOpenGoodsBigfieldQuery(notMustParams ...Params) *UnionOpenGoodsBigfieldQueryResult {
func (c *Client) UnionOpenGoodsBigfieldQuery(ctx context.Context, notMustParams ...Params) *UnionOpenGoodsBigfieldQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.goods.bigfield.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenGoodsBigfieldQueryResultResponse
var result UnionOpenGoodsBigfieldQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -122,11 +123,11 @@ func newUnionOpenGoodsJIngFenQueryResult(responce UnionOpenGoodsJIngFenQueryResu
// UnionOpenGoodsJIngFenQuery 京粉精选商品查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.jingfen.query
func (c *Client) UnionOpenGoodsJIngFenQuery(notMustParams ...Params) *UnionOpenGoodsJIngFenQueryResult {
func (c *Client) UnionOpenGoodsJIngFenQuery(ctx context.Context, notMustParams ...Params) *UnionOpenGoodsJIngFenQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.goods.jingfen.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenGoodsJIngFenQueryResultResponse
var result UnionOpenGoodsJIngFenQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -119,11 +120,11 @@ func newUnionOpenGoodsMaterialQueryResult(responce UnionOpenGoodsMaterialQueryRe
// UnionOpenGoodsMaterialQuery 猜你喜欢商品推荐
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.material.query
func (c *Client) UnionOpenGoodsMaterialQuery(notMustParams ...Params) *UnionOpenGoodsMaterialQueryResult {
func (c *Client) UnionOpenGoodsMaterialQuery(ctx context.Context, notMustParams ...Params) *UnionOpenGoodsMaterialQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.goods.material.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenGoodsMaterialQueryResultResponse
var result UnionOpenGoodsMaterialQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -57,11 +58,11 @@ func newUnionOpenGoodsPromotionGoodsInfoQueryResult(responce UnionOpenGoodsPromo
// UnionOpenGoodsPromotionGoodsInfoQuery 根据skuid查询商品信息接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.promotiongoodsinfo.query
func (c *Client) UnionOpenGoodsPromotionGoodsInfoQuery(notMustParams ...Params) *UnionOpenGoodsPromotionGoodsInfoQueryResult {
func (c *Client) UnionOpenGoodsPromotionGoodsInfoQuery(ctx context.Context, notMustParams ...Params) *UnionOpenGoodsPromotionGoodsInfoQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.goods.promotiongoodsinfo.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenGoodsPromotionGoodsInfoQueryResultResponse
var result UnionOpenGoodsPromotionGoodsInfoQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -82,11 +83,11 @@ func newUnionOpenOrderQueryResult(responce UnionOpenOrderQueryResultResponse, re
// UnionOpenOrderQuery 订单查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.order.query
func (c *Client) UnionOpenOrderQuery(notMustParams ...Params) *UnionOpenOrderQueryResult {
func (c *Client) UnionOpenOrderQuery(ctx context.Context, notMustParams ...Params) *UnionOpenOrderQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.order.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenOrderQueryResultResponse
var result UnionOpenOrderQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -91,11 +92,11 @@ func newUnionOpenOrderRowQueryResult(responce UnionOpenOrderRowQueryResultRespon
// UnionOpenOrderRowQuery 订单行查询接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.order.row.query
func (c *Client) UnionOpenOrderRowQuery(notMustParams ...Params) *UnionOpenOrderRowQueryResult {
func (c *Client) UnionOpenOrderRowQuery(ctx context.Context, notMustParams ...Params) *UnionOpenOrderRowQueryResult {
// 参数
params := NewParamsWithType("jd.union.open.order.row.query", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenOrderRowQueryResultResponse
var result UnionOpenOrderRowQueryQueryResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -36,11 +37,11 @@ func newUnionOpenPromotionBySubUnionIdGetResult(responce UnionOpenPromotionBySub
// UnionOpenPromotionBySubUnionIdGet 社交媒体获取推广链接接口【申请】
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.promotion.bysubunionid.get
func (c *Client) UnionOpenPromotionBySubUnionIdGet(notMustParams ...Params) *UnionOpenPromotionBySubUnionIdGetResult {
func (c *Client) UnionOpenPromotionBySubUnionIdGet(ctx context.Context, notMustParams ...Params) *UnionOpenPromotionBySubUnionIdGetResult {
// 参数
params := NewParamsWithType("jd.union.open.promotion.bysubunionid.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenPromotionBySubUnionIdGetResultResponse
var result UnionOpenPromotionBySubUnionIdGetGetResult

@ -1,6 +1,7 @@
package jd
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -36,11 +37,11 @@ func newUnionOpenPromotionCommonGetResult(responce UnionOpenPromotionCommonGetRe
// UnionOpenPromotionCommonGet 网站/APP获取推广链接接口
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.promotion.common.get
func (c *Client) UnionOpenPromotionCommonGet(notMustParams ...Params) *UnionOpenPromotionCommonGetResult {
func (c *Client) UnionOpenPromotionCommonGet(ctx context.Context, notMustParams ...Params) *UnionOpenPromotionCommonGetResult {
// 参数
params := NewParamsWithType("jd.union.open.promotion.common.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var responce UnionOpenPromotionCommonGetResultResponse
var result UnionOpenPromotionCommonGetGetResult

@ -1,12 +1,14 @@
package jd
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"github.com/dtapps/go-library/utils/gostring"
)
// 请求接口
func (c *Client) request(params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, params map[string]interface{}) (gorequest.Response, error) {
// 签名
c.Sign(params)
@ -21,17 +23,17 @@ func (c *Client) request(params map[string]interface{}) (gorequest.Response, err
client.SetParams(params)
// 发起请求
request, err := client.Post()
request, err := client.Post(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddlewareCustom(gostring.ToString(params["method"]), request)
go c.log.GormMiddlewareCustom(ctx, gostring.ToString(params["method"]), request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddlewareCustom(gostring.ToString(params["method"]), request)
go c.log.MongoMiddlewareCustom(ctx, gostring.ToString(params["method"]), request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -17,11 +18,11 @@ type ApiBuyResponse struct {
Cards []struct {
CardNo string `json:"card_no"`
CardPassword string `json:"card_password"`
} `json:"cards,omitempty"` // 卡密(仅当订单成功并且商品类型为卡密时返回此数据)
} `json:"cards,omitempty"` // 卡密(仅当订单成功并且商品类型为卡密时返回此数据)
Tickets []struct {
No string `json:"no"`
Ticket string `json:"ticket"`
} `json:"tickets,omitempty"` // 卡券(仅当订单成功并且商品类型为卡券时返回此数据)
} `json:"tickets,omitempty"` // 卡券(仅当订单成功并且商品类型为卡券时返回此数据)
} `json:"data"`
}
@ -38,11 +39,11 @@ func newApiBuyResult(result ApiBuyResponse, body []byte, http gorequest.Response
// ApiBuy 购买商品
// http://doc.cqmeihu.cn/sales/buy.html
func (c *Client) ApiBuy(notMustParams ...gorequest.Params) *ApiBuyResult {
func (c *Client) ApiBuy(ctx context.Context, notMustParams ...gorequest.Params) *ApiBuyResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/api/buy", params)
request, err := c.request(ctx, apiUrl+"/api/buy", params)
// 定义
var response ApiBuyResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -28,9 +29,9 @@ func newApiCustomerResult(result ApiCustomerResponse, body []byte, http goreques
// ApiCustomer 获取商家信息
// http://doc.cqmeihu.cn/sales/merchant-info.html
func (c *Client) ApiCustomer() *ApiCustomerResult {
func (c *Client) ApiCustomer(ctx context.Context) *ApiCustomerResult {
// 请求
request, err := c.request(apiUrl+"/api/customer", map[string]interface{}{})
request, err := c.request(ctx, apiUrl+"/api/customer", map[string]interface{}{})
// 定义
var response ApiCustomerResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -52,13 +53,13 @@ func newApiOrderResult(result ApiOrderResponse, body []byte, http gorequest.Resp
// ApiOrder 获取单个订单信息。
// 仅能获取自己购买的订单。
// http://doc.cqmeihu.cn/sales/order-info.html
func (c *Client) ApiOrder(orderId string) *ApiOrderResult {
func (c *Client) ApiOrder(ctx context.Context, orderId string) *ApiOrderResult {
// 参数
param := gorequest.NewParams()
param.Set("order_id", orderId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/api/order", params)
request, err := c.request(ctx, apiUrl+"/api/order", params)
// 定义
var response ApiOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -52,13 +53,13 @@ func newApiOuterOrderResult(result ApiOuterOrderResponse, body []byte, http gore
// ApiOuterOrder 使用外部订单号获取单个订单信息
// 仅能获取自己购买的订单
// http://doc.cqmeihu.cn/sales/outer-order-info.html
func (c *Client) ApiOuterOrder(orderId string) *ApiOuterOrderResult {
func (c *Client) ApiOuterOrder(ctx context.Context, orderId string) *ApiOuterOrderResult {
// 参数
param := gorequest.NewParams()
param.Set("outer_order_id", orderId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/api/outer-order", params)
request, err := c.request(ctx, apiUrl+"/api/outer-order", params)
// 定义
var response ApiOuterOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -0,0 +1,47 @@
package kashangwl
import (
"context"
"encoding/json"
"fmt"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
)
type ApiProductCacheResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
GoodsId string `json:"goods_id"`
ApiGoodsId int `json:"api_goods_id"`
GoodsName string `json:"goods_name"`
ClassificationName string `json:"classification_name"`
GoodsPrice float64 `json:"goods_price"`
PurchaseTips string `json:"purchase_tips"`
} `json:"data"`
Time int `json:"time"`
TraceId string `json:"trace_id"`
}
type ApiProductCacheResult struct {
Result ApiProductCacheResponse // 结果
Body []byte // 内容
Http gorequest.Response // 请求
Err error // 错误
}
func newApiProductCacheResult(result ApiProductCacheResponse, body []byte, http gorequest.Response, err error) *ApiProductCacheResult {
return &ApiProductCacheResult{Result: result, Body: body, Http: http, Err: err}
}
// ApiProductCache [缓存,需托管授权]获取单个商品信息
func (c *Client) ApiProductCache(ctx context.Context, productId int64) *ApiProductCacheResult {
// 参数
params := gorequest.NewParams()
// 请求
request, err := c.requestCache(ctx, fmt.Sprintf("%s/%d/goods_info/%d", apiUrlCache, c.GetCustomerId(), productId), params, http.MethodGet)
// 定义
var response ApiProductCacheResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newApiProductCacheResult(response, request.ResponseBody, request, err)
}

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -17,7 +18,7 @@ type ApiProductResponse struct {
SuperiorCommissionsRate int `json:"superior_commissions_rate"` // 上级佣金比例
Type int `json:"type"` // 商品类型1充值2卡密3卡券4人工
SupplyState int `json:"supply_state"` // 库存状态1充足2断货
StockState int `json:"stock_state"` // 状态1上架2维护3下架
StockState int `json:"stock_state"` // 状态1上架2维护3下架
BanStartAt string `json:"ban_start_at"` // 禁售开始时间
BanEndAt string `json:"ban_end_at"` // 禁售结束时间
} `json:"data"`
@ -36,12 +37,12 @@ func newApiProductResult(result ApiProductResponse, body []byte, http gorequest.
// ApiProduct 获取单个商品信息
// http://doc.cqmeihu.cn/sales/product-info.html
func (c *Client) ApiProduct(productId int64) *ApiProductResult {
func (c *Client) ApiProduct(ctx context.Context, productId int64) *ApiProductResult {
// 参数
params := gorequest.NewParams()
params.Set("product_id", productId)
// 请求
request, err := c.request(apiUrl+"/api/product", params)
request, err := c.request(ctx, apiUrl+"/api/product", params)
// 定义
var response ApiProductResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package kashangwl
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -32,12 +33,12 @@ func newApiProductRechargeParamsResult(result ApiProductRechargeParamsResponse,
// ApiProductRechargeParams 接口说明
// 获取商品的充值参数(仅支持充值类商品)
// http://doc.cqmeihu.cn/sales/ProductParams.html
func (c *Client) ApiProductRechargeParams(productId int64) *ApiProductRechargeParamsResult {
func (c *Client) ApiProductRechargeParams(ctx context.Context, productId int64) *ApiProductRechargeParamsResult {
// 参数
params := gorequest.NewParams()
params.Set("product_id", productId)
// 请求
request, err := c.request(apiUrl+"/api/product/recharge-params", params)
request, err := c.request(ctx, apiUrl+"/api/product/recharge-params", params)
// 定义
var response ApiProductRechargeParamsResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -5,7 +5,12 @@ const (
)
const (
apiUrl = "http://www.kashangwl.com"
CodeCacheSuccess = 1
)
const (
apiUrl = "http://www.kashangwl.com"
apiUrlCache = "https://api.dtapp.net/v1/866ka"
)
const (

@ -1,11 +1,13 @@
package kashangwl
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"time"
)
func (c *Client) request(url string, params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}) (gorequest.Response, error) {
// 公共参数
params["timestamp"] = time.Now().UnixNano() / 1e6
@ -27,17 +29,51 @@ func (c *Client) request(url string, params map[string]interface{}) (gorequest.R
client.SetParams(params)
// 发起请求
request, err := client.Post()
request, err := client.Post(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err
}
func (c *Client) requestCache(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
// 设置请求地址
client.SetUri(url)
// 设置方式
client.SetMethod(method)
// 设置FORM格式
client.SetContentTypeJson()
// 设置参数
client.SetParams(params)
// 发起请求
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package kuaishou
import (
"context"
"errors"
"github.com/mvdan/xurls"
"strings"
@ -21,7 +22,7 @@ func newAnalysisResult(result AnalysisResponse, err error) *AnalysisResult {
}
// Analysis 快手解析
func (c *Client) Analysis(content string) *AnalysisResult {
func (c *Client) Analysis(ctx context.Context, content string) *AnalysisResult {
// 定义
var response AnalysisResponse

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -25,7 +26,7 @@ func newApiGenerateLinkResult(result ApiGenerateLinkResponse, body []byte, http
// ApiGenerateLink 自助取链接口(新版)
// https://union.meituan.com/v2/apiDetail?id=25
func (c *Client) ApiGenerateLink(actId int64, sid string, linkType, shortLink int) *ApiGenerateLinkResult {
func (c *Client) ApiGenerateLink(ctx context.Context, actId int64, sid string, linkType, shortLink int) *ApiGenerateLinkResult {
// 参数
param := gorequest.NewParams()
param.Set("actId", actId) // 活动id可以在联盟活动列表中查看获取
@ -37,7 +38,7 @@ func (c *Client) ApiGenerateLink(actId int64, sid string, linkType, shortLink in
params := gorequest.NewParamsWith(param)
params["sign"] = c.getSign(c.config.Secret, params)
// 请求
request, err := c.request(apiUrl+"/api/generateLink", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/api/generateLink", params, http.MethodGet)
// 定义
var response ApiGenerateLinkResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"github.com/dtapps/go-library/utils/gotime"
@ -34,7 +35,7 @@ func newApiGetQuaLitYsCoreBySidResult(result ApiGetQuaLitYsCoreBySidResponse, bo
// ApiGetQuaLitYsCoreBySid 优选sid质量分&复购率查询
// https://union.meituan.com/v2/apiDetail?id=28
func (c *Client) ApiGetQuaLitYsCoreBySid(notMustParams ...gorequest.Params) *ApiGetQuaLitYsCoreBySidResult {
func (c *Client) ApiGetQuaLitYsCoreBySid(ctx context.Context, notMustParams ...gorequest.Params) *ApiGetQuaLitYsCoreBySidResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求时刻10位时间戳(秒级)有效期60s
@ -42,7 +43,7 @@ func (c *Client) ApiGetQuaLitYsCoreBySid(notMustParams ...gorequest.Params) *Api
params["appkey"] = c.config.AppKey
params["sign"] = c.getSign(c.config.Secret, params)
// 请求
request, err := c.request(apiUrl+"/api/getqualityscorebysid", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/api/getqualityscorebysid", params, http.MethodGet)
// 定义
var response ApiGetQuaLitYsCoreBySidResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -25,7 +26,7 @@ func newApiMiniCodeResult(result ApiMiniCodeResponse, body []byte, http goreques
// ApiMiniCode 小程序生成二维码(新版)
// https://union.meituan.com/v2/apiDetail?id=26
func (c *Client) ApiMiniCode(actId int64, sid string) *ApiMiniCodeResult {
func (c *Client) ApiMiniCode(ctx context.Context, actId int64, sid string) *ApiMiniCodeResult {
// 参数
param := gorequest.NewParams()
param.Set("appkey", c.config.AppKey)
@ -35,7 +36,7 @@ func (c *Client) ApiMiniCode(actId int64, sid string) *ApiMiniCodeResult {
params := gorequest.NewParamsWith(param)
params["sign"] = c.getSign(c.config.Secret, params)
// 请求
request, err := c.request(apiUrl+"/api/miniCode", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/api/miniCode", params, http.MethodGet)
// 定义
var response ApiMiniCodeResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -47,14 +48,14 @@ func newApiOrderResult(result ApiOrderResponse, body []byte, http gorequest.Resp
// ApiOrder 单订单查询接口(新版)
// https://union.meituan.com/v2/apiDetail?id=24
func (c *Client) ApiOrder(notMustParams ...gorequest.Params) *ApiOrderResult {
func (c *Client) ApiOrder(ctx context.Context, notMustParams ...gorequest.Params) *ApiOrderResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求时刻10位时间戳(秒级)有效期60s
params["appkey"] = c.config.AppKey
params["sign"] = c.getSign(c.config.Secret, params)
// 请求
request, err := c.request(apiUrl+"/api/order", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/api/order", params, http.MethodGet)
// 定义
var response ApiOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"github.com/dtapps/go-library/utils/gotime"
@ -46,7 +47,7 @@ func newApiOrderListResult(result ApiOrderListResponse, body []byte, http gorequ
// ApiOrderList 订单列表查询接口(新版)
// https://union.meituan.com/v2/apiDetail?id=23
func (c *Client) ApiOrderList(notMustParams ...gorequest.Params) *ApiOrderListResult {
func (c *Client) ApiOrderList(ctx context.Context, notMustParams ...gorequest.Params) *ApiOrderListResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求时刻10位时间戳(秒级)有效期60s
@ -54,7 +55,7 @@ func (c *Client) ApiOrderList(notMustParams ...gorequest.Params) *ApiOrderListRe
params["appkey"] = c.config.AppKey
params["sign"] = c.getSign(c.config.Secret, params)
// 请求
request, err := c.request(apiUrl+"/api/orderList", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/api/orderList", params, http.MethodGet)
// 定义
var response ApiOrderListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -31,13 +32,13 @@ func newPoiAreaResult(result PoiAreaResponse, body []byte, http gorequest.Respon
// PoiArea 基础数据 - 商圈接口
// https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiAreaCityid1
func (c *Client) PoiArea(cityID int) *PoiAreaResult {
func (c *Client) PoiArea(ctx context.Context, cityID int) *PoiAreaResult {
// 参数
param := gorequest.NewParams()
param.Set("cityid", cityID)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/poi/area", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/poi/area", params, http.MethodGet)
// 定义
var response PoiAreaResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -31,13 +32,13 @@ func newPoiCategoryResult(result PoiCategoryResponse, body []byte, http goreques
// PoiCategory 基础数据 - 品类接口
// https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiDistrictCityid1
func (c *Client) PoiCategory(cityID int) *PoiCategoryResult {
func (c *Client) PoiCategory(ctx context.Context, cityID int) *PoiCategoryResult {
// 参数
param := gorequest.NewParams()
param.Set("cityid", cityID)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/poi/category", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/poi/category", params, http.MethodGet)
// 定义
var response PoiCategoryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -28,9 +29,9 @@ func newPoiCityResult(result PoiCityResponse, body []byte, http gorequest.Respon
// PoiCity 基础数据 - 开放城市接口
// https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiCity
func (c *Client) PoiCity() *PoiCityResult {
func (c *Client) PoiCity(ctx context.Context) *PoiCityResult {
// 请求
request, err := c.request(apiUrl+"/poi/city", map[string]interface{}{}, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/poi/city", map[string]interface{}{}, http.MethodGet)
// 定义
var response PoiCityResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package meituan
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
"net/http"
@ -27,13 +28,13 @@ func newPoiDistrictResult(result PoiDistrictResponse, body []byte, http goreques
// PoiDistrict 基础数据 - 城市的行政区接口
// https://openapi.meituan.com/#api-0.%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE-GetHttpsOpenapiMeituanComPoiDistrictCityid1
func (c *Client) PoiDistrict(cityID int) *PoiDistrictResult {
func (c *Client) PoiDistrict(ctx context.Context, cityID int) *PoiDistrictResult {
// 参数
param := gorequest.NewParams()
param.Set("cityid", cityID)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/poi/district", params, http.MethodGet)
request, err := c.request(ctx, apiUrl+"/poi/district", params, http.MethodGet)
// 定义
var response PoiDistrictResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,8 +1,12 @@
package meituan
import "github.com/dtapps/go-library/utils/gorequest"
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
)
func (c *Client) request(url string, params map[string]interface{}, method string) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}, method string) (gorequest.Response, error) {
// 创建请求
client := c.client
@ -20,17 +24,17 @@ func (c *Client) request(url string, params map[string]interface{}, method strin
client.SetParams(params)
// 发起请求
request, err := client.Request()
request, err := client.Request(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package meituan
import (
"context"
"github.com/gin-gonic/gin"
"net/http"
)
@ -37,7 +38,7 @@ type ResponseServeHttpOrder struct {
// ServeHttpOrder 订单回推接口(新版)
// https://union.meituan.com/v2/apiDetail?id=22
func (c *Client) ServeHttpOrder(gCtx *gin.Context) (validateJson ResponseServeHttpOrder, err error) {
func (c *Client) ServeHttpOrder(ctx context.Context, gCtx *gin.Context) (validateJson ResponseServeHttpOrder, err error) {
// 声明接收的变量
err = gCtx.ShouldBind(&validateJson)
return

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -62,12 +63,12 @@ func newCmsPromUrlGenerateResult(result CmsPromUrlGenerateResponse, body []byte,
// CmsPromUrlGenerate 生成商城-频道推广链接
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.cms.prom.url.generate
func (c *Client) CmsPromUrlGenerate(notMustParams ...Params) *CmsPromUrlGenerateResult {
func (c *Client) CmsPromUrlGenerate(ctx context.Context, notMustParams ...Params) *CmsPromUrlGenerateResult {
// 参数
params := NewParamsWithType("pdd.ddk.cms.prom.url.generate", notMustParams...)
params.Set("p_id_list", []string{c.config.Pid})
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response CmsPromUrlGenerateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -97,12 +98,12 @@ func newGoodsDetailResult(result GoodsDetailResponse, body []byte, http goreques
// GoodsDetail 多多进宝商品详情查询
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.detail
func (c *Client) GoodsDetail(notMustParams ...Params) *GoodsDetailResult {
func (c *Client) GoodsDetail(ctx context.Context, notMustParams ...Params) *GoodsDetailResult {
// 参数
params := NewParamsWithType("pdd.ddk.goods.detail", notMustParams...)
params.Set("pid", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsDetailResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -30,11 +31,11 @@ func newGoodsPidGenerateResult(result GoodsPidGenerateResponse, body []byte, htt
// GoodsPidGenerate 创建多多进宝推广位
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
func (c *Client) GoodsPidGenerate(notMustParams ...Params) *GoodsPidGenerateResult {
func (c *Client) GoodsPidGenerate(ctx context.Context, notMustParams ...Params) *GoodsPidGenerateResult {
// 参数
params := NewParamsWithType("pdd.ddk.goods.pid.generate", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsPidGenerateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -50,12 +51,12 @@ func newGoodsPromotionUrlGenerateResult(result GoodsPromotionUrlGenerateResponse
// GoodsPromotionUrlGenerate 多多进宝推广链接生成
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.promotion.url.generate
func (c *Client) GoodsPromotionUrlGenerate(notMustParams ...Params) *GoodsPromotionUrlGenerateResult {
func (c *Client) GoodsPromotionUrlGenerate(ctx context.Context, notMustParams ...Params) *GoodsPromotionUrlGenerateResult {
// 参数
params := NewParamsWithType("pdd.ddk.goods.promotion.url.generate", notMustParams...)
params.Set("p_id", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsPromotionUrlGenerateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -79,12 +80,12 @@ func newGoodsRecommendGetResult(result GoodsRecommendGetResponse, body []byte, h
// GoodsRecommendGet 多多进宝商品推荐API
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.recommend.get
func (c *Client) GoodsRecommendGet(notMustParams ...Params) *GoodsRecommendGetResult {
func (c *Client) GoodsRecommendGet(ctx context.Context, notMustParams ...Params) *GoodsRecommendGetResult {
// 参数
params := NewParamsWithType("pdd.ddk.goods.recommend.get", notMustParams...)
params.Set("pid", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsRecommendGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -93,12 +94,12 @@ func newGoodsSearchResult(result GoodsSearchResponse, body []byte, http goreques
// GoodsSearch 多多进宝商品查询
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
func (c *Client) GoodsSearch(notMustParams ...Params) *GoodsSearchResult {
func (c *Client) GoodsSearch(ctx context.Context, notMustParams ...Params) *GoodsSearchResult {
// 参数
params := NewParamsWithType("pdd.ddk.goods.search", notMustParams...)
params.Set("pid", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsSearchResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -25,12 +26,12 @@ func newMemberAuthorityQueryResult(result MemberAuthorityQueryResponse, body []b
// MemberAuthorityQuery 查询是否绑定备案
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search
func (c *Client) MemberAuthorityQuery(notMustParams ...Params) *MemberAuthorityQueryResult {
func (c *Client) MemberAuthorityQuery(ctx context.Context, notMustParams ...Params) *MemberAuthorityQueryResult {
// 参数
params := NewParamsWithType("pdd.ddk.member.authority.query", notMustParams...)
params.Set("pid", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response MemberAuthorityQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -66,13 +67,13 @@ func newOrderDetailGetResult(result OrderDetailGetResponse, body []byte, http go
}
// OrderDetailGet 多多进宝商品查询 https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.detail.get
func (c *Client) OrderDetailGet(orderSn string) *OrderDetailGetResult {
func (c *Client) OrderDetailGet(ctx context.Context, orderSn string) *OrderDetailGetResult {
// 参数
param := NewParams()
param.Set("order_sn", orderSn)
params := NewParamsWithType("pdd.ddk.order.detail.get", param)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response OrderDetailGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -71,11 +72,11 @@ func newOrderListIncrementGetResult(result OrderListIncrementGetResponse, body [
// OrderListIncrementGet 最后更新时间段增量同步推广订单信息
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.increment.get
func (c *Client) OrderListIncrementGet(notMustParams ...Params) *OrderListIncrementGetResult {
func (c *Client) OrderListIncrementGet(ctx context.Context, notMustParams ...Params) *OrderListIncrementGetResult {
// 参数
params := NewParamsWithType("pdd.ddk.order.list.increment.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response OrderListIncrementGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -71,11 +72,11 @@ func newOrderListRangeGetResult(result OrderListRangeGetResponse, body []byte, h
// OrderListRangeGet 用时间段查询推广订单接口
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.order.list.range.get
func (c *Client) OrderListRangeGet(notMustParams ...Params) *OrderListRangeGetResult {
func (c *Client) OrderListRangeGet(ctx context.Context, notMustParams ...Params) *OrderListRangeGetResult {
// 参数
params := NewParamsWithType("pdd.ddk.order.list.range.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response OrderListRangeGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -51,12 +52,12 @@ func newResourceUrlGenResult(result ResourceUrlGenResponse, body []byte, http go
// ResourceUrlGen 生成多多进宝频道推广
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.pid.generate
func (c *Client) ResourceUrlGen(notMustParams ...Params) *ResourceUrlGenResult {
func (c *Client) ResourceUrlGen(ctx context.Context, notMustParams ...Params) *ResourceUrlGenResult {
// 参数
params := NewParamsWithType("pdd.ddk.resource.url.gen", notMustParams...)
params.Set("pid", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response ResourceUrlGenResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -66,12 +67,12 @@ func newRpPromUrlGenerateResult(result RpPromUrlGenerateResponse, body []byte, h
// RpPromUrlGenerate 生成营销工具推广链接
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.rp.prom.url.generate
func (c *Client) RpPromUrlGenerate(notMustParams ...Params) *RpPromUrlGenerateResult {
func (c *Client) RpPromUrlGenerate(ctx context.Context, notMustParams ...Params) *RpPromUrlGenerateResult {
// 参数
params := NewParamsWithType("pdd.ddk.rp.prom.url.generate", notMustParams...)
params.Set("p_id_list", []string{c.config.Pid})
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response RpPromUrlGenerateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -59,12 +60,12 @@ func newTopGoodsListQueryResult(result TopGoodsListQueryResponse, body []byte, h
// TopGoodsListQuery 多多客获取爆款排行商品接口
// https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.top.goods.list.query
func (c *Client) TopGoodsListQuery(notMustParams ...Params) *TopGoodsListQueryResult {
func (c *Client) TopGoodsListQuery(ctx context.Context, notMustParams ...Params) *TopGoodsListQueryResult {
// 参数
params := NewParamsWithType("pdd.ddk.top.goods.list.query", notMustParams...)
params.Set("p_id", c.config.Pid)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TopGoodsListQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -29,13 +30,13 @@ func newGoodsCatsGetResult(result GoodsCatsGetResponse, body []byte, http gorequ
// GoodsCatsGet 商品标准类目接口
// https://open.pinduoduo.com/application/document/api?id=pdd.goods.cats.get
func (c *Client) GoodsCatsGet(parentOptId int) *GoodsCatsGetResult {
func (c *Client) GoodsCatsGet(ctx context.Context, parentOptId int) *GoodsCatsGetResult {
// 参数
param := NewParams()
param.Set("parent_cat_id", parentOptId)
params := NewParamsWithType("pdd.goods.cats.get", param)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsCatsGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pinduoduo
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -29,13 +30,13 @@ func newGoodsOptGetResult(result GoodsOptGetResponse, body []byte, http goreques
// GoodsOptGet 查询商品标签列表
// https://open.pinduoduo.com/application/document/api?id=pdd.goods.opt.get
func (c *Client) GoodsOptGet(parentOptId int) *GoodsOptGetResult {
func (c *Client) GoodsOptGet(ctx context.Context, parentOptId int) *GoodsOptGetResult {
// 参数
param := NewParams()
param.Set("parent_opt_id", parentOptId)
params := NewParamsWithType("pdd.goods.opt.get", param)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response GoodsOptGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,11 +1,13 @@
package pinduoduo
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"github.com/dtapps/go-library/utils/gostring"
)
func (c *Client) request(params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, params map[string]interface{}) (gorequest.Response, error) {
// 签名
c.Sign(params)
@ -17,17 +19,17 @@ func (c *Client) request(params map[string]interface{}) (gorequest.Response, err
client.SetParams(params)
// 发起请求
request, err := client.Get()
request, err := client.Get(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddlewareCustom(gostring.ToString(params["type"]), request)
go c.log.GormMiddlewareCustom(ctx, gostring.ToString(params["type"]), request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddlewareCustom(gostring.ToString(params["type"]), request)
go c.log.MongoMiddlewareCustom(ctx, gostring.ToString(params["type"]), request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -42,7 +43,7 @@ func newApiOrderCreateSoonOrderResult(result ApiOrderCreateSoonOrderResponse, bo
}
// ApiOrderCreateSoonOrder 秒出单下单 https://www.showdoc.com.cn/1154868044931571/6437295495912025
func (c *Client) ApiOrderCreateSoonOrder(param ApiOrderCreateSoonOrder) *ApiOrderCreateSoonOrderResult {
func (c *Client) ApiOrderCreateSoonOrder(ctx context.Context, param ApiOrderCreateSoonOrder) *ApiOrderCreateSoonOrderResult {
// api params
params := map[string]interface{}{}
b, _ := json.Marshal(&param)
@ -51,7 +52,7 @@ func (c *Client) ApiOrderCreateSoonOrder(param ApiOrderCreateSoonOrder) *ApiOrde
for k, v := range m {
params[k] = v
}
request, err := c.request(apiUrl+"/api/order/create-soon-order", params)
request, err := c.request(ctx, apiUrl+"/api/order/create-soon-order", params)
// 定义
var response ApiOrderCreateSoonOrderResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -23,11 +24,11 @@ func newApiOrderCreateResult(result ApiOrderCreateResponse, body []byte, http go
}
// ApiOrderCreate 下单api https://www.showdoc.com.cn/1154868044931571/5891022916496848
func (c *Client) ApiOrderCreate(notMustParams ...gorequest.Params) *ApiOrderCreateResult {
func (c *Client) ApiOrderCreate(ctx context.Context, notMustParams ...gorequest.Params) *ApiOrderCreateResult {
// 参数
params := gorequest.NewParamsWith(notMustParams...)
// 请求
request, err := c.request(apiUrl+"/api/order/create", params)
request, err := c.request(ctx, apiUrl+"/api/order/create", params)
// 定义
var response ApiOrderCreateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -45,13 +46,13 @@ func newApiOrderQueryResult(result ApiOrderQueryResponse, body []byte, http gore
}
// ApiOrderQuery 订单查询 https://www.showdoc.com.cn/1154868044931571/5965244588489845
func (c *Client) ApiOrderQuery(thirdOrderId string) *ApiOrderQueryResult {
func (c *Client) ApiOrderQuery(ctx context.Context, thirdOrderId string) *ApiOrderQueryResult {
// 测试
param := gorequest.NewParams()
param.Set("thirdOrderId", thirdOrderId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/api/order/query", params)
request, err := c.request(ctx, apiUrl+"/api/order/query", params)
// 定义
var response ApiOrderQueryResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -29,8 +30,8 @@ func newApiUserInfoResult(result ApiUserInfoResponse, body []byte, http goreques
}
// ApiUserInfo 账号信息查询 https://www.showdoc.com.cn/1154868044931571/6269224958928211
func (c *Client) ApiUserInfo() *ApiUserInfoResult {
request, err := c.request(apiUrl+"/api/user/info", map[string]interface{}{})
func (c *Client) ApiUserInfo(ctx context.Context) *ApiUserInfoResult {
request, err := c.request(ctx, apiUrl+"/api/user/info", map[string]interface{}{})
// 定义
var response ApiUserInfoResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -37,14 +38,14 @@ func newGetCinemaListResult(result GetCinemaListResponse, body []byte, http gore
}
// GetCinemaList 影院列表 https://www.showdoc.com.cn/1154868044931571/5866426126744792
func (c *Client) GetCinemaList(cityId int) *GetCinemaListResult {
func (c *Client) GetCinemaList(ctx context.Context, cityId int) *GetCinemaListResult {
// 参数
param := gorequest.NewParams()
param.Set("cityId", cityId)
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-cinema-list", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-cinema-list", params)
// 定义
var response GetCinemaListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -30,13 +31,13 @@ func newGetCityAreaResult(result GetCityAreaResponse, body []byte, http goreques
// GetCityArea 城市下区域
// https://www.showdoc.com.cn/1154868044931571/6243539682553126
func (c *Client) GetCityArea(cityId int) *GetCityAreaResult {
func (c *Client) GetCityArea(ctx context.Context, cityId int) *GetCityAreaResult {
// 测试
param := gorequest.NewParams()
param.Set("cityId", cityId)
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-city-area", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-city-area", params)
var response GetCityAreaResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newGetCityAreaResult(response, request.ResponseBody, request, err)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -33,8 +34,8 @@ func newGetCityListResult(result GetCityListResponse, body []byte, http goreques
// GetCityList 城市列表
// https://www.showdoc.com.cn/1154868044931571/5865562425538244
func (c *Client) GetCityList() *GetCityListResult {
request, err := c.request(apiUrl+"/movieapi/movie-info/get-city-list", map[string]interface{}{})
func (c *Client) GetCityList(ctx context.Context) *GetCityListResult {
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-city-list", map[string]interface{}{})
var response GetCityListResponse
err = json.Unmarshal(request.ResponseBody, &response)
return newGetCityListResult(response, request.ResponseBody, request, err)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -42,14 +43,14 @@ func newGetHotListResult(result GetHotListResponse, body []byte, http gorequest.
}
// GetHotList 正在热映 https://www.showdoc.com.cn/1154868044931571/5866125707634369
func (c *Client) GetHotList(cityId int) *GetHotListResult {
func (c *Client) GetHotList(ctx context.Context, cityId int) *GetHotListResult {
// 参数
param := gorequest.NewParams()
param.Set("cityId", cityId)
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-hot-list", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-hot-list", params)
// 定义
var response GetHotListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -46,14 +47,14 @@ func newGetScheduleListResult(result GetScheduleListResponse, body []byte, http
}
// GetScheduleList 场次排期 https://www.showdoc.com.cn/1154868044931571/5866708808899217
func (c *Client) GetScheduleList(cinemaId int) *GetScheduleListResult {
func (c *Client) GetScheduleList(ctx context.Context, cinemaId int) *GetScheduleListResult {
// 参数
param := gorequest.NewParams()
param.Set("cinemaId", cinemaId)
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-schedule-list", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-schedule-list", params)
// 定义
var response GetScheduleListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -43,14 +44,14 @@ func newGetSeatResult(result GetSeatResponse, body []byte, http gorequest.Respon
}
// GetSeat 座位 https://www.showdoc.com.cn/1154868044931571/5866824368760475
func (c *Client) GetSeat(showId string) *GetSeatResult {
func (c *Client) GetSeat(ctx context.Context, showId string) *GetSeatResult {
// 参数
param := gorequest.NewParams()
param.Set("showId", showId)
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-seat", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-seat", params)
// 定义
var response GetSeatResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -26,7 +27,7 @@ func newGetShowDateResult(result GetShowDateResponse, body []byte, http goreques
}
// GetShowDate 包含某电影的日期 https://www.showdoc.com.cn/1154868044931571/6091788579441818
func (c *Client) GetShowDate(cityId, filmId int) *GetShowDateResult {
func (c *Client) GetShowDate(ctx context.Context, cityId, filmId int) *GetShowDateResult {
// 参数
param := gorequest.NewParams()
param.Set("cityId", cityId)
@ -34,7 +35,7 @@ func (c *Client) GetShowDate(cityId, filmId int) *GetShowDateResult {
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-show-date", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-show-date", params)
// 定义
var response GetShowDateResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -48,7 +49,7 @@ func newGetShowListResult(result GetShowListResponse, body []byte, http goreques
}
// GetShowList 包含某电影的影院 https://www.showdoc.com.cn/1154868044931571/6067372188376779
func (c *Client) GetShowList(param GetShowList) *GetShowListResult {
func (c *Client) GetShowList(ctx context.Context, param GetShowList) *GetShowListResult {
// api params
params := map[string]interface{}{}
b, _ := json.Marshal(&param)
@ -57,7 +58,7 @@ func (c *Client) GetShowList(param GetShowList) *GetShowListResult {
for k, v := range m {
params[k] = v
}
request, err := c.request(apiUrl+"/movieapi/movie-info/get-show-list", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-show-list", params)
// 定义
var response GetShowListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -42,14 +43,14 @@ func newGetSoonListResult(result GetSoonListResponse, body []byte, http goreques
}
// GetSoonList 即将上映 https://www.showdoc.com.cn/1154868044931571/5866125707634369
func (c *Client) GetSoonList(cityId int) *GetSoonListResult {
func (c *Client) GetSoonList(ctx context.Context, cityId int) *GetSoonListResult {
// 参数
param := gorequest.NewParams()
param.Set("cityId", cityId)
// 转换
params := gorequest.NewParamsWith(param)
// 请求
request, err := c.request(apiUrl+"/movieapi/movie-info/get-soon-list", params)
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-soon-list", params)
// 定义
var response GetSoonListResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package pintoto
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -24,8 +25,8 @@ func newGetVersionResult(result GetVersionResponse, body []byte, http gorequest.
}
// GetVersion 获取同步版本号 https://www.showdoc.com.cn/1154868044931571/6566701084841699
func (c *Client) GetVersion() *GetVersionResult {
request, err := c.request(apiUrl+"/movieapi/movie-info/get-version", map[string]interface{}{})
func (c *Client) GetVersion(ctx context.Context) *GetVersionResult {
request, err := c.request(ctx, apiUrl+"/movieapi/movie-info/get-version", map[string]interface{}{})
// 定义
var response GetVersionResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,12 +1,14 @@
package pintoto
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"time"
)
// 请求
func (c *Client) request(url string, params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, url string, params map[string]interface{}) (gorequest.Response, error) {
// 公共参数
params["time"] = time.Now().Unix()
@ -28,17 +30,17 @@ func (c *Client) request(url string, params map[string]interface{}) (gorequest.R
client.SetParams(params)
// 发起请求
request, err := client.Post()
request, err := client.Post(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddleware(request)
go c.log.GormMiddleware(ctx, request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddleware(request)
go c.log.MongoMiddleware(ctx, request, go_library.Version())
}
return request, err

@ -1,11 +1,13 @@
package taobao
import (
"context"
"github.com/dtapps/go-library"
"github.com/dtapps/go-library/utils/gorequest"
"github.com/dtapps/go-library/utils/gostring"
)
func (c *Client) request(params map[string]interface{}) (gorequest.Response, error) {
func (c *Client) request(ctx context.Context, params map[string]interface{}) (gorequest.Response, error) {
// 签名
c.Sign(params)
@ -17,17 +19,17 @@ func (c *Client) request(params map[string]interface{}) (gorequest.Response, err
client.SetParams(params)
// 发起请求
request, err := client.Get()
request, err := client.Get(ctx)
if err != nil {
return gorequest.Response{}, err
}
// 日志
if c.config.PgsqlDb != nil {
go c.log.GormMiddlewareCustom(gostring.ToString(params["method"]), request)
go c.log.GormMiddlewareCustom(ctx, gostring.ToString(params["method"]), request, go_library.Version())
}
if c.config.MongoDb != nil {
go c.log.MongoMiddlewareCustom(gostring.ToString(params["method"]), request)
go c.log.MongoMiddlewareCustom(ctx, gostring.ToString(params["method"]), request, go_library.Version())
}
return request, err

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -28,11 +29,11 @@ func newTbkDgNewuserOrderGetResult(result TbkDgNewuserOrderGetResponse, body []b
// TbkDgNewuserOrderGet 淘宝客-推广者-新用户订单明细查询
// https://open.taobao.com/api.htm?docId=33892&docType=2
func (c *Client) TbkDgNewuserOrderGet(notMustParams ...Params) *TbkDgNewuserOrderGetResult {
func (c *Client) TbkDgNewuserOrderGet(ctx context.Context, notMustParams ...Params) *TbkDgNewuserOrderGetResult {
// 参数
params := NewParamsWithType("taobao.tbk.dg.newuser.order.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkDgNewuserOrderGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -82,11 +83,11 @@ func newTbkOrderDetailsGetResult(result TbkOrderDetailsGetResponse, body []byte,
// TbkOrderDetailsGet 淘宝客-推广者-所有订单查询
// https://open.taobao.com/api.htm?docId=43328&docType=2&scopeId=16175
func (c *Client) TbkOrderDetailsGet(notMustParams ...Params) *TbkOrderDetailsGetResult {
func (c *Client) TbkOrderDetailsGet(ctx context.Context, notMustParams ...Params) *TbkOrderDetailsGetResult {
// 参数
params := NewParamsWithType("taobao.tbk.order.details.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkOrderDetailsGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -34,12 +35,12 @@ func newTbkActivityInfoGetResult(result TbkActivityInfoGetResponse, body []byte,
// TbkActivityInfoGet 淘宝客-推广者-官方活动转链
// https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.5a83669a7rURsF&source=search&docId=48340&docType=2
func (c *Client) TbkActivityInfoGet(notMustParams ...Params) *TbkActivityInfoGetResult {
func (c *Client) TbkActivityInfoGet(ctx context.Context, notMustParams ...Params) *TbkActivityInfoGetResult {
// 参数
params := NewParamsWithType("taobao.tbk.activity.info.get", notMustParams...)
params.Set("adzone_id", c.GetAdzoneId())
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkActivityInfoGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -58,11 +59,11 @@ func newTbkCouponGetResult(result TbkCouponGetResponse, body []byte, http gorequ
// TbkCouponGet 淘宝客-公用-阿里妈妈推广券详情查询
// https://open.taobao.com/api.htm?docId=31106&docType=2
func (c *Client) TbkCouponGet(notMustParams ...Params) *TbkCouponGetResult {
func (c *Client) TbkCouponGet(ctx context.Context, notMustParams ...Params) *TbkCouponGetResult {
// 参数
params := NewParamsWithType("taobao.tbk.coupon.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkCouponGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -77,12 +78,12 @@ func newTbkDgMaterialOptionalResult(result TbkDgMaterialOptionalResponse, body [
// TbkDgMaterialOptional 淘宝客-推广者-物料搜索
// https://open.taobao.com/api.htm?docId=35896&docType=2&source=search
func (c *Client) TbkDgMaterialOptional(notMustParams ...Params) *TbkDgMaterialOptionalResult {
func (c *Client) TbkDgMaterialOptional(ctx context.Context, notMustParams ...Params) *TbkDgMaterialOptionalResult {
// 参数
params := NewParamsWithType("taobao.tbk.dg.material.optional", notMustParams...)
params.Set("adzone_id", c.GetAdzoneId())
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkDgMaterialOptionalResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -61,12 +62,12 @@ func newTbkDgOptimusMaterialResult(result TbkDgOptimusMaterialResponse, body []b
// TbkDgOptimusMaterial 淘宝客-推广者-物料精选
// https://open.taobao.com/api.htm?spm=a219a.7386797.0.0.5d67669aIeQeVI&source=search&docId=33947&docType=2
func (c *Client) TbkDgOptimusMaterial(notMustParams ...Params) *TbkDgOptimusMaterialResult {
func (c *Client) TbkDgOptimusMaterial(ctx context.Context, notMustParams ...Params) *TbkDgOptimusMaterialResult {
// 参数
params := NewParamsWithType("taobao.tbk.dg.optimus.material", notMustParams...)
params.Set("adzone_id", c.GetAdzoneId())
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkDgOptimusMaterialResponse
err = json.Unmarshal(request.ResponseBody, &response)

@ -1,6 +1,7 @@
package taobao
import (
"context"
"encoding/json"
"github.com/dtapps/go-library/utils/gorequest"
)
@ -58,11 +59,11 @@ func newTbkItemInfoGetResult(result TbkItemInfoGetResponse, body []byte, http go
// TbkItemInfoGet 淘宝客-公用-淘宝客商品详情查询(简版)
// https://open.taobao.com/api.htm?docId=24518&docType=2&source=search
func (c *Client) TbkItemInfoGet(notMustParams ...Params) *TbkItemInfoGetResult {
func (c *Client) TbkItemInfoGet(ctx context.Context, notMustParams ...Params) *TbkItemInfoGetResult {
// 参数
params := NewParamsWithType("taobao.tbk.item.info.get", notMustParams...)
// 请求
request, err := c.request(params)
request, err := c.request(ctx, params)
// 定义
var response TbkItemInfoGetResponse
err = json.Unmarshal(request.ResponseBody, &response)

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save