diff --git a/mp.go b/mp.go index ec9d42a..613b034 100644 --- a/mp.go +++ b/mp.go @@ -58,3 +58,52 @@ func SendTemplateMessage(access_token string, touser, template_id, url string, d return res, err } +func SendTemplateMessageApplet(access_token string, touser, template_id string, miniprogram map[string]string, data map[string]interface{}, client_msg_id, miniapp_appid, miniapp_pagepath string) (wx_template_msg_res, error) { + + var res wx_template_msg_res + + if touser == "" { + return res, errors.New("缺少用户openid") + } + if template_id == "" { + return res, errors.New("缺少消息模板") + } + if access_token == "" { + return res, errors.New("缺少access token") + } + api_url := fmt.Sprintf(MP_TEMPLATE_MESSAGE_API, access_token) + + msg := map[string]interface{}{ + "touser": touser, + "template_id": template_id, + "data": data, + } + + if len(miniprogram) > 0 { + msg["miniprogram"] = miniprogram + } + if client_msg_id != "" { + msg["client_msg_id"] = client_msg_id + } + + if miniapp_appid != "" { + msg["miniprogram"] = map[string]string{ + "appid": miniapp_appid, + "pagepath": miniapp_pagepath, + } + } + + msg_json, err := json.Marshal(msg) + + if err != nil { + return res, err + } + + data_byte, err := PostJson(api_url, msg_json) + + if err == nil { + err = json.Unmarshal(data_byte, &res) + } + + return res, err +} diff --git a/qqwry.dat b/qqwry.dat new file mode 100644 index 0000000..ec4fc38 Binary files /dev/null and b/qqwry.dat differ diff --git a/qqwry20200228.dat b/qqwry20200228.dat new file mode 100644 index 0000000..4608728 Binary files /dev/null and b/qqwry20200228.dat differ