miduo_client/Assets/ManagedResources/~Lua/Modules/Net/HttpManager.lua

53 lines
1.7 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base.HttpCrypt")
HttpManager = {}
-- 加密密钥
local CRYPT_KEY = "d53b3e8ef74bf72d8aafce3a1c8671a0"
-- 是否要加密
local isCrypt = AppConst.Platform == "IOS" --or AppConst.Platform == "EDITOR"
-- 计数器
local _Counter = 0
-- GET 请求
function HttpManager:SendGetHttp(url, callback, _, _, failCB)
local request = url
_Counter = _Counter + 1
local count = _Counter
LogWarn("Http请求" .. count.. ""..request)
if isCrypt and ServerConfigManager.GetVersionInfo("channel") == "MHT" then
local urlList = string.split(url, "?")
urlList[2] = HTTP_ENCRYPT(urlList[2], CRYPT_KEY)
request = urlList[1] .. "?crypt=" .. urlList[2]
LogWarn("Http加密请求" .. count.. ""..request)
end
networkMgr:SendGetHttp(request, function(msg)
LogWarn("Http请求" .. count.. "结果:"..msg)
if isCrypt and ServerConfigManager.GetVersionInfo("channel") == "MHT" then
msg = HTTP_DECRYPT(msg, CRYPT_KEY)
LogWarn("Http请求" .. count.. "结果解密:"..msg)
end
if callback then
callback(msg)
end
end, nil, nil, failCB)
end
-- post 请求
function HttpManager:SendPostHttp(url, data,callback, _, _, failCB)
local request = url
_Counter = _Counter + 1
local count = _Counter
LogWarn("Http请求" .. count.. ""..request)
LogError("chanel=="..ServerConfigManager.GetVersionInfo("channel"))
LogError("request=="..request)
networkMgr:SendHttpPost_Json_Lua(request,data,function(msg)
LogError("Http请求" .. count.. "结果:"..msg)
if callback then
callback(msg)
end
end,failCB)
end
return HttpManager