106 lines
3.1 KiB
Go
106 lines
3.1 KiB
Go
package ding
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
)
|
|
|
|
func TestSendTextMessage(t *testing.T) {
|
|
webhookURL := "your_webhook_url"
|
|
secret := "your_secret"
|
|
|
|
client := NewDingTalkClient(webhookURL, secret)
|
|
|
|
// 发送文本消息
|
|
content := "这是一条测试文本消息,@相关人员。"
|
|
atMobiles := []string{"13800138000"}
|
|
isAtAll := false
|
|
|
|
err := client.SendTextMessage(content, atMobiles, isAtAll)
|
|
if err != nil {
|
|
fmt.Println("文本消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("文本消息发送成功")
|
|
}
|
|
}
|
|
|
|
func TestSendLinkMessage(t *testing.T) {
|
|
title := "测试链接消息"
|
|
text := "这是一条测试链接消息的详细内容,@相关人员。"
|
|
messageURL := "https://example.com"
|
|
picURL := "https://example.com/pic.jpg"
|
|
|
|
webhookURL := "your_webhook_url"
|
|
secret := "your_secret"
|
|
|
|
atMobiles := []string{"13800138000"}
|
|
|
|
client := NewDingTalkClient(webhookURL, secret)
|
|
err := client.SendLinkMessage(title, text, messageURL, picURL, atMobiles, false)
|
|
if err != nil {
|
|
fmt.Println("链接消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("链接消息发送成功")
|
|
}
|
|
}
|
|
|
|
func TestSendMarkdownMessage(t *testing.T) {
|
|
markdownTitle := "测试 Markdown 消息"
|
|
|
|
markdownText := "# <font color='green'><h1>立减金发放平台报警通知</h1></font> \n<font color='black'>不好了,订单发放发生异常了,错误内容[<font color='#FFA500'>批次号不存在</font>]@相关人员。</font>"
|
|
|
|
atMobiles := []string{"18666173766", "15102807142"}
|
|
|
|
webhookURL := "https://oapi.dingtalk.com/robot/send?access_token=5f10c2213cbf8168985cb2d061ebb1a5f70bd1dd47ec7cef58fa6fe545d52588"
|
|
secret := "SEC77b63d70a9e22317144e712b4538ce1e0013db885c65f7f9bae283e8958b39eb"
|
|
|
|
client := NewDingTalkClient(webhookURL, secret)
|
|
if err := client.SendMarkdownMessage(markdownTitle, markdownText, atMobiles, false); err != nil {
|
|
fmt.Println("Markdown 消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("Markdown 消息发送成功")
|
|
}
|
|
}
|
|
|
|
func TestSend(t *testing.T) {
|
|
webhookURL := "your_webhook_url"
|
|
secret := "your_secret"
|
|
|
|
client := NewDingTalkClient(webhookURL, secret)
|
|
|
|
// 发送文本消息
|
|
content := "这是一条测试文本消息,@相关人员。"
|
|
atMobiles := []string{"13800138000"}
|
|
|
|
err := client.SendTextMessage(content, atMobiles, false)
|
|
if err != nil {
|
|
fmt.Println("文本消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("文本消息发送成功")
|
|
}
|
|
|
|
// 发送链接消息
|
|
title := "测试链接消息"
|
|
text := "这是一条测试链接消息的详细内容,@相关人员。"
|
|
messageURL := "https://example.com"
|
|
picURL := "https://example.com/pic.jpg"
|
|
|
|
err = client.SendLinkMessage(title, text, messageURL, picURL, atMobiles, false)
|
|
if err != nil {
|
|
fmt.Println("链接消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("链接消息发送成功")
|
|
}
|
|
|
|
// 发送 Markdown 消息
|
|
markdownTitle := "测试 Markdown 消息"
|
|
markdownText := "# 标题\n这是一条测试 Markdown 消息的详细内容,@13800138000。"
|
|
|
|
err = client.SendMarkdownMessage(markdownTitle, markdownText, atMobiles, false)
|
|
if err != nil {
|
|
fmt.Println("Markdown 消息发送失败:", err)
|
|
} else {
|
|
fmt.Println("Markdown 消息发送成功")
|
|
}
|
|
}
|