Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/mini program template #806

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions miniprogram/subscribe/subscribe.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package subscribe

import (
"encoding/json"
"fmt"

"github.com/silenceper/wechat/v2/miniprogram/context"
Expand Down Expand Up @@ -70,6 +71,13 @@ type TemplateList struct {
Data []TemplateItem `json:"data"`
}

// resTemplateSend 发送获取 msg id
type resTemplateSend struct {
util.CommonError

MsgID int64 `json:"msgid"`
}

// Send 发送订阅消息
func (s *Subscribe) Send(msg *Message) (err error) {
var accessToken string
Expand All @@ -85,6 +93,33 @@ func (s *Subscribe) Send(msg *Message) (err error) {
return util.DecodeWithCommonError(response, "Send")
}

// SendGetMsgID 发送订阅消息返回 msgid
func (s *Subscribe) SendGetMsgID(msg *Message) (msgID int64, err error) {
var accessToken string
accessToken, err = s.GetAccessToken()
if err != nil {
return
}
uri := fmt.Sprintf("%s?access_token=%s", subscribeSendURL, accessToken)
response, err := util.PostJSON(uri, msg)
if err != nil {
return
}

var result resTemplateSend
if err = json.Unmarshal(response, &result); err != nil {
return
}
if result.ErrCode != 0 {
err = fmt.Errorf("template msg send error : errcode=%v , errmsg=%v", result.ErrCode, result.ErrMsg)
houseme marked this conversation as resolved.
Show resolved Hide resolved
return
}

msgID = result.MsgID

return
}

// ListTemplates 获取当前帐号下的个人模板列表
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
func (s *Subscribe) ListTemplates() (*TemplateList, error) {
Expand Down
Loading