【http】请求加密

dev_chengFeng
JLIOSM1 2021-07-13 18:24:33 +08:00
parent 1ba37dce92
commit 5b311e2ac8
6 changed files with 94 additions and 10 deletions

View File

@ -0,0 +1,55 @@
-- 对字符串进行加密解密
require "Common.BitMath"
function strSplit(input, delimiter)
input = tostring(input)
delimiter = tostring(delimiter)
if (delimiter=='') then return false end
local pos,arr = 0, {}
for st,sp in function() return string.find(input, delimiter, pos, true) end do
table.insert(arr, string.sub(input, pos, st - 1))
pos = sp + 1
end
table.insert(arr, string.sub(input, pos))
return arr
end
function StrToBytes(s)
local t={}
for i=1,string.len(s) do
table.insert(t,string.byte(string.sub(s,i,i)))
end
return t
end
function HTTP_ENCRYPT(src, key)
local data = StrToBytes(src)
local keys = StrToBytes(key)
local sb = ""
for i = 1, #data do
local n = BitMath.andOp(255, data[i]) + BitMath.andOp(255, keys[(i - 1) % #keys + 1])
sb = sb.."@"..n
end
return sb
end
function HTTP_DECRYPT(src, key)
local list = strSplit(src, "@")
if not list or #list < 1 then
return src
end
table.remove(list, 1)
local keys = StrToBytes(key)
local data = ""
for i = 1, #list do
local n = list[i] - BitMath.andOp(255, keys[(i - 1) % #keys + 1])
data = data .. string.char(n)
end
return data
end
-- local t = HTTP_ENCRYPT("fajkfkahsdfjkhkashd", "123")
-- print(t)
-- local data = HTTP_DECRYPT(t, "123")
-- print(data)

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c0a2e12bba84144f48f8b9b64c1e89c4
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,4 +1,4 @@
BattleManager = {}
BattleManager = {}
local this = BattleManager
local PassiveSkillLogicConfig = ConfigManager.GetConfig(ConfigName.PassiveSkillLogicConfig)
local SkillLogicConfig = ConfigManager.GetConfig(ConfigName.SkillLogicConfig)
@ -1014,7 +1014,7 @@ function this.RequestBattleDataByFightId(serverUrl, fightId, func)
local uid = string.split(fightId, "_")[1]
local requestUrl = string.format("http://%s/req/getFightRecord?uid=%s&fightid=%s", serverUrl, uid, fightId)
LogGreen(requestUrl)
networkMgr:SendGetHttp(requestUrl, function(str)
LoginManager:SendGetHttp(requestUrl, function(str)
--LogGreen(str)
local json = require 'cjson'
local data = json.decode(str)

View File

@ -61,7 +61,7 @@ function this.DOGetBindPhone(type, phoneNumber, code)
local sign = Util.MD5Encrypt(string.format("%s%s%s%s%s%s", pid,
gid, type, phoneNumber, time, signKey))
local code = code and code or ""
networkMgr:SendGetHttp(string.format("%s?pid=%s&gid=%s&token=%s&type=%s&phone=%s&code=%s&time=%s&sign=%s",
LoginManager:SendGetHttp(string.format("%s?pid=%s&gid=%s&token=%s&type=%s&phone=%s&code=%s&time=%s&sign=%s",
GetBindUrl, pid, gid, token, type, phoneNumber, code, time, sign), this.OnCodeResult, nil, nil, nil)
end

View File

@ -1,4 +1,4 @@
LoginManager = {};
LoginManager = {};
local this = LoginManager
this.sign = "d13b3e8ef74bf72d8aafce3a1c8672a0"
this.openId = nil
@ -124,7 +124,7 @@ function this.RequestRegist(name, pw, call)
pw, this.sign))
RequestPanel.Show(Language[11132])
networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/registerUser?userName=".. name .. "&password=".. pw .."&repeat=".. pw .. "&sign=" .. sign,
this:SendGetHttp(LoginRoot_Url .. "jl_loginserver/registerUser?userName=".. name .. "&password=".. pw .."&repeat=".. pw .. "&sign=" .. sign,
function(str)
RequestPanel.Hide()
if str == nil then
@ -150,7 +150,7 @@ function this.RequestUser(name, pw, call)
pw, this.sign))
RequestPanel.Show(Language[11134])
networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/userLogin?userName=".. name .. "&password=".. pw .. "&sign=" .. sign, function(str)
this:SendGetHttp(LoginRoot_Url .. "jl_loginserver/userLogin?userName=".. name .. "&password=".. pw .. "&sign=" .. sign, function(str)
RequestPanel.Hide()
if str == nil then
return
@ -179,6 +179,28 @@ function this.RequestUser(name, pw, call)
end,nil,nil,nil)
end
require("Base.HttpCrypt")
local CRYPT_KEY = "d53b3e8ef74bf72d8aafce3a1c8671a0"
function this:SendGetHttp(url, callback)
local request = url
LogGreen("Http请求"..request)
if AppConst.Platform == "IOS" then
local urlList = string.split(url, "?")
urlList[2] = HTTP_ENCRYPT(urlList[2], CRYPT_KEY)
request = urlList[1] .. "?crypt=" .. urlList[2]
LogGreen("Http加密请求"..request)
end
networkMgr:SendGetHttp(request, function(msg)
LogGreen("Http请求结果"..msg)
if AppConst.Platform == "IOS" then
msg = HTTP_DECRYPT(msg, CRYPT_KEY)
LogGreen("Http请求结果解密"..msg)
end
if callback then
callback(msg)
end
end, nil, nil, nil)
end
return this

View File

@ -1,4 +1,4 @@
require("Base/BasePanel")
require("Base/BasePanel")
LoginPanel = Inherit(BasePanel)
local this = LoginPanel
@ -281,7 +281,7 @@ function this.ShowNotice()
if subNoticeID then
LoginRoot_NoticeChannel = LoginRoot_NoticeChannel.. subNoticeID
end
networkMgr:SendGetHttp(LoginRoot_Url .. "jl_loginserver/getNotice?timestamp="..timeStamp.."&sign=".. timeSign.."&packageName="..LoginRoot_NoticeChannel,function (str)
LoginManager:SendGetHttp(LoginRoot_Url .. "jl_loginserver/getNotice?timestamp="..timeStamp.."&sign=".. timeSign.."&packageName="..LoginRoot_NoticeChannel,function (str)
UIManager.OpenPanel(UIName.NoticePopup,str)
end, nil, nil, nil)
end
@ -293,7 +293,7 @@ function this.RequestServerList(userId, callback)
"%sjl_loginserver/getServerList?openId=%s&channel=%s&plat=android&sub_channel=%s&server_version=%s",
LoginRoot_Url, userId, LoginRoot_Channel, LoginRoot_SubChannel, ServerVersion)
Log(url)
networkMgr:SendGetHttp(url, callback, nil, nil, nil)
LoginManager:SendGetHttp(url, callback, nil, nil, nil)
end
@ -646,7 +646,7 @@ function this.RequestHttpLogin()
end
Log(url)
networkMgr:SendGetHttp(url, this.OnReceiveLogin, nil, nil, nil)
LoginManager:SendGetHttp(url, this.OnReceiveLogin, nil, nil, nil)
end
--用户id登录