1、需要小程序后台申请消息模板
2、小测程序推送实现
//发起推送授权
wx.requestSubscribeMessage({
tmplIds: ["模板id"],
success(re3) {
if (re3.errMsg == "requestSubscribeMessage:ok") {
//调用推送接口
api.request('/notification', {
touser: openid,
page: '公众号页面',
name4: //名称
amount2: //价格
character_string1: //订单号
date3: //下单时间
}).then(res => {
if (res.errcode == 0) {
api.showToast("推送成功");
} else if (res.errcode == 40003) {
api.showToast("touser字段openid为空或者不正确");
} else if (res.errcode == 400037) {
api.showToast("订阅模板id为空不正确");
} else if (res.errcode == 43101) {
api.showToast("用户拒绝接受消息,如果用户之前曾经订阅过,则表示用户取消了订阅关系");
} else if (res.errcode == 47003) {
api.showToast("模板参数不准确");
} else if (res.errcode == 41030) {
api.showToast("page路径不正确,需要保证在现网版本小程序中存在,与app.json保持一致");
}
}).catch(err => {
api.showToast("接口异常");
});
}
}
})
3、后端接口实现(工具类和接口)
package com.***.util.WeCahtApplet;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;