forked from opq-osc/OPQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApi_GetUrl.lua
72 lines (71 loc) · 1.75 KB
/
Api_GetUrl.lua
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
local http = require("http")
local json = require("json")
function GetUrl(data)
local index = GenRandInt(1, 2)
if index == 1 then
return GetYZFUrl(data)
end
if index == 2 then
return GetBJHUrl(data)
end
end
function GetYZFUrl(data)
local userid = string.format("kfh53e531627f2ee4c_h552fdfc072182654f163f5f%d", os.time())
response, error_message =
http.request(
"POST",
string.format("https://yzf.qq.com/fsna/kf-file/upload_wx_media?_t=%d", os.time()),
{
multipart = {
["userid"] = userid,
["agentid"] = "",
["media_type"] = "image",
["mid"] = "fsna"
},
file = {
["file"] = "./22.jpg",
["body"] = data
}
}
)
jsonData = json.decode(response.body)
if jsonData["code"] ~= 0 then
return nil
end
return UrlDecode(jsonData["KfPicUrl"])
end
function GetBJHUrl(data)
response, error_message =
http.request(
"POST",
"https://baijiahao.baidu.com/builderinner/api/content/file/upload",
{
multipart = {},
file = {
["media"] = "22222.jpg",
["body"] = data
}
}
)
jsonData = json.decode(response.body)
if jsonData.errno ~= 0 then
return nil
end
return jsonData.ret.https_url
end
function UrlDecode(s)
s =
string.gsub(
s,
"%%(%x%x)",
function(h)
return string.char(tonumber(h, 16))
end
)
return s
end
function GenRandInt(x, y)
math.randomseed(tonumber(tostring(os.time()):reverse():sub(1, 6)))
num = math.random(x, y)
return num
end