-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.lua
More file actions
68 lines (54 loc) · 1.71 KB
/
Copy pathplayer.lua
File metadata and controls
68 lines (54 loc) · 1.71 KB
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
local json = require "json"
local Player = {
_version = "0.0.1",
}
function Player.new(idx)
local obj = { user_id = 0, idx = idx, access_token = "" }
return setmetatable(obj, { __index = Player })
end
function Player:get_request(robot_id)
local i = self.idx
self.idx = i + 1
return self.fun[i](self, robot_id)
end
function Player:restart()
self.idx = 2
end
function Player:is_end()
return self.idx > #self.fun
end
local function login(_, robot_id)
return "GET", string.format("/auth/v1/inner/access_token?platform=wechat&open_id=robot_%d&app_id=1001", robot_id),
{ ["X-Robot-Index"] = robot_id, }, nil
end
local function login_result(p, data)
p.user_id = data.userId
p.access_token = data.accessToken
end
local function user_info(p, robot_id)
return "GET", string.format("/auth/v1/player/info?user_id=%d", p.user_id), { ["X-Robot-Index"] = robot_id, }, nil
end
local function user_info_result(p, data)
if data.userId ~= p.user_id then
end
end
local function verify_token(p, robot_id)
return "GET", string.format("/auth/v1/token/authentication?access_token=%s&user_id=%d", p.access_token, p.user_id),
{ ["X-Robot-Index"] = robot_id, }, nil
end
local function verify_token_result(p, data)
if data == nil then
end
end
Player.fun = { [1] = login, [2] = user_info, [3] = verify_token, } -- 发起request
local switch = { [2] = login_result, [3] = user_info_result, [4] = verify_token_result, } -- 处理response
function Player.parse_rsp(self, body)
local rsp = json.decode(body)
if rsp.errCode == 0 then
local fun = switch[self.idx]
if fun then
fun(self, rsp.data)
end
end
end
return Player