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
15085d0a
Commit
15085d0a
authored
Aug 24, 2020
by
scjtqs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开放自由xml的支持接口,方便开发者自行设计和调用
parent
84a82681
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
180 additions
and
0 deletions
+180
-0
.gitignore
.gitignore
+1
-0
coolq/api.go
coolq/api.go
+98
-0
docs/cqhttp.md
docs/cqhttp.md
+56
-0
server/http.go
server/http.go
+25
-0
No files found.
.gitignore
View file @
15085d0a
vendor/
vendor/
.idea
coolq/api.go
View file @
15085d0a
...
@@ -622,3 +622,101 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
...
@@ -622,3 +622,101 @@ func convertGroupMemberInfo(groupId int64, m *client.GroupMemberInfo) MSG {
"card_changeable"
:
false
,
"card_changeable"
:
false
,
}
}
}
}
func
(
bot
*
CQBot
)
Send_private_msg_xml
(
userId
int64
,
i
interface
{},
ResId
int64
)
MSG
{
var
str
string
if
m
,
ok
:=
i
.
(
gjson
.
Result
);
ok
{
if
m
.
Type
==
gjson
.
JSON
{
elem
:=
bot
.
ConvertObjectMessage
(
m
,
true
)
mid
:=
bot
.
SendPrivateMessage
(
userId
,
&
message
.
SendingMessage
{
Elements
:
elem
})
if
mid
==
-
1
{
return
Failed
(
100
)
}
return
OK
(
MSG
{
"message_id"
:
mid
})
}
str
=
func
()
string
{
if
m
.
Str
!=
""
{
return
m
.
Str
}
return
m
.
Raw
}()
}
else
if
s
,
ok
:=
i
.
(
string
);
ok
{
str
=
s
}
if
str
==
""
{
return
Failed
(
100
)
}
var
elem
[]
message
.
IMessageElement
println
(
str
)
elem
=
append
(
elem
,
NewXmlMsg
(
str
,
ResId
))
mid
:=
bot
.
SendPrivateMessage
(
userId
,
&
message
.
SendingMessage
{
Elements
:
elem
})
if
mid
==
-
1
{
return
Failed
(
100
)
}
return
OK
(
MSG
{
"message_id"
:
mid
})
}
func
NewXmlMsg
(
template
string
,
ResId
int64
)
*
message
.
ServiceElement
{
var
serviceid
string
if
ResId
==
0
{
serviceid
=
"2"
//默认值2
}
else
{
serviceid
=
strconv
.
FormatInt
(
ResId
,
10
)
}
//println(serviceid)
return
&
message
.
ServiceElement
{
Id
:
int32
(
ResId
),
Content
:
template
,
ResId
:
serviceid
,
SubType
:
"xml"
,
}
}
func
(
bot
*
CQBot
)
CQSendGroupMessage_XML
(
groupId
int64
,
i
interface
{},
ResId
int64
)
MSG
{
var
str
string
fixAt
:=
func
(
elem
[]
message
.
IMessageElement
)
{
for
_
,
e
:=
range
elem
{
if
at
,
ok
:=
e
.
(
*
message
.
AtElement
);
ok
&&
at
.
Target
!=
0
{
at
.
Display
=
"@"
+
func
()
string
{
mem
:=
bot
.
Client
.
FindGroup
(
groupId
)
.
FindMember
(
at
.
Target
)
if
mem
!=
nil
{
return
mem
.
DisplayName
()
}
return
strconv
.
FormatInt
(
at
.
Target
,
10
)
}()
}
}
}
if
m
,
ok
:=
i
.
(
gjson
.
Result
);
ok
{
if
m
.
Type
==
gjson
.
JSON
{
elem
:=
bot
.
ConvertObjectMessage
(
m
,
true
)
fixAt
(
elem
)
mid
:=
bot
.
SendGroupMessage
(
groupId
,
&
message
.
SendingMessage
{
Elements
:
elem
})
if
mid
==
-
1
{
return
Failed
(
100
)
}
return
OK
(
MSG
{
"message_id"
:
mid
})
}
str
=
func
()
string
{
if
m
.
Str
!=
""
{
return
m
.
Str
}
return
m
.
Raw
}()
}
else
if
s
,
ok
:=
i
.
(
string
);
ok
{
str
=
s
}
if
str
==
""
{
return
Failed
(
100
)
}
var
elem
[]
message
.
IMessageElement
println
(
str
)
elem
=
append
(
elem
,
NewXmlMsg
(
str
,
ResId
))
//fixAt(elem)
mid
:=
bot
.
SendGroupMessage
(
groupId
,
&
message
.
SendingMessage
{
Elements
:
elem
})
if
mid
==
-
1
{
return
Failed
(
100
)
}
return
OK
(
MSG
{
"message_id"
:
mid
})
}
docs/cqhttp.md
View file @
15085d0a
...
@@ -258,3 +258,59 @@ Type: `node`
...
@@ -258,3 +258,59 @@ Type: `node`
|
`user_id`
| int64 | | 好友id |
|
`user_id`
| int64 | | 好友id |
|
`message_id`
| int64 | | 被撤回的消息id |
|
`message_id`
| int64 | | 被撤回的消息id |
## 自定义xml结构化消息发送,请自行承担风险
### 发送好友消息
终结点:
`/send_private_msg_xml`
或者
`send_private_msg_xml_async`
**参数**
| 字段 | 类型 | 说明 |
| -------- | ------ | ---- |
| user_id | int64 | qq号 |
| message | string | xml数据 |
| serviceid | int | 服务Id,一般xml中也有,不填默认为2 |
### 发送群消息
终结点:
`/send_group_msg_xml`
或者
`send_group_msg_xml_async`
**参数**
| 字段 | 类型 | 说明 |
| -------- | ------ | ---- |
| group_id | int64 | 群号 |
| message | string | xml数据 |
| serviceid | int | 服务Id,一般xml中也有,不填默认为2 |
###一些xml样例
#### qq音乐
```
xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<msg
serviceID=
"2"
templateID=
"1"
action=
"web"
brief=
"[分享] 十年"
sourceMsgId=
"0"
url=
"https://i.y.qq.com/v8/playsong.html?_wv=1&songid=4830342&souce=qqshare&source=qqshare&ADTAG=qqshare"
flag=
"0"
adverSign=
"0"
multiMsgFlag=
"0"
><item
layout=
"2"
><audio
cover=
"http://imgcache.qq.com/music/photo/album_500/26/500_albumpic_89526_0.jpg"
src=
"http://ws.stream.qqmusic.qq.com/C400003mAan70zUy5O.m4a?guid=1535153710&vkey=D5315B8C0603653592AD4879A8A3742177F59D582A7A86546E24DD7F282C3ACF81526C76E293E57EA1E42CF19881C561275D919233333ADE&uin=&fromtag=3"
/><title>
十年
</title><summary>
陈奕迅
</summary></item><source
name=
"QQ音乐"
icon=
"https://i.gtimg.cn/open/app_icon/01/07/98/56/1101079856_100_m.png"
url=
"http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856"
action=
"app"
a_actionData=
"com.tencent.qqmusic"
i_actionData=
"tencent1101079856://"
appid=
"1101079856"
/></msg>
```
#### 网易音乐
```
xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<msg
serviceID=
"2"
templateID=
"1"
action=
"web"
brief=
"[分享] 十年"
sourceMsgId=
"0"
url=
"http://music.163.com/m/song/409650368"
flag=
"0"
adverSign=
"0"
multiMsgFlag=
"0"
><item
layout=
"2"
><audio
cover=
"http://p2.music.126.net/g-Qgb9ibk9Wp_0HWra0xQQ==/16636710440565853.jpg?param=90y90"
src=
"https://music.163.com/song/media/outer/url?id=409650368.mp3"
/><title>
十年
</title><summary>
黄梦之
</summary></item><source
name=
"网易云音乐"
icon=
"https://pic.rmb.bdstatic.com/911423bee2bef937975b29b265d737b3.png"
url=
"http://web.p.qq.com/qqmpmobile/aio/app.html?id=1101079856"
action=
"app"
a_actionData=
"com.netease.cloudmusic"
i_actionData=
"tencent100495085://"
appid=
"100495085"
/></msg>
```
#### 卡片消息1
```
xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<msg
serviceID=
"1"
>
<item><title>
生死8秒!女司机高速急刹,他一个操作救下一车性命
</title></item>
<source
name=
"官方认证消息"
icon=
"https://qzs.qq.com/ac/qzone_v5/client/auth_icon.png"
action=
""
appid=
"-1"
/>
</msg>
```
#### 卡片消息2
```
xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<msg
serviceID=
"1"
>
<item
layout=
"4"
>
<title>
test title
</title>
<picture
cover=
"http://url.cn/5CEwIUy"
/>
</item>
</msg>
```
\ No newline at end of file
server/http.go
View file @
15085d0a
...
@@ -155,6 +155,10 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
...
@@ -155,6 +155,10 @@ func (s *httpServer) Run(addr, authToken string, bot *coolq.CQBot) {
s
.
engine
.
Any
(
"/get_version_info_async"
,
s
.
GetVersionInfo
)
s
.
engine
.
Any
(
"/get_version_info_async"
,
s
.
GetVersionInfo
)
s
.
engine
.
Any
(
"/.handle_quick_operation"
,
s
.
HandleQuickOperation
)
s
.
engine
.
Any
(
"/.handle_quick_operation"
,
s
.
HandleQuickOperation
)
s
.
engine
.
Any
(
"/send_private_msg_xml"
,
s
.
Send_private_msg_xml
)
s
.
engine
.
Any
(
"/send_private_msg_xml_async"
,
s
.
Send_private_msg_xml
)
s
.
engine
.
Any
(
"/send_group_msg_xml"
,
s
.
SendGroupMessage_xml
)
s
.
engine
.
Any
(
"/send_group_msg_xml_async"
,
s
.
SendGroupMessage_xml
)
go
func
()
{
go
func
()
{
log
.
Infof
(
"CQ HTTP 服务器已启动: %v"
,
addr
)
log
.
Infof
(
"CQ HTTP 服务器已启动: %v"
,
addr
)
...
@@ -400,6 +404,7 @@ func getParamOrDefault(c *gin.Context, k, def string) string {
...
@@ -400,6 +404,7 @@ func getParamOrDefault(c *gin.Context, k, def string) string {
return
def
return
def
}
}
func
getParam
(
c
*
gin
.
Context
,
k
string
)
string
{
func
getParam
(
c
*
gin
.
Context
,
k
string
)
string
{
p
,
_
:=
getParamWithType
(
c
,
k
)
p
,
_
:=
getParamWithType
(
c
,
k
)
return
p
return
p
...
@@ -439,3 +444,23 @@ func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
...
@@ -439,3 +444,23 @@ func getParamWithType(c *gin.Context, k string) (string, gjson.Type) {
}
}
return
""
,
gjson
.
Null
return
""
,
gjson
.
Null
}
}
func
(
s
*
httpServer
)
Send_private_msg_xml
(
c
*
gin
.
Context
)
{
uid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"user_id"
),
10
,
64
)
msg
,
t
:=
getParamWithType
(
c
,
"message"
)
resId
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"serviceid"
),
10
,
64
)
if
t
==
gjson
.
JSON
{
c
.
JSON
(
200
,
s
.
bot
.
Send_private_msg_xml
(
uid
,
gjson
.
Parse
(
msg
),
resId
))
return
}
c
.
JSON
(
200
,
s
.
bot
.
Send_private_msg_xml
(
uid
,
msg
,
resId
))
}
func
(
s
*
httpServer
)
SendGroupMessage_xml
(
c
*
gin
.
Context
)
{
gid
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"group_id"
),
10
,
64
)
msg
,
t
:=
getParamWithType
(
c
,
"message"
)
resId
,
_
:=
strconv
.
ParseInt
(
getParam
(
c
,
"serviceid"
),
10
,
64
)
if
t
==
gjson
.
JSON
{
c
.
JSON
(
200
,
s
.
bot
.
CQSendGroupMessage_XML
(
gid
,
gjson
.
Parse
(
msg
),
resId
))
return
}
c
.
JSON
(
200
,
s
.
bot
.
CQSendGroupMessage_XML
(
gid
,
msg
,
resId
))
}
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