lb.hbs 3.43 KB
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()