lb.hbs
3.43 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
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
local cjson = require "cjson"
local aes = require "resty.aes"
local upt = require "url_process_tool"
local icutil = require "iconfig_util"
--5b2d8b4b242e067616c6cd98851b2306 close
--2a90dfa0f37b92aaebf369e9a4d38ba4 open
local open_dl = "{@{open_dl}@}"
local close_dl = "5b2d8b4b242e067616c6cd98851b2306"
local function common_lb ()
local response_table = {
code = 200,
ae = "e0323a9039add2978bf5b49550572c7c",
url = "http://m.yohobuy.com",
tl = "352f028bd6ecf28de1c285c573642659",
rp = "17d7a40f313560d4d9a1189a91e45ab9",
dl = open_dl,
dli = open_dl,
dlwi = open_dl
}
return response_table
end
function lb()
ngx.log (ngx.INFO, "----- lb START ----- ")
-- args error --
local args = ngx.var.args
if not args then
icutil.error_response ("40011","args not found")
ngx.log (ngx.ERROR, "- 40011 - args : ", args, "---")
return
end
local url_args = upt.url_args_decrypt(args)
if not url_args then
icutil.error_response ("40012","args not found")
ngx.log (ngx.ERROR, "- 40012 - args : ", args, "---")
return
end
-- args parse --
ngx.req.set_uri_args(url_args)
local uri_args = ngx.req.get_uri_args()
--for k,v in pairs(uri_args) do ngx.log(ngx.INFO," k = ", k, " v = ", v) end
local uid = uri_args["uid"]
local app_ver = uri_args["app_ver"]
local os = uri_args["os"]
local udid = uri_args["udid"]
local osversion = uri_args["osv"]
ngx.log (ngx.INFO, "5、--- uid : ", uid, " app_ver :", app_ver, " os :", os, "---")
local result
-- ios
local ios_lb = {
["4.8.1"] = function()
return common_lb()
end,
["4.9.2"] = function()
local response_table = common_lb()
response_table.dli = "2a90dfa0f37b92aaebf369e9a4d38ba4"
return response_table
end
,
["5.0.0"] = function()
local response_table = common_lb()
if osversion == "7" then
response_table.dli = close_dl
else
response_table.dli = open_dl
end
return response_table
end
}
-- anopen_stringdroid
local android_lb = {
["4.8.1"] = function()
return common_lb()
end,
["5.0.0"] = function()
local response_table = common_lb()
local dla_value = { dlw = open_dl, dlp = close_dl }
response_table.dla = dla_value
return response_table
end
}
-- switch 0:ios 1:android
if os == "0" then
ngx.log (ngx.INFO, "----- 1. enter ios lb ----- ")
if ios_lb[app_ver] ~= nil and ios_lb[app_ver]() ~= nil then
result = ios_lb[app_ver]()
ngx.log (ngx.INFO, "----- 2. app_ver found ----- ")
else
result = common_lb()
ngx.log (ngx.INFO, "----- 2. app_ver not found ----- ")
end
elseif os == "1" then
ngx.log (ngx.INFO, "----- enter android lb ----- ")
if android_lb[app_ver] ~= nil and android_lb[app_ver]() ~= nil then
result = android_lb[app_ver]()
ngx.log (ngx.INFO, "----- 2. app_ver found ----- ")
else
result = common_lb()
ngx.log (ngx.INFO, "----- 2. app_ver not found ----- ")
end
else
result = icutil.error_response ("40013","os error")
ngx.log (ngx.ERR, "- 40013 - enter error lb ----- ")
ngx.log (ngx.ERR, "- 40013 - uid : ", uid, " app_ver :", app_ver, " os :", os, "---")
end
--response
ngx.header["Content-type"]="text/plain;charset=utf-8"
local result_json = cjson.encode(result)
local resultstr = upt.url_args_encrypt (result_json)
ngx.log (ngx.INFO, string.format ("--- response %s ---",resultstr))
ngx.say(resultstr)
ngx.log (ngx.INFO, "----- lb OVER ----- ")
end
lb()