Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
location share white
Commits
e80d426b
Commit
e80d426b
authored
Oct 22, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
e441a352
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
223 additions
and
0 deletions
+223
-0
AESHelper.kt
...main/java/com/base/locationsharewhite/helper/AESHelper.kt
+62
-0
ReportUtils.java
.../java/com/base/locationsharewhite/helper/ReportUtils.java
+56
-0
LocationRequestUtils.kt
.../base/locationsharewhite/location/LocationRequestUtils.kt
+105
-0
No files found.
app/src/main/java/com/base/locationsharewhite/helper/AESHelper.kt
0 → 100644
View file @
e80d426b
package
com.base.locationsharewhite.helper
import
android.util.Base64
import
java.security.SecureRandom
import
javax.crypto.Cipher
import
javax.crypto.spec.GCMParameterSpec
import
javax.crypto.spec.SecretKeySpec
object
AESHelper
{
private
const
val
aesKey
=
"7vwdrlk6bp8rihe4"
private
val
cipher
by
lazy
{
Cipher
.
getInstance
(
"AES/GCM/NoPadding"
)
}
fun
encrypt
(
content
:
String
):
String
{
try
{
val
iv
=
ByteArray
(
12
).
apply
{
SecureRandom
().
nextBytes
(
this
)
}
val
contentBytes
=
content
.
toByteArray
(
Charsets
.
UTF_8
)
val
params
=
GCMParameterSpec
(
128
,
iv
)
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
secretKey
,
params
)
val
encryptData
=
cipher
.
doFinal
(
contentBytes
)
if
(
encryptData
.
size
!=
contentBytes
.
size
+
16
)
{
throw
IllegalStateException
(
"Encryption failed"
)
}
val
message
=
ByteArray
(
12
+
contentBytes
.
size
+
16
)
System
.
arraycopy
(
iv
,
0
,
message
,
0
,
12
)
System
.
arraycopy
(
encryptData
,
0
,
message
,
12
,
encryptData
.
size
)
return
String
(
Base64
.
encode
(
message
,
Base64
.
NO_WRAP
),
Charsets
.
UTF_8
)
}
catch
(
_
:
Exception
)
{
}
return
content
}
@Synchronized
fun
decrypt
(
content
:
String
):
String
{
try
{
val
con
=
content
.
replace
(
" "
.
toRegex
(),
"+"
)
val
contentByte
=
Base64
.
decode
(
con
,
Base64
.
NO_WRAP
)
require
(
contentByte
.
size
>=
12
+
16
)
val
params
=
GCMParameterSpec
(
128
,
contentByte
,
0
,
12
)
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
secretKey
,
params
)
val
decryptData
=
cipher
.
doFinal
(
contentByte
,
12
,
contentByte
.
size
-
12
)
return
String
(
decryptData
,
Charsets
.
UTF_8
)
}
catch
(
_
:
Exception
)
{
}
return
content
}
private
val
secretKey
by
lazy
{
SecretKeySpec
(
aesKey
.
toByteArray
(),
"AES"
)
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/helper/ReportUtils.java
0 → 100644
View file @
e80d426b
package
com
.
base
.
locationsharewhite
.
helper
;
import
android.text.TextUtils
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Map
;
import
com.base.locationsharewhite.utils.LogEx
;
public
class
ReportUtils
{
private
static
String
TAG
=
"ReportUtils"
;
public
static
String
doPost
(
String
urlPath
,
Map
<
String
,
String
>
paramsMap
,
String
json
)
{
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
urlPath
).
openConnection
();
conn
.
setRequestMethod
(
"POST"
);
conn
.
setDoOutput
(
true
);
conn
.
setConnectTimeout
(
600000
);
if
(!
TextUtils
.
isEmpty
(
json
))
{
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"Content-Length"
,
Integer
.
toString
(
json
.
getBytes
().
length
));
conn
.
getOutputStream
().
write
(
json
.
getBytes
());
}
StringBuilder
result
=
new
StringBuilder
();
for
(
Map
.
Entry
<
String
,
String
>
entry
:
paramsMap
.
entrySet
())
{
result
.
append
(
"&"
).
append
(
entry
.
getKey
()).
append
(
"="
).
append
(
entry
.
getValue
());
}
if
(
result
.
length
()
>
0
)
{
conn
.
getOutputStream
().
write
(
result
.
substring
(
1
).
getBytes
());
}
else
{
// conn.getOutputStream().write(result.substring(0).getBytes());
}
if
(
conn
.
getResponseCode
()
==
200
)
{
String
s
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
())).
readLine
();
if
(!
TextUtils
.
isEmpty
(
s
))
{
}
else
{
s
=
""
;
}
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"code=200"
,
false
);
return
s
;
}
else
{
LogEx
.
INSTANCE
.
logDebug
(
TAG
,
"code!=200"
,
false
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
"{ \"success\": false,\n \"errorMsg\": \"后台服务器开小差了!\",\n \"result\":{}}"
;
}
}
app/src/main/java/com/base/locationsharewhite/location/LocationRequestUtils.kt
0 → 100644
View file @
e80d426b
package
com.base.locationsharewhite.location
import
android.os.Build
import
com.base.locationsharewhite.BuildConfig
import
com.base.locationsharewhite.helper.AESHelper
import
com.base.locationsharewhite.helper.ConfigHelper
import
com.base.locationsharewhite.helper.ReportUtils.doPost
import
com.base.locationsharewhite.utils.AppPreferences
import
com.base.locationsharewhite.utils.LogEx
import
org.json.JSONObject
object
LocationRequestUtils
{
var
invitationCodeSp
=
""
get
()
{
return
AppPreferences
.
getInstance
().
getString
(
"invitationCodeSp"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"invitationCodeSp"
,
value
,
true
)
}
var
nickNameSp
=
""
get
()
{
return
AppPreferences
.
getInstance
().
getString
(
"nickNameSp"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"nickNameSp"
,
value
,
true
)
}
var
uIdSp
=
""
get
()
{
return
AppPreferences
.
getInstance
().
getString
(
"uIdSp"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"uIdSp"
,
value
,
true
)
}
private
val
TAG
=
"LocationRequestUtils"
private
const
val
DATA_KEY
=
"data"
private
val
url
by
lazy
{
val
pkg
=
ConfigHelper
.
packageName
val
url
=
StringBuilder
(
"${ConfigHelper.eventUrl}/dingwei/${pkg.filter { it.isLowerCase() }.substring(4, 9)}v"
)
url
.
toString
()
}
fun
login
(
name
:
String
)
{
Thread
{
val
pkg
=
ConfigHelper
.
packageName
val
data
=
JSONObject
()
data
.
put
(
"nickName"
,
name
)
val
bp
=
JSONObject
()
// .put("${pkg}_1", "")
.
put
(
"${pkg}_5"
,
Build
.
VERSION
.
SDK_INT
)
.
put
(
"${pkg}_8"
,
BuildConfig
.
VERSION_NAME
)
.
put
(
"${pkg}_9"
,
AppPreferences
.
getInstance
().
getString
(
"uuid"
,
""
))
.
put
(
"${pkg}_10"
,
AppPreferences
.
getInstance
().
getString
(
"gid"
,
""
))
.
put
(
"${pkg}_13"
,
"android"
)
.
put
(
"${pkg}_14"
,
BuildConfig
.
VERSION_CODE
)
.
put
(
"${pkg}_15"
,
"google"
)
.
put
(
"${pkg}_24"
,
BuildConfig
.
BUILD_TYPE
)
val
body
=
JSONObject
()
.
put
(
"data"
,
data
)
.
put
(
"bp"
,
bp
)
.
toString
()
val
paramJson
=
AESHelper
.
encrypt
(
body
)
LogEx
.
logDebug
(
TAG
,
"url=$url"
)
val
result
=
doPost
(
url
,
HashMap
(),
paramJson
)
val
responseData
=
extractData
(
result
)
if
(
responseData
!=
null
)
{
val
decryptedData
=
AESHelper
.
decrypt
(
responseData
)
parseLoginData
(
decryptedData
)
}
}.
start
()
}
private
fun
extractData
(
response
:
String
):
String
?
{
val
regex
=
Regex
(
"\"$DATA_KEY\":\"(.*?)\""
)
val
match
=
regex
.
find
(
response
)
return
match
?.
groupValues
?.
get
(
1
)
}
private
fun
parseLoginData
(
json
:
String
)
{
val
data
:
JSONObject
=
JSONObject
(
json
)
val
invitationCode
=
data
.
getString
(
"invitationCode"
)
invitationCodeSp
=
invitationCode
val
nickName
=
data
.
getString
(
"nickName"
)
nickNameSp
=
nickName
val
uId
=
data
.
getString
(
"uId"
)
uIdSp
=
uId
LogEx
.
logDebug
(
TAG
,
"invitationCode=$invitationCode nickName=$nickName uId=$uId"
)
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment