Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
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
nanahira
go-cqhttp
Commits
cdbf9033
Commit
cdbf9033
authored
Aug 11, 2020
by
Mrs4s
Committed by
GitHub
Aug 11, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #74 from Shigma/api-type-check
sendXXX api type check
parents
906247fc
72a74308
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
server/http.go
server/http.go
+17
-12
No files found.
server/http.go
View file @
cdbf9033
...
@@ -235,8 +235,8 @@ func (s *httpServer) SendMessage(c *gin.Context) {
...
@@ -235,8 +235,8 @@ func (s *httpServer) SendMessage(c *gin.Context) {
func
(
s
*
httpServer
)
SendPrivateMessage
(
c
*
gin
.
Context
)
{
func
(
s
*
httpServer
)
SendPrivateMessage
(
c
*
gin
.
Context
)
{
uid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"user_id"
),
10
,
64
)
uid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"user_id"
),
10
,
64
)
msg
:=
getParam
(
c
,
"message"
)
msg
,
t
:=
getParamWithType
(
c
,
"message"
)
if
gjson
.
Valid
(
msg
)
{
if
t
==
gjson
.
JSON
{
c
.
JSON
(
200
,
s
.
bot
.
CQSendPrivateMessage
(
uid
,
gjson
.
Parse
(
msg
)))
c
.
JSON
(
200
,
s
.
bot
.
CQSendPrivateMessage
(
uid
,
gjson
.
Parse
(
msg
)))
return
return
}
}
...
@@ -245,8 +245,8 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
...
@@ -245,8 +245,8 @@ func (s *httpServer) SendPrivateMessage(c *gin.Context) {
func
(
s
*
httpServer
)
SendGroupMessage
(
c
*
gin
.
Context
)
{
func
(
s
*
httpServer
)
SendGroupMessage
(
c
*
gin
.
Context
)
{
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
msg
:=
getParam
(
c
,
"message"
)
msg
,
t
:=
getParamWithType
(
c
,
"message"
)
if
gjson
.
Valid
(
msg
)
{
if
t
==
gjson
.
JSON
{
c
.
JSON
(
200
,
s
.
bot
.
CQSendGroupMessage
(
gid
,
gjson
.
Parse
(
msg
)))
c
.
JSON
(
200
,
s
.
bot
.
CQSendGroupMessage
(
gid
,
gjson
.
Parse
(
msg
)))
return
return
}
}
...
@@ -372,14 +372,19 @@ func getParamOrDefault(c *gin.Context, k, def string) string {
...
@@ -372,14 +372,19 @@ func getParamOrDefault(c *gin.Context, k, def string) string {
}
}
func
getParam
(
c
*
gin
.
Context
,
k
string
)
string
{
func
getParam
(
c
*
gin
.
Context
,
k
string
)
string
{
p
,
_
:=
getParamWithType
(
c
,
k
)
return
p
}
func
getParamWithType
(
c
*
gin
.
Context
,
k
string
)
(
string
,
gjson
.
Type
)
{
if
q
:=
c
.
Query
(
k
);
q
!=
""
{
if
q
:=
c
.
Query
(
k
);
q
!=
""
{
return
q
return
q
,
gjson
.
Null
}
}
if
c
.
Request
.
Method
==
"POST"
{
if
c
.
Request
.
Method
==
"POST"
{
if
h
:=
c
.
Request
.
Header
.
Get
(
"Content-Type"
);
h
!=
""
{
if
h
:=
c
.
Request
.
Header
.
Get
(
"Content-Type"
);
h
!=
""
{
if
h
==
"application/x-www-form-urlencoded"
{
if
h
==
"application/x-www-form-urlencoded"
{
if
p
,
ok
:=
c
.
GetPostForm
(
k
);
ok
{
if
p
,
ok
:=
c
.
GetPostForm
(
k
);
ok
{
return
p
return
p
,
gjson
.
Null
}
}
}
}
if
h
==
"application/json"
{
if
h
==
"application/json"
{
...
@@ -388,20 +393,20 @@ func getParam(c *gin.Context, k string) string {
...
@@ -388,20 +393,20 @@ func getParam(c *gin.Context, k string) string {
if
res
.
Exists
()
{
if
res
.
Exists
()
{
switch
res
.
Type
{
switch
res
.
Type
{
case
gjson
.
JSON
:
case
gjson
.
JSON
:
return
res
.
Raw
return
res
.
Raw
,
gjson
.
JSON
case
gjson
.
String
:
case
gjson
.
String
:
return
res
.
Str
return
res
.
Str
,
gjson
.
String
case
gjson
.
Number
:
case
gjson
.
Number
:
return
strconv
.
FormatInt
(
res
.
Int
(),
10
)
// 似乎没有需要接受 float 类型的api
return
strconv
.
FormatInt
(
res
.
Int
(),
10
)
,
gjson
.
Number
// 似乎没有需要接受 float 类型的api
case
gjson
.
True
:
case
gjson
.
True
:
return
"true"
return
"true"
,
gjson
.
True
case
gjson
.
False
:
case
gjson
.
False
:
return
"false"
return
"false"
,
gjson
.
False
}
}
}
}
}
}
}
}
}
}
}
}
return
""
return
""
,
gjson
.
Null
}
}
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