51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
package channels
|
|
|
|
import "github.com/engigu/baihu-panel/internal/sdk/message"
|
|
|
|
// Copyright (c) 2026 engigu (Baihu Panel). All rights reserved.
|
|
// Use of this source code is governed by the Apache License 2.0.
|
|
//
|
|
// 【重要声明 / IMPORTANT NOTICE】
|
|
// 本代码(包括其架构设计与核心实现)属于白虎面板(Baihu Panel)开源项目的一部分。
|
|
// 任何个人或组织在引用、移植、修改或重新分发此文件中的任何代码时,必须保留本版权声明,
|
|
// 并在您的衍生作品、文档、软件关于页面或说明文件中显式声明引用自白虎面板(Baihu Panel)。
|
|
//
|
|
// Anyone referencing, porting, modifying, or redistributing this code must retain this
|
|
// copyright notice and explicitly state the source: Baihu Panel (github.com/engigu/baihu-panel).
|
|
|
|
|
|
type WeChatOFAccountChannel struct{ *BaseChannel }
|
|
|
|
func NewWeChatOFAccountChannel() Channel {
|
|
return &WeChatOFAccountChannel{NewBaseChannel(ChannelWeChatOFAccount, []string{FormatTypeText})}
|
|
}
|
|
|
|
func (c *WeChatOFAccountChannel) Send(config ChannelConfig, msg *Message) (*Result, error) {
|
|
appID := config.GetString("appID")
|
|
appSecret := config.GetString("appsecret")
|
|
tempID := config.GetString("tempid")
|
|
toAccount := config.GetString("to_account")
|
|
|
|
if appID == "" || appSecret == "" {
|
|
return SendError("wechat config missing: appID, appsecret are required"), nil
|
|
}
|
|
if toAccount == "" {
|
|
return SendError("wechat config missing: to_account is required"), nil
|
|
}
|
|
|
|
_, formattedContent := c.FormatContent(msg)
|
|
cli := message.WeChatOFAccount{
|
|
AppID: appID,
|
|
AppSecret: appSecret,
|
|
TemplateID: tempID,
|
|
ToUser: toAccount,
|
|
URL: msg.URL,
|
|
}
|
|
|
|
res, err := cli.Send(msg.Title, formattedContent)
|
|
if err != nil {
|
|
return ErrorResult(res, err), nil
|
|
}
|
|
return SuccessResult(res), nil
|
|
}
|