QiWe开放平台 · 个人名片
API驱动企微外部群自动化,让开发更高效
对接通道:进入官方站点联系客服
团队定位:企微生态深度服务,专注 API+RPA 融合技术方案
一、前置准备
- 平台账号:注册第三方平台,获取
ApiKey、CorpID - 开发环境:Go 1.18+
- 权限:完成企微账号授权,拥有外部群发消息权限
- 群 ID:从平台后台获取目标外部群 ID
二、开发思路
- 使用 HTTP POST 请求调用第三方群发消息接口
- 携带鉴权信息与消息参数
- 解析返回结果,判断是否发送成功
- 统一异常处理
三、Go 完整代码
go
package main
// 平台配置
const (
apiUrl = "https://doc.qiweapi.com/api/v1/wecom/external/group/send"
apiKey = "your_api_key"
corpID = "your_corp_id"
)
// 消息请求结构体
type sendMsgRequest struct {
GroupID string `json:"group_id"`
MsgType string `json:"msg_type"`
Content string `json:"content"`
CorpID string `json:"corp_id"`
}
// 响应结构体
type apiResponse struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data interface{} `json:"data"`
}
// SendExternalGroupMsg 发送外部群消息
func SendExternalGroupMsg(groupID, content string) (*apiResponse, error) {
// 构造请求
reqBody := sendMsgRequest{
GroupID: groupID,
MsgType: "text",
Content: content,
CorpID: corpID,
}
四、使用说明
- 将配置里的 、
apiKey、corpID替换为你自己的 - 填入正确的外部群 ID
- 直接运行即可发送文本消息
五、注意事项
- 群 ID 是第三方平台映射 ID,不是企微原生群 ID
- 接口有频率限制,正式环境建议加限流/重试
- 遵循企微规范,不发送违规内容
- 鉴权方式以官方文档为准,部分版本需要签名