-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjd_test.go
350 lines (307 loc) · 8.96 KB
/
jd_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package jd
import (
"encoding/json"
"fmt"
"github.com/cliod/jd-go/common"
"github.com/cliod/jd-go/log"
"io/ioutil"
"os"
"testing"
"time"
)
type LocalConfig struct {
AppKey string `json:"app_key"`
SecretKey string `json:"secret_key"`
}
// 获取测试配置信息
func GetConfig() LocalConfig {
var c LocalConfig
f, err := os.Open("./config.json")
if err != nil {
f, err := os.Create("./config.json")
if err != nil {
panic(err)
}
b, err := json.Marshal(c)
if err != nil {
panic(err)
}
_, _ = f.Write(b)
return c
}
b, err := ioutil.ReadAll(f)
if err != nil {
fmt.Println(err)
}
_ = json.Unmarshal(b, &c)
return c
}
// 签名测试
func TestParameter_AttachSign(t *testing.T) {
c := GetConfig()
param := map[string]interface{}{}
param["goodsReq"] = &GoodsJingfenQueryRequest{
EliteId: 33,
}
p := newParameter(NewConfig(c.AppKey, c.SecretKey), param)
p.Method = "jd.union.open.goods.jingfen.query"
p.attachSign()
r, _ := json.Marshal(param)
b, err := common.NewService().Get(BaseUrl, Param{
ParamJson: string(r),
AppKey: p.AppKey,
Method: p.Method,
AccessToken: p.AccessToken,
Timestamp: p.Timestamp,
Format: p.Format,
Version: p.Version,
SignMethod: p.SignMethod,
Sign: p.Sign,
})
t.Log(string(b), err)
}
// 优惠券领取情况查询接口【申请】
func TestCouponServiceImpl_CouponQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
couponService := service.GetCouponService()
res, err := couponService.CouponQueryByList("https://coupon.m.jd.com/coupons/show.action?linkKey=AAROH_xIpeffAs_-naABEFoe_GDEC4dVfVg03Fj3h8FXrH2uMMS7Y_UectztQMsMX3S6kCZX2ZFNkNK1ppUHnuinop15Fw")
t.Log(res, err)
}
// 礼金创建
func TestGiftServiceImpl_CouponGiftGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
giftService := service.GetGiftService()
res, err := giftService.CouponGiftGet(&CouponGiftGetRequest{
SkuMaterialId: "",
Discount: 0,
Amount: 0,
ReceiveStartTime: "",
ReceiveEndTime: "",
IsSpu: 0,
ExpireType: 0,
Share: 0,
})
t.Log(res, err)
}
// 礼金停止
func TestGiftServiceImpl_CouponGiftStop(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
giftService := service.GetGiftService()
res, err := giftService.CouponGiftStopBy("")
t.Log(res, err)
}
// 礼金效果数据
func TestGiftServiceImpl_GiftStatisticCouponQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
giftService := service.GetGiftService()
res, err := giftService.StatisticGiftCouponQuery(&StatisticGiftCouponQueryRequest{
SkuId: 0,
GiftCouponKey: "",
StartTime: "",
CreateTime: "",
})
t.Log(res, err)
}
// 商品类目查询接口
func TestGoodsServiceImpl_CategoryGoodsGetQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
goodsService := service.GetGoodsService()
res, err := goodsService.CategoryGoodsGetQuery(&CategoryGoodsGetRequest{
ParentId: 0,
Grade: 0,
})
t.Log(res, err)
}
// 获取商品列表
func TestGoodsServiceImpl_GoodsGigfieldQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
goodsService := service.GetGoodsService()
// 商品详情查询
res, err := goodsService.GoodsGigfieldQuery(&GoodsGigFieldQueryRequest{
SkuIds: []uint64{63682765730},
})
t.Log(res, err)
}
// 获取商品列表
func TestGoodsServiceImpl_GoodsJingfenQuery(t *testing.T) {
config := GetConfig()
service := NewJosService(config.AppKey, config.SecretKey, "")
log.FileLog("logs/", "jd-go.log", 7, 1*time.Hour, 24*time.Minute)
goodsService := service.GetGoodsService()
res, err := goodsService.GoodsJingfenQuery(&GoodsJingfenQueryRequest{
EliteId: 33,
})
t.Log(res, err)
r, err := res.ResponseBody()
t.Log(r, err)
}
// 根据skuid获取商品详情
func TestGoodsServiceImpl_GoodsPromotiongoodsinfoQuery(t *testing.T) {
config := GetConfig()
service := NewJosService(config.AppKey, config.SecretKey, "")
goodsService := service.GetGoodsService()
// 商品详情查询
res, err := goodsService.GoodsPromotiongoodsinfoQueryMap(
"63682765730",
)
t.Log(res, err)
}
// 关键字获取商品
func TestGoodsServiceImpl_GoodsQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
goodsService := service.GetGoodsService()
log.SetLevel(6)
res, err := goodsService.GoodsQuery(&GoodsQueryRequest{})
t.Log(res, err)
}
// 奖励订单查询接口【申请】
func TestOrderServiceImpl_OrderBonusQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
orderService := service.GetOrderService()
res, err := orderService.OrderBonusQuery(&OrderBonusQueryRequest{
OptType: 1,
StartTime: 0,
EndTime: 9999999999999,
PageSize: 10,
})
t.Log(res, err)
}
// 订单查询接口
func TestOrderServiceImpl_OrderQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
orderService := service.GetOrderService()
res, err := orderService.OrderQuery(&OrderQueryRequest{
PageNo: 1,
PageSize: 10,
Type: 1,
Time: "20201117090000",
})
t.Log(res, err)
}
// 订单行查询接口
func TestOrderServiceImpl_OrderRowQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
orderService := service.GetOrderService()
res, err := orderService.OrderRowQuery(&OrderRowQueryRequest{
PageSize: 10,
PageIndex: 1,
Type: 1,
StartTime: "2020-11-30 16:00:00",
EndTime: "2020-11-30 16:30:00",
})
t.Log(res, err)
}
// 活动查询接口
func TestOtherServiceImpl_ActivityQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
otherService := service.GetOtherService()
res, err := otherService.ActivityQuery(&ActivityQueryRequest{})
t.Log(res, err)
}
// 创建推广位【申请】
func TestOtherServiceImpl_PositionCreate(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
otherService := service.GetOtherService()
res, err := otherService.PositionCreate(&PositionCreateRequest{
UnionId: 0,
Key: "",
UnionType: 1,
Type: 1,
SpaceNameList: []string{""},
})
t.Log(res, err)
}
// 查询推广位【申请】
func TestOtherServiceImpl_PositionQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
otherService := service.GetOtherService()
res, err := otherService.PositionQuery(&PositionQueryRequest{
UnionId: 0,
Key: "",
UnionType: 1,
PageIndex: 1,
PageSize: 10,
})
t.Log(res, err)
}
// 京享红包效果数据
func TestOtherServiceImpl_StatisticsRedpacketQuery(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
otherService := service.GetOtherService()
res, err := otherService.StatisticsRedpacketQuery(&StatisticsRedpacketQueryRequest{
StartDate: "",
EndDate: "",
PageIndex: 1,
PageSize: 10,
})
t.Log(res, err)
}
// 获取PID【申请】
func TestOtherServiceImpl_UserPidGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
otherService := service.GetOtherService()
res, err := otherService.UserPidGet(&UserPidGetRequest{
UnionId: 0,
ChildUnionId: 0,
PositionName: "",
PromotionType: 1,
})
t.Log(res, err)
}
// 社交媒体获取推广链接接口【申请】
func TestPromotionServiceImpl_PromotionBysubunionidGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
promoteService := service.GetPromoteService()
res, err := promoteService.PromotionBysubunionidGet(&PromotionBysubunionidGetRequest{
MaterialId: "",
})
t.Log(res, err)
}
// 工具商获取推广链接接口【申请】
func TestPromotionServiceImpl_PromotionByunionidGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
promoteService := service.GetPromoteService()
res, err := promoteService.PromotionByunionidGet(&PromotionByunionidGetRequest{
MaterialId: "",
UnionId: 0,
})
t.Log(res, err)
}
// 网站/APP获取推广链接接口
func TestPromotionServiceImpl_PromotionCommonGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
promoteService := service.GetPromoteService()
res, err := promoteService.PromotionCommonGet(&PromoteCommonGetRequest{
MaterialId: "1",
SiteId: "1",
})
t.Log(res, err)
}
// 通过小程序获取推广链接【申请】
func TestPromotionServiceImpl_PromotionAppletGet(t *testing.T) {
config := GetConfig()
service := NewJdService(config.AppKey, config.SecretKey)
promoteService := service.GetPromoteService()
res, err := promoteService.PromotionAppletGet(&PromotionAppletGetRequest{
Type: 1,
})
t.Log(res, err)
}