-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
开发微信报警功能并添加微信报警说明文档
- Loading branch information
Showing
20 changed files
with
223 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/astaxie/beego" | ||
weixin "github.com/chanyipiaomiao/weixin-kit" | ||
) | ||
|
||
var ( | ||
corpID = beego.AppConfig.String("weixin::corpID") | ||
appSecret = beego.AppConfig.String("weixin::warningAppSecret") | ||
accessTokenAPI = beego.AppConfig.String("weixin::accessTokenAPI") | ||
sendMessageAPIURL = beego.AppConfig.String("weixin::sendMessageAPIURL") | ||
) | ||
|
||
// SendWeixinMessage 发送消息 | ||
func SendWeixinMessage(msgType, text, toTag, toUser, toParty string) (bool, error) { | ||
agentID, err := beego.AppConfig.Int64("weixin::warningAppAgentID") | ||
if err != nil { | ||
return false, fmt.Errorf("get agentID from app.conf error: %s ", err) | ||
} | ||
|
||
message := &weixin.Message{ | ||
MsgType: msgType, // 目前只支持发送文本消息 | ||
ToTag: toTag, // ToTag 是在企业微信后台定义的标签ID,标签里面可以包含很多人,多个请用|分开 | ||
ToUser: toUser, // ToUser 是企业微信后台看到的用户的ID,多个请用|分开 | ||
ToParty: toParty, // ToParty 是企业微信后台看到的部门的ID,多个请用|分开 | ||
AgentID: agentID, // 企业应用的id,整型。可在应用的设置页面查看 | ||
Safe: 0, // 表示是否是保密消息,0表示否,1表示是,默认0 | ||
Text: &weixin.Text{ | ||
Content: text, | ||
}, | ||
} | ||
|
||
client := &weixin.Client{ | ||
AccessTokenAPI: accessTokenAPI, | ||
APIURL: sendMessageAPIURL, | ||
CorpID: corpID, | ||
CorpSecret: appSecret, | ||
Message: message, | ||
} | ||
_, err = client.SendMessage() | ||
if err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package controllers | ||
|
||
import ( | ||
"devops-api/common" | ||
"fmt" | ||
) | ||
|
||
// SendMessage 发送消息 | ||
func (w *WeixinController) SendMessage() { | ||
msgType := w.GetString("msgType") | ||
toTag := w.GetString("toTag") | ||
toUser := w.GetString("toUser") | ||
toParty := w.GetString("toParty") | ||
text := w.GetString("text") | ||
|
||
requestID := w.Data["RequestID"].(string) | ||
sendWeixinMessageLog := map[string]interface{}{ | ||
"entryType": "SendWeixinMessage", | ||
"requestId": requestID, | ||
} | ||
_, err := common.SendWeixinMessage(msgType, text, toTag, toUser, toParty) | ||
if err != nil { | ||
sendWeixinMessageLog["statuscode"] = 1 | ||
sendWeixinMessageLog["errmsg"] = fmt.Sprintf("%s", err) | ||
common.GetLogger().Error(sendWeixinMessageLog, "发送微信消息") | ||
w.Data["json"] = sendWeixinMessageLog | ||
w.ServeJSON() | ||
return | ||
} | ||
sendWeixinMessageLog["statuscode"] = 0 | ||
sendWeixinMessageLog["errmsg"] = "" | ||
sendWeixinMessageLog["result"] = "发送成功" | ||
common.GetLogger().Info(sendWeixinMessageLog, text) | ||
w.Data["json"] = sendWeixinMessageLog | ||
w.ServeJSON() | ||
return | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 微信报警流程 | ||
|
||
以前是通过微信企业号做报警,现在企业微信替代了微信企业号,所以现在只能通过企业微信来进行报警 | ||
|
||
## 1. [注册](https://work.weixin.qq.com/wework_admin/register_wx?from=myhome)企业微信 | ||
|
||
![注册](/doc/image/weixin/reg.png) | ||
|
||
## 2. [登录](https://work.weixin.qq.com/wework_admin/loginpage_wx)企业微信后台 | ||
|
||
使用管理员的微信扫描登录管理后台,登录之后如下图: | ||
|
||
![主页](/doc/image/weixin/home.png) | ||
|
||
## 3. 邀请成员 | ||
|
||
通过 微信扫描二维码的方式, 把所有要接收报警的人邀请进来,确保都在通讯录里面,才能接收到报警 | ||
|
||
![邀请成员](/doc/image/weixin/add_p.png) | ||
|
||
可以不用下载企业微信客户端 | ||
|
||
## 4. 添加应用 | ||
|
||
在企业应用里面创建一个应用 | ||
|
||
![创建应用](/doc/image/weixin/add_app.png) | ||
|
||
![填写应用信息](/doc/image/weixin/add_app_person.png) | ||
|
||
注意: 可以选择 部门/用户/标签 做为接收人,这一步很重要. | ||
|
||
创建之后,点开应用 | ||
|
||
![应用详情](/doc/image/weixin/app_detail.png) | ||
|
||
**记录 AgentId 和 Secret 这个会在调用API时用到** | ||
|
||
## 5. 接收报警的人都要使用微信扫码关注微信插件的二维码 | ||
|
||
这一步至关重要,不关注的话接收不到报警信息 | ||
|
||
![微信插件](/doc/image/weixin/weixin_plugin.png) | ||
|
||
## 6. 查看企业信息 | ||
|
||
**记录 CorpID,这个会在调用API时用到** | ||
|
||
![企业信息](/doc/image/weixin/mycorp.png) | ||
|
||
## 7. 查看通讯录,记录部门/用户/标签的 ID | ||
|
||
部门ID | ||
|
||
![部门ID](/doc/image/weixin/dep_id.png) | ||
|
||
用户ID | ||
|
||
![用户ID](/doc/image/weixin/person_click.png) | ||
![用户ID](/doc/image/weixin/person_id.png) | ||
|
||
标签ID | ||
|
||
![标签ID](/doc/image/weixin/tag_click.png) | ||
![标签ID](/doc/image/weixin/tag_id.png) | ||
|
||
记录这3种ID,然后调用API就可以发送了. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters