Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sdk-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Odysseus
sdk-api
Commits
f4bd8fc5
Commit
f4bd8fc5
authored
Jul 23, 2024
by
贾浩@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update v2 api
parent
a94f0866
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
2 deletions
+92
-2
router.go
server/router.go
+4
-2
user.go
server/user.go
+88
-0
No files found.
server/router.go
View file @
f4bd8fc5
...
...
@@ -17,8 +17,10 @@ func initRouter(e *gin.Engine) {
user
.
POST
(
"/serverLogin"
,
login
)
user
.
POST
(
"/create"
,
middleware
.
JWTMiddleware
,
createUser
)
}
v2
:=
e
.
Group
(
"/api/v2"
)
{
v1
.
GET
(
"/task/status"
,
getTaskStatus
)
user
:=
v2
.
Group
(
"/user"
)
user
.
POST
(
"/serverLogin"
,
loginV2
)
}
}
server/user.go
View file @
f4bd8fc5
...
...
@@ -203,3 +203,91 @@ func login(c *gin.Context) {
c
.
JSON
(
200
,
withSuccess
(
resp
))
return
}
func
loginV2
(
c
*
gin
.
Context
)
{
req
:=
&
apiModel
.
LoginRequest
{}
if
err
:=
c
.
ShouldBindJSON
(
req
);
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
var
platformId
string
switch
req
.
Platform
{
case
constant
.
PlatformTelegram
:
var
ok
bool
var
userId
string
var
botId
string
for
_
,
token
:=
range
conf
.
TGBot
.
Tokens
{
ok
,
botId
,
userId
=
util
.
VerifyInitData
(
req
.
InitData
,
token
)
if
ok
{
break
}
}
if
!
ok
{
c
.
JSON
(
200
,
withError
(
"invalid initData"
))
return
}
_
=
botId
// platformId = fmt.Sprintf("%s:%s", botId, userId)
platformId
=
fmt
.
Sprintf
(
"v2:%s"
,
userId
)
case
constant
.
PlatformFingerprint
:
if
len
(
req
.
VisitorID
)
<=
10
{
c
.
JSON
(
200
,
withError
(
constant
.
InvalidParam
))
return
}
platformId
=
req
.
VisitorID
default
:
c
.
JSON
(
200
,
withError
(
constant
.
UnsupportedPlatform
))
return
}
// 检查签名是否为keystore中的地址
address
:=
gjson
.
Get
(
req
.
Keystore
,
"address"
)
.
String
()
binSignature
,
err
:=
hexutil
.
Decode
(
req
.
Signature
)
if
err
!=
nil
||
len
(
binSignature
)
<
65
{
c
.
JSON
(
200
,
withError
(
"invalid signature"
))
return
}
binSignature
[
64
]
-=
27
ecdsaPub
,
err
:=
crypto
.
SigToPub
(
accounts
.
TextHash
([]
byte
(
req
.
Keystore
)),
binSignature
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
"invalid signature"
))
return
}
addr
:=
crypto
.
PubkeyToAddress
(
*
ecdsaPub
)
if
strings
.
ToLower
(
addr
.
Hex
()[
2
:
])
!=
address
{
c
.
JSON
(
200
,
withError
(
"invalid signature"
))
return
}
isExistKeystore
,
uid
,
keystore
,
err
:=
srv
.
CheckUser
(
req
.
Platform
,
platformId
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
token
:=
util
.
GenerateJWT
(
uid
,
req
.
Platform
,
platformId
)
resp
:=
&
apiModel
.
CheckUserResponse
{
IsNewUser
:
!
isExistKeystore
,
Keystore
:
keystore
,
Token
:
token
,
Uid
:
uid
,
}
if
!
isExistKeystore
{
_
,
err
=
srv
.
SetKeystore
(
uid
,
address
,
req
.
Keystore
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
resp
.
Keystore
=
req
.
Keystore
}
taskId
,
err
:=
srv
.
AONServerLogin
(
address
,
req
.
UserId
,
req
.
InviterId
)
if
err
!=
nil
{
c
.
JSON
(
200
,
withError
(
constant
.
InternalError
))
return
}
resp
.
TaskId
=
taskId
c
.
JSON
(
200
,
withSuccess
(
resp
))
return
}
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