-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcookie_func.lua
More file actions
37 lines (29 loc) · 830 Bytes
/
cookie_func.lua
File metadata and controls
37 lines (29 loc) · 830 Bytes
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
require "ngx" --ngx库
local config = require "config"
local tools = require "tools"
local ck = require "resty.cookie"
ngx.header["P3P"] = 'CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"'
function doSetCookie()
--参数
local args = ngx.req.get_uri_args()
local did = args['did']
if not did then
ngx.log(ngx.ERR, string.format("not have did param in request, remoteIp : %s", tools.getRealIp()))
local resStr = tools.jsonp('0')
tools.jsonpSay(resStr)
return
end
local did = ngx.escape_uri(did)
--设置加密cookie
local cookie, err = ck:new()
local ok, err = cookie:set({
key = config.deviceIdCookieName,
value = did,
path = "/",
httponly = true
})
local resStr = tools.jsonp('1')
tools.jsonpSay(resStr)
return
end
doSetCookie()