Browse Source

增加发送模板消息跳转小程序

master v0.5.1
loshiqi 8 months ago
parent
commit
c3faf5bc5e
3 changed files with 49 additions and 0 deletions
  1. +49
    -0
      mp.go
  2. BIN
      qqwry.dat
  3. BIN
      qqwry20200228.dat

+ 49
- 0
mp.go View File

@ -58,3 +58,52 @@ func SendTemplateMessage(access_token string, touser, template_id, url string, d
return res, err 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
}

BIN
qqwry.dat View File


BIN
qqwry20200228.dat View File


Loading…
Cancel
Save