Impl Forward Message
This commit is contained in:
parent
059eb1197f
commit
21f63ee545
@ -12,6 +12,23 @@
|
||||
|
||||
4、浏览器打开 `http://localhost:7600` 查看支持的接口
|
||||
|
||||
## 配置说明
|
||||
|
||||
```yml
|
||||
httpd:
|
||||
address: 127.0.0.1:7600 # api 监听地址
|
||||
token: "" # 使用 token 验证请求
|
||||
logger:
|
||||
dir: logs # 日志目录
|
||||
level: info # 日志级别
|
||||
target: stdout # 日志输出方式
|
||||
wcf:
|
||||
address: 127.0.0.1:10080 # rpc 监听地址
|
||||
sdklibrary: libs/sdk.dll # sdk 依赖库
|
||||
wechatauto: true # 自动启动或停止微信
|
||||
msgprint: true # 打印收到的消息
|
||||
```
|
||||
|
||||
## 功能清单
|
||||
|
||||
- 检查登录状态
|
||||
@ -40,8 +57,8 @@
|
||||
- 获取群成员昵称
|
||||
- 邀请群成员
|
||||
- 拍一拍群友
|
||||
- 开启消息转发
|
||||
- 停止消息转发
|
||||
- 转发消息给好友
|
||||
- 转发收到的消息到URL
|
||||
|
||||
## 生成 OpenApi 文档
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package wcfrest
|
||||
|
||||
import (
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -13,14 +14,18 @@ import (
|
||||
)
|
||||
|
||||
var wc *wcferry.Client
|
||||
var forwardUrls = map[string]bool{}
|
||||
|
||||
func initService() {
|
||||
|
||||
parts := strings.Split(args.Wcf.Address, ":")
|
||||
host, port, err := net.SplitHostPort(args.Wcf.Address)
|
||||
if err != nil {
|
||||
logman.Fatal("failed to start wcf", "error", err)
|
||||
}
|
||||
|
||||
wc = &wcferry.Client{
|
||||
ListenAddr: parts[0],
|
||||
ListenPort: strutil.ToInt(parts[1]),
|
||||
ListenAddr: host,
|
||||
ListenPort: strutil.ToInt(port),
|
||||
SdkLibrary: args.Wcf.SdkLibrary,
|
||||
WeChatAuto: args.Wcf.WeChatAuto,
|
||||
}
|
||||
@ -283,6 +288,27 @@ func revokeMsg(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// @Summary 转发消息
|
||||
// @Produce json
|
||||
// @Param body body wcferry.ForwardMsg true "转发消息请求参数"
|
||||
// @Success 200 {object} RespPayload
|
||||
// @Router /forward_msg [post]
|
||||
func forwardMsg(c *gin.Context) {
|
||||
|
||||
var req wcferry.ForwardMsg
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.Set("Error", err)
|
||||
return
|
||||
}
|
||||
|
||||
status := wc.CmdClient.ForwardMsg(req.Id, req.Receiver)
|
||||
|
||||
c.Set("Payload", RespPayload{
|
||||
Success: status == 1,
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
// @Summary 发送文本消息
|
||||
// @Produce json
|
||||
// @Param body body wcferry.TextMsg true "文本消息请求参数"
|
||||
@ -534,7 +560,7 @@ func receiveTransfer(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// @Summary 开启消息转发
|
||||
// @Summary 开启转发消息到URL
|
||||
// @Produce json
|
||||
// @Param body body ForwardMsgRequest true "消息转发请求参数"
|
||||
// @Success 200 {object} RespPayload
|
||||
@ -552,11 +578,20 @@ func enableForwardMsg(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, ok := forwardUrls[req.Url]; ok {
|
||||
c.Set("Error", "url already exists")
|
||||
return
|
||||
}
|
||||
|
||||
err := wc.EnrollReceiver(true, func(msg *wcferry.WxMsg) {
|
||||
logman.Info("forward msg", "url", req.Url, "Id", msg.Id)
|
||||
request.JsonPost(req.Url, msg, request.H{})
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
forwardUrls[req.Url] = true
|
||||
}
|
||||
|
||||
c.Set("Payload", RespPayload{
|
||||
Success: err == nil,
|
||||
Error: err,
|
||||
@ -564,7 +599,7 @@ func enableForwardMsg(c *gin.Context) {
|
||||
|
||||
}
|
||||
|
||||
// @Summary 关闭消息转发
|
||||
// @Summary 关闭转发消息到URL
|
||||
// @Produce json
|
||||
// @Param body body ForwardMsgRequest true "消息转发请求参数"
|
||||
// @Success 200 {object} RespPayload
|
||||
|
@ -30,6 +30,7 @@ func Route(rg *gin.RouterGroup) {
|
||||
rg.POST("del_chatroom_members", delChatRoomMembers)
|
||||
|
||||
rg.GET("revoke_msg/:msgid", revokeMsg)
|
||||
rg.POST("forward_msg", forwardMsg)
|
||||
rg.POST("send_txt", sendTxt)
|
||||
rg.POST("send_img", sendImg)
|
||||
rg.POST("send_file", sendFile)
|
||||
|
5
clients/gohttp/public/assets/image/icon.svg
Normal file
5
clients/gohttp/public/assets/image/icon.svg
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg version="1.1" width="160" height="160" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<path
|
||||
d="m 133.19656,100.76048 c -4.65698,0.18313 -9.34964,0.70676 -13.95132,1.61149 -1.23893,0.23402 -2.5871,0.61836 -3.82856,1.0658 -0.64877,2.16647 -1.20763,4.36035 -1.79204,6.54542 1.58555,-0.30164 3.15751,-0.66922 4.73692,-1.00089 -0.61371,8.95742 -1.27989,17.91144 -1.99384,26.86171 -0.29442,3.62953 -0.52943,7.26341 -0.75616,10.89788 1.86774,-0.3579 3.55939,-1.29744 5.38281,-1.81763 1.27468,-0.42814 2.55455,-0.84488 3.80692,-1.33534 0.31406,-0.69306 0.1844,-1.52113 0.31831,-2.269 0.32993,-3.64635 0.65961,-7.29274 0.98978,-10.93908 2.7618,0.3073 5.57164,0.4131 8.31393,-0.12062 4.80385,-0.85929 9.45139,-3.20292 12.62313,-6.96543 2.55696,-3.1713 3.25843,-7.42864 3.05047,-11.39782 -0.10968,-3.07735 -1.47498,-6.16018 -3.95971,-8.04266 -3.08122,-2.33261 -7.0554,-2.8864 -10.80923,-3.07292 -0.71003,-0.0286 -1.42093,-0.0345 -2.13141,-0.0208 z m -0.40793,6.55367 c 2.41792,-0.009 5.14573,0.77883 6.45773,2.9691 1.10267,1.89282 0.79124,4.19106 0.49122,6.25738 -0.56573,3.40307 -3.15192,6.12911 -6.14793,7.64676 -1.519,0.73784 -3.24968,1.32799 -4.95463,1.0606 -1.2847,-0.20548 -1.93156,-1.60186 -1.77353,-2.7952 0.3007,-3.52247 0.57505,-7.04776 0.94908,-10.56363 0.12937,-0.83562 0.0553,-1.89107 0.36811,-2.75357 0.69887,-1.36058 2.39457,-1.67662 3.78561,-1.78204 0.27361,-0.0292 0.54966,-0.032 0.82434,-0.0393 z m -49.59709,-5.76679 c -1.177219,0.0152 -2.290464,0.0446 -3.406471,0.10975 -2.200556,0.0982 -4.570882,0.38716 -6.280955,1.91972 -2.294143,2.05844 -4.51393,4.20067 -6.779415,6.2914 2.032068,-0.34075 4.027356,-0.85809 6.035092,-1.31471 -0.29277,4.42 -0.583247,8.87329 -0.930953,13.24535 -0.247701,3.58438 -0.608065,7.18985 -0.865832,10.7856 -0.197329,2.45578 -0.299965,4.92062 -0.603051,7.36657 -1.182286,2.26098 -2.366388,4.521 -3.549373,6.78162 4.255462,0.0251 8.527429,0.0413 12.750612,-0.56007 6.773416,-0.89346 13.542359,-3.03099 19.074356,-7.13985 3.50579,-2.61935 6.21384,-6.26482 7.70233,-10.38067 1.32963,-3.69497 1.66725,-7.71313 1.26404,-11.60479 -0.38504,-3.63318 -2.20178,-7.07468 -4.99795,-9.42894 -2.3182,-2.05977 -4.964601,-3.82061 -7.963403,-4.70352 -3.686463,-1.19181 -7.599161,-1.43469 -11.449027,-1.36751 z m 2.274305,6.29932 c 3.134894,-0.0473 6.255769,1.4461 8.091177,4.00535 2.54448,3.501 3.754103,7.91422 3.431022,12.22534 -0.226322,4.14823 -1.236859,8.49082 -4.054824,11.67783 -2.576486,2.9221 -6.459033,4.43752 -10.304517,4.56919 -1.051815,0.0491 -2.105697,0.0482 -3.1583,0.0775 0.928832,-9.24255 1.484356,-18.51758 2.433733,-27.75794 0.121951,-1.23355 0.244303,-2.46709 0.365783,-3.7007 1.013568,-0.47883 2.038785,-1.10465 3.195926,-1.09668 z m -24.695317,-6.55434 c -6.616793,0.30247 -13.247083,0.59067 -19.822764,0.9827 -2.93934,0.16726 -5.878891,0.33118 -8.818307,0.49714 -0.939787,2.46811 -1.879559,4.93619 -2.819346,7.40428 3.678262,0.014 7.357493,-0.0451 11.034605,0.0727 -0.310173,4.62265 -0.461625,9.25797 -0.996882,13.86248 -0.577369,7.54214 -1.162189,15.08413 -1.672169,22.63031 3.114046,-1.09029 6.210004,-2.23218 9.316888,-3.3429 1.026749,-11.05353 2.082729,-22.10437 3.083613,-33.15981 3.507509,0.003 7.015208,-0.005 10.522592,0.003 0.834619,-1.78324 1.394282,-3.69399 2.119057,-5.52802 0.394904,-1.11279 0.836468,-2.39191 1.298175,-3.551 -1.081817,0.043 -2.16364,0.0859 -3.245462,0.12887 z m -39.28928,44.37272 C 10.397706,140.70341 6.3360532,121.72682 13.320607,107.53765 22.554039,88.779899 43.351122,78.588439 69.210903,80.148932 c 6.22913,0.375816 13.96527,0.694936 17.19144,0.708996 3.226156,0.01519 5.86543,0.0874 5.865084,0.162644 -0.005,0.953525 -10.29208,2.919739 -20.225093,3.865549 -27.253018,2.594993 -44.443892,11.736712 -52.420422,27.876019 -7.053434,14.27163 -1.767181,32.39927 9.462007,32.44701 2.179213,0.008 2.608039,0.21013 1.700552,0.79658 -1.719469,1.11122 -6.446537,0.93806 -9.303241,-0.34086 z M 78.514084,77.146886 C 65.119128,75.809604 63.292384,75.17957 70.828794,74.496338 105.03532,71.395227 126.34754,64.306892 134.8055,53.217996 c 2.77337,-3.636068 2.71149,-3.660615 -6.62342,-2.627369 -19.34773,2.141583 -35.197284,7.519706 -45.678459,15.499815 -5.65313,4.304141 -6.193784,4.444816 -3.369456,0.876576 12.153145,-15.354163 31.900745,-24.116341 58.894295,-26.131842 13.84256,-1.033551 12.81731,-1.410848 11.17819,4.113611 -6.98636,23.546803 -34.01928,35.859399 -70.692566,32.198099 z M 67.217444,69.080518 C 67.036566,51.005964 83.478129,29.343522 107.27263,16.306046 c 8.416,-4.611291 8.04996,-4.856276 8.04977,5.387472 -2e-4,9.674321 -1.76661,14.279227 -8.12002,21.168179 -4.00687,4.344647 -4.01654,4.293006 -0.68287,-3.640402 2.0729,-4.933034 3.6287,-14.561528 2.35291,-14.561528 -6.42277,0 -32.466361,27.807852 -38.917446,41.553832 -2.592261,5.523548 -2.709703,5.646553 -2.73753,2.866919 z" />
|
||||
</svg>
|
After Width: | Height: | Size: 4.8 KiB |
@ -1,12 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<html lang="zh-Hans-CN">
|
||||
|
||||
<head>
|
||||
<title>WeChat Rest API</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta http-equiv="Content-Security-Policy" />
|
||||
<link rel="shortcut icon" href="/assets/img/icon.png">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui.min.css">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
|
||||
<link rel="shortcut icon" type="image/svg" href="assets/image/icon.svg" />
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui.min.css" />
|
||||
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist/swagger-ui-bundle.min.js"></script>
|
||||
<title>WeChat Rest API</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
@ -274,7 +274,7 @@
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "关闭消息转发",
|
||||
"summary": "关闭转发消息到URL",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "消息转发请求参数",
|
||||
@ -355,7 +355,7 @@
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "开启消息转发",
|
||||
"summary": "开启转发消息到URL",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "消息转发请求参数",
|
||||
@ -377,6 +377,33 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/forward_msg": {
|
||||
"post": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "转发消息",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "转发消息请求参数",
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/wcferry.ForwardMsg"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/wcfrest.RespPayload"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/friends": {
|
||||
"get": {
|
||||
"produces": [
|
||||
@ -796,6 +823,19 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"wcferry.ForwardMsg": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "待转发消息 ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"receiver": {
|
||||
"description": "转发接收目标,群为 roomId,个人为 wxid",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"wcferry.MemberMgmt": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
Loading…
Reference in New Issue
Block a user