66 lines
1.8 KiB
Go
66 lines
1.8 KiB
Go
// This file is auto-generated, don't edit it. Thanks.
|
|
package alibaba
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
|
|
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
|
|
dingtalkrobot_1_0 "github.com/alibabacloud-go/dingtalk/robot_1_0"
|
|
util "github.com/alibabacloud-go/tea-utils/v2/service"
|
|
"github.com/alibabacloud-go/tea/tea"
|
|
)
|
|
|
|
const (
|
|
AUTO_NOTIFY_CHAT_ID = "cidSdyTEELI8btxKdGnSprffg=="
|
|
ROBOT_TOKEN = "dingrmgtodzxaik76jpc"
|
|
)
|
|
|
|
/**
|
|
* 使用 Token 初始化账号Client
|
|
* @return Client
|
|
* @throws Exception
|
|
*/
|
|
func CreateRobotClient() (_result *dingtalkrobot_1_0.Client, _err error) {
|
|
config := &openapi.Config{}
|
|
config.Protocol = tea.String("https")
|
|
config.RegionId = tea.String("central")
|
|
_result = &dingtalkrobot_1_0.Client{}
|
|
_result, _err = dingtalkrobot_1_0.NewClient(config)
|
|
return _result, _err
|
|
}
|
|
|
|
func SendMessage() (_err error) {
|
|
client, _err := CreateRobotClient()
|
|
if _err != nil {
|
|
return _err
|
|
}
|
|
token, err := GetToken()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
type msgP struct {
|
|
Title string `json:"title"`
|
|
Text string `json:"text"`
|
|
}
|
|
message := msgP{
|
|
Title: "更新通知",
|
|
Text: "```golang\n{\n\"message\": \"新版本 1.2.3 已发布,请及时更新!\"\n}\n```",
|
|
}
|
|
|
|
msgStr, _ := json.Marshal(message)
|
|
orgGroupSendHeaders := &dingtalkrobot_1_0.OrgGroupSendHeaders{}
|
|
orgGroupSendHeaders.XAcsDingtalkAccessToken = tea.String(token)
|
|
orgGroupSendRequest := &dingtalkrobot_1_0.OrgGroupSendRequest{
|
|
MsgParam: tea.String(string(msgStr)),
|
|
MsgKey: tea.String("sampleMarkdown"),
|
|
OpenConversationId: tea.String("cidSdyTEELI8btxKdGnSprffg=="),
|
|
RobotCode: tea.String(ROBOT_TOKEN),
|
|
CoolAppCode: tea.String(""),
|
|
}
|
|
resp, _err := client.OrgGroupSendWithOptions(orgGroupSendRequest, orgGroupSendHeaders, &util.RuntimeOptions{})
|
|
fmt.Println(resp)
|
|
return _err
|
|
}
|