forked from royalrick/weapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.go
49 lines (39 loc) · 1.2 KB
/
send.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package subscribemessage
import (
"github.com/medivhzhan/weapp/v3/request"
)
const apiSend = "/cgi-bin/message/subscribe/send"
// SubscribeMessage 订阅消息
type SendRequest struct {
ToUser string `json:"touser"`
TemplateID string `json:"template_id"`
Page string `json:"page,omitempty"`
MiniprogramState MiniprogramState `json:"miniprogram_state,omitempty"`
Data SendData `json:"data"`
}
// 模板数据内容
type SendData map[string]SendValue
// 模板变量值
type SendValue struct {
Value string `json:"value"`
}
// MiniprogramState 跳转小程序类型
type MiniprogramState = string
// developer为开发版;trial为体验版;formal为正式版;默认为正式版
const (
MiniprogramStateDeveloper = "developer"
MiniprogramStateTrial = "trial"
MiniprogramStateFormal = "formal"
)
// 发送订阅消息
func (cli *SubscribeMessage) Send(msg *SendRequest) (*request.CommonError, error) {
api, err := cli.conbineURI(apiSend, nil, true)
if err != nil {
return nil, err
}
res := new(request.CommonError)
if err := cli.request.Post(api, msg, res); err != nil {
return nil, err
}
return res, nil
}