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

53 lines
1.7 KiB
Lua
Raw Normal View History

2021-11-09 10:49:37 +08:00
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)
2022-07-15 14:31:26 +08:00
if isCrypt and ServerConfigManager.GetVersionInfo("channel") == "MHT" then
2021-11-09 10:49:37 +08:00
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)
2022-07-15 14:31:26 +08:00
if isCrypt and ServerConfigManager.GetVersionInfo("channel") == "MHT" then
2021-11-09 10:49:37 +08:00
msg = HTTP_DECRYPT(msg, CRYPT_KEY)
LogWarn("Http请求" .. count.. "结果解密:"..msg)
end
if callback then
callback(msg)
end
end, nil, nil, failCB)
end
2022-07-15 14:20:47 +08:00
-- 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
2021-11-09 10:49:37 +08:00
return HttpManager