forked from Toulu-debug/enen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jd_api_test.ts
47 lines (41 loc) · 1.47 KB
/
jd_api_test.ts
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
/**
* 网络测试
* 1、测试是否能访问助力池
* 2、助力获取失败、没有统计到运行次数,很大可能因为访问api失败
* 3、如果出现失败,自行更换设备dns
*/
import axios from 'axios'
import {format} from 'date-fns'
import {getRandomNumberByRange, wait} from "./TS_USER_AGENTS"
!(async () => {
console.log(`\n==================脚本执行- 北京时间(UTC+8):${format(Date.now(), 'yyyy-MM-dd HH:mm:ss')}\n\n`)
let cars: string[] = ['bean', 'farm', 'health', 'jxfactory', 'pet']
let db: string = cars[Math.floor(Math.random() * cars.length)]
let num: number = getRandomNumberByRange(5, 20)
console.log(`本次随机选择${db}获取${num}个随机助力码`)
await car(db, num)
let times = getRandomNumberByRange(3, 6)
console.log(`开始测试${times}次上报`)
for (let i = 0; i < times; i++) {
console.log(`第${i + 1}次上报测试`)
await runTimes()
await wait(getRandomNumberByRange(2000, 6000))
}
})()
async function car(db: string, num: number) {
try {
let {data} = await axios.get(`https://api.jdsharecode.xyz/api/${db}/${num}`)
console.log('获取助力池成功')
console.log(data)
} catch (e: any) {
console.log(`获取助力池失败:`, e)
}
}
async function runTimes() {
try {
let {data} = await axios.get(`https://api.jdsharecode.xyz/api/runTimes?activityId=bean&sharecode=123`)
console.log('测试成功', data)
} catch (e: any) {
console.log('测试失败', e)
}
}