Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
d62e4e00
Commit
d62e4e00
authored
Mar 02, 2022
by
liusheng
Browse files
Options
Browse Files
Download
Plain Diff
合并
parents
2ac9369d
5a00e8be
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
72 deletions
+56
-72
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
+42
-60
core/src/main/java/com/github/shadowsocks/http/FreshToken.kt
core/src/main/java/com/github/shadowsocks/http/FreshToken.kt
+5
-7
core/src/main/java/com/github/shadowsocks/http/LineConfig.kt
core/src/main/java/com/github/shadowsocks/http/LineConfig.kt
+9
-5
No files found.
core/src/main/java/com/github/shadowsocks/bg/AuthManager.kt
View file @
d62e4e00
...
@@ -5,9 +5,7 @@ import android.util.Log
...
@@ -5,9 +5,7 @@ import android.util.Log
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.Core
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.http.FreshToken
import
com.github.shadowsocks.http.*
import
com.github.shadowsocks.http.HttpConfig
import
com.github.shadowsocks.http.LineConfig
import
com.google.gson.Gson
import
com.google.gson.Gson
import
com.google.gson.JsonStreamParser
import
com.google.gson.JsonStreamParser
import
com.google.gson.reflect.TypeToken
import
com.google.gson.reflect.TypeToken
...
@@ -19,7 +17,6 @@ import okhttp3.OkHttpClient
...
@@ -19,7 +17,6 @@ import okhttp3.OkHttpClient
import
okhttp3.Request
import
okhttp3.Request
import
okhttp3.RequestBody
import
okhttp3.RequestBody
import
okhttp3.RequestBody.Companion.toRequestBody
import
okhttp3.RequestBody.Companion.toRequestBody
import
okhttp3.Response
import
timber.log.Timber
import
timber.log.Timber
import
java.io.File
import
java.io.File
import
java.io.IOException
import
java.io.IOException
...
@@ -79,7 +76,7 @@ object AuthManager {
...
@@ -79,7 +76,7 @@ object AuthManager {
MMKV
.
defaultMMKV
().
putLong
(
"ACC_TIME"
,
acc_time
)
MMKV
.
defaultMMKV
().
putLong
(
"ACC_TIME"
,
acc_time
)
}
}
var
Last_ACC_TIme
:
Long
var
Last_ACC_TIme
:
Long
get
()
=
MMKV
.
defaultMMKV
().
decodeLong
(
"LAST_ACC_TIME"
,
0L
)
get
()
=
MMKV
.
defaultMMKV
().
decodeLong
(
"LAST_ACC_TIME"
,
0L
)
set
(
last_acc_time
)
{
set
(
last_acc_time
)
{
MMKV
.
defaultMMKV
().
putLong
(
"LAST_ACC_TIME"
,
last_acc_time
)
MMKV
.
defaultMMKV
().
putLong
(
"LAST_ACC_TIME"
,
last_acc_time
)
...
@@ -89,19 +86,19 @@ object AuthManager {
...
@@ -89,19 +86,19 @@ object AuthManager {
suspend
fun
initAuthProfile
(
profile
:
Profile
)
{
suspend
fun
initAuthProfile
(
profile
:
Profile
)
{
withContext
(
Dispatchers
.
IO
)
{
withContext
(
Dispatchers
.
IO
)
{
getLineConfig
()
?.
let
{
val
gameId
:
Int
=
gameId
?.
toInt
()
?:
throw
AuthException
(
"游戏不存在"
)
if
(
it
.
code
==
1001
){
//vip过期
val
lineConfigResult
=
postSync
<
LineConfig
>(
"/api/acc/line"
,
LineConfigReq
(
gameId
,
area
))
throw
AuthException
(
it
.
error
)
if
(
lineConfigResult
.
isSuccessful
())
{
}
else
if
(
it
.
code
!=
200
)
{
val
lineConfig
=
lineConfigResult
.
unwrapData
()
throw
AuthException
(
it
.
error
)
profile
.
host
=
lineConfig
.
host
}
profile
.
token
=
lineConfig
.
token
profile
.
host
=
it
.
data
.
host
profile
.
remotePort
=
lineConfig
.
port
profile
.
token
=
it
.
data
.
token
profile
.
remotePort
=
it
.
data
.
port
Timber
.
d
(
"start vpn with games: ${profile.individual}, profileId: ${profile.id}, route: ${profile.route}"
)
Timber
.
d
(
"start vpn with games: ${profile.individual}, profileId: ${profile.id}, route: ${profile.route}"
)
ProfileManager
.
updateProfile
(
profile
)
ProfileManager
.
updateProfile
(
profile
)
}
?:
let
{
}
else
if
(
lineConfigResult
.
code
==
1001
)
{
throw
AuthException
(
"未知错误"
)
throw
AuthException
(
lineConfigResult
.
error
!!
)
}
else
{
throw
AuthException
(
lineConfigResult
.
error
!!
)
}
}
}
}
}
}
...
@@ -120,12 +117,19 @@ object AuthManager {
...
@@ -120,12 +117,19 @@ object AuthManager {
if
(
data
.
state
==
BaseService
.
State
.
Connected
)
{
if
(
data
.
state
==
BaseService
.
State
.
Connected
)
{
data
.
proxy
?.
let
{
proxyInstance
->
data
.
proxy
?.
let
{
proxyInstance
->
getToken
(
proxyInstance
.
profile
.
token
?:
""
)
?.
let
{
val
refreshTokenResult
=
postSync
<
RefreshTokenRes
>(
if
(
it
.
code
==
200
)
{
"/api/acc/line/refresh"
,
proxyInstance
.
profile
.
token
=
it
.
data
.
token
RefreshTokenReq
(
proxyInstance
.
profile
.
token
?:
""
)
configJson
.
addProperty
(
"token"
,
it
.
data
.
token
)
)
Timber
.
d
(
"refreshTokenResult: $refreshTokenResult"
)
if
(
refreshTokenResult
.
isSuccessful
())
{
proxyInstance
.
profile
.
token
=
refreshTokenResult
.
unwrapData
().
token
configJson
.
addProperty
(
"token"
,
proxyInstance
.
profile
.
token
)
configFile
.
writeText
(
configJson
.
toString
())
configFile
.
writeText
(
configJson
.
toString
())
}
}
else
if
(
refreshTokenResult
.
code
==
1001
)
{
throw
AuthException
(
refreshTokenResult
.
error
!!
)
}
else
{
// TODO: error handling
}
}
}
}
}
}
...
@@ -133,53 +137,31 @@ object AuthManager {
...
@@ -133,53 +137,31 @@ object AuthManager {
},
1
,
1
,
TimeUnit
.
MINUTES
)
},
1
,
1
,
TimeUnit
.
MINUTES
)
}
}
fun
getToken
(
token
:
String
):
FreshToken
?
{
val
map
=
mapOf
(
Pair
(
"token"
,
token
))
return
postSync
<
FreshToken
>(
"/api/acc/line/refresh"
,
map
)
}
val
jsonType
get
()
=
"application/json; charset=utf-8"
.
toMediaTypeOrNull
()
val
jsonType
get
()
=
"application/json; charset=utf-8"
.
toMediaTypeOrNull
()
private
fun
getLineConfig
(
):
LineConfig
?
{
val
map
=
mutableMapOf
<
String
,
String
>()
area
?.
let
{
map
.
put
(
"area"
,
it
)
}
gameId
?.
let
{
map
.
put
(
"gameId"
,
it
)
}
return
postSync
<
LineConfig
>(
"/api/acc/line"
,
map
)
}
inline
fun
<
reified
T
>
postSync
(
inline
fun
<
reified
T
>
postSync
(
url
:
String
,
url
:
String
,
map
:
Map
<
String
,
String
>
params
:
Any
):
T
?
{
):
ApiResult
<
T
>
{
try
{
val
body
:
RequestBody
=
gson
.
toJson
(
params
).
toString
().
toRequestBody
(
jsonType
)
val
body
:
RequestBody
=
gson
.
toJson
(
map
).
toString
().
toRequestBody
(
jsonType
)
val
request
=
Request
.
Builder
()
val
request
=
Request
.
Builder
()
.
url
(
HttpConfig
.
baseUrl
+
url
)
.
url
(
HttpConfig
.
baseUrl
+
url
)
.
post
(
body
)
.
post
(
body
)
authToken
?.
let
{
authToken
?.
let
{
request
.
addHeader
(
"Authorization"
,
it
)
request
.
addHeader
(
"Authorization"
,
it
)
}
}
val
call
=
okHttpClient
.
newCall
(
request
.
build
())
val
call
=
okHttpClient
.
newCall
(
request
.
build
())
val
response
:
Response
=
call
.
execute
()
val
resultType
=
object
:
TypeToken
<
ApiResult
<
T
>>()
{}.
type
if
(
response
.
isSuccessful
)
{
try
{
call
.
execute
().
use
{
response
->
val
string
=
response
.
body
?.
string
()
val
string
=
response
.
body
?.
string
()
Log
.
e
(
"postSync"
,
"=====url:"
+
HttpConfig
.
baseUrl
+
url
)
Log
.
e
(
"postSync"
,
"=====result:"
+
string
)
println
(
string
)
println
(
string
)
val
type
=
object
:
TypeToken
<
T
>()
{}.
type
return
gson
.
fromJson
(
string
,
resultType
)
return
gson
.
fromJson
(
string
,
type
)
}
}
return
null
}
catch
(
e
:
IOException
)
{
}
catch
(
e
:
java
.
lang
.
Exception
)
{
Timber
.
e
(
e
,
"AuthManager 调用接口错误"
)
println
(
e
)
return
ApiResult
(
ApiError
.
NetworkError
)
}
}
return
null
}
}
private
fun
initSSLSocketFactory
():
SSLSocketFactory
{
private
fun
initSSLSocketFactory
():
SSLSocketFactory
{
...
...
core/src/main/java/com/github/shadowsocks/http/FreshToken.kt
View file @
d62e4e00
package
com.github.shadowsocks.http
package
com.github.shadowsocks.http
data class
FreshToken
(
data class
RefreshTokenReq
(
val
code
:
Int
,
val
token
:
String
val
error
:
String
?,
val
`data`
:
Token
)
)
data class
Token
(
data class
RefreshTokenRes
(
val
token
:
String
?
val
token
:
String
)
)
core/src/main/java/com/github/shadowsocks/http/LineConfig.kt
View file @
d62e4e00
package
com.github.shadowsocks.http
package
com.github.shadowsocks.http
data class
LineConfig
(
//data class LineConfig(
val
code
:
Int
,
// val code: Int,
val
`data`
:
Data
,
// val `data`: Data
val
error
:
String
//)
data class
LineConfigReq
(
val
gameId
:
Int
,
val
area
:
String
?,
)
)
data class
Data
(
data class
LineConfig
(
val
host
:
String
,
val
host
:
String
,
val
method
:
String
,
val
method
:
String
,
val
port
:
Int
,
val
port
:
Int
,
...
...
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