You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
147 lines
3.7 KiB
147 lines
3.7 KiB
package commonus
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
//设定信息发送地址
|
|
func sendUrlSet() (sendUrlstr string, isTrue bool, msg string) {
|
|
isTrue = false
|
|
ton, _, err := GetWechatTokenType("")
|
|
if err != nil {
|
|
msg = "获取ToKen失败!"
|
|
return
|
|
}
|
|
isTrue = true
|
|
msg = "获取ToKen成功!"
|
|
sendUrlstr = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + ton
|
|
return
|
|
}
|
|
|
|
//更新模版卡片消息
|
|
func UpdateSendTemplateCard() (sendUrlstr string, isTrue bool, msg string) {
|
|
isTrue = false
|
|
ton, _, err := GetWechatTokenType("")
|
|
if err != nil {
|
|
msg = "获取ToKen失败!"
|
|
return
|
|
}
|
|
isTrue = true
|
|
msg = "获取ToKen成功!"
|
|
sendUrlstr = "https://qyapi.weixin.qq.com/cgi-bin/message/update_template_card?access_token=" + ton
|
|
return
|
|
}
|
|
|
|
//发送文本信息
|
|
func (t *SendText) SendTextMessage() ([]byte, bool, string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return nil, false, msg
|
|
}
|
|
sendJsonData, _ := json.Marshal(t)
|
|
addDePartMent := CurlPostJosn(sendUrl, sendJsonData)
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
return addDePartMent, true, msg
|
|
}
|
|
|
|
//发送文本信息
|
|
func (s *SendMarkDown) SendMarkDownMassage() (bool, string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return false, msg
|
|
}
|
|
sendJsonData, _ := json.Marshal(s)
|
|
addDePartMent := CurlPostJosn(sendUrl, sendJsonData)
|
|
fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
return true, msg
|
|
}
|
|
|
|
//发送图文信息
|
|
func (s *SendImgCont) SendImgMessage() ([]byte, bool, string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return nil, false, msg
|
|
}
|
|
sendJsonData, _ := json.Marshal(s)
|
|
addDePartMent := CurlPostJosn(sendUrl, sendJsonData)
|
|
// fmt.Printf("%v-------------->%v\n", string(sendJsonData), string(addDePartMent))
|
|
return addDePartMent, true, msg
|
|
}
|
|
|
|
//发送按钮交互型模板文件
|
|
func (b *ButtonTemplateAll) SendButtonMessage() (receiveData []byte, IsTrue bool, msg string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return
|
|
}
|
|
sendJsonData, sendErr := json.Marshal(b)
|
|
if sendErr != nil {
|
|
IsTrue = false
|
|
msg = "发送数据不正确"
|
|
return
|
|
}
|
|
receiveData = CurlPostJosn(sendUrl, sendJsonData)
|
|
return
|
|
}
|
|
func (b *ButtonTemplate) SendButtonMessage() (receiveData []byte, IsTrue bool, msg string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return
|
|
}
|
|
sendJsonData, sendErr := json.Marshal(b)
|
|
if sendErr != nil {
|
|
IsTrue = false
|
|
msg = "发送数据不正确"
|
|
return
|
|
}
|
|
receiveData = CurlPostJosn(sendUrl, sendJsonData)
|
|
return
|
|
}
|
|
|
|
//跟新按钮交互型模板文件
|
|
func (u *UpdateButtonNotClickable) UpdateSendButtonMessage() (receiveData []byte, IsTrue bool, msg string) {
|
|
sendUrl, IsTrue, msg := UpdateSendTemplateCard()
|
|
if IsTrue == false {
|
|
return
|
|
}
|
|
sendJsonData, sendErr := json.Marshal(u)
|
|
if sendErr != nil {
|
|
IsTrue = false
|
|
msg = "发送数据不正确"
|
|
return
|
|
}
|
|
receiveData = CurlPostJosn(sendUrl, sendJsonData)
|
|
return
|
|
}
|
|
|
|
//文本通知型 --- 模板卡片消息
|
|
func (t *TextNotice) SendTextTemplateCard() (receiveData []byte, IsTrue bool, msg string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return
|
|
}
|
|
sendJsonData, sendErr := json.Marshal(t)
|
|
if sendErr != nil {
|
|
IsTrue = false
|
|
msg = "发送数据不正确"
|
|
return
|
|
}
|
|
receiveData = CurlPostJosn(sendUrl, sendJsonData)
|
|
return
|
|
}
|
|
|
|
func (i *ImageTextTemplate) SendImageTemplateCard() (receiveData []byte, IsTrue bool, msg string) {
|
|
sendUrl, IsTrue, msg := sendUrlSet()
|
|
if IsTrue == false {
|
|
return
|
|
}
|
|
sendJsonData, sendErr := json.Marshal(i)
|
|
if sendErr != nil {
|
|
IsTrue = false
|
|
msg = "发送数据不正确"
|
|
return
|
|
}
|
|
receiveData = CurlPostJosn(sendUrl, sendJsonData)
|
|
return
|
|
}
|
|
|