小程序推送

1.推送前參數準備:

APPID:wxaa2xxxx9980ff
SECRET:c125549df72xxxxx192548c1ca
MEETING_TEMP_ID:SwGyvDXxxxxxxxxxxp33-_tnctw

2.推送前獲取access_token值
獲取access_token地址:

getAccessTokenUrl:"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;

遠程請求獲取access_token接口,返回結果(字符串)轉成Map,從Map中獲取access_token

String accessToekn = Smap.get("access_token").toString()

3.準備推送的參數
推送請求地址:

sendMessageUrl:https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=

//拼接完整地址

sendMessageUrl = sendMessageUrl + accessToken

推送參數對象準備
在這裏插入圖片描述

WxMssVo wxMssVo = new WxMssVo();
//模板ID
wxMssVo.setTemplate_id(xxx)
//收集的用戶的formId(7天有效)
wxMssVo.setForm_id(xxx)
//推送用戶的openid
wxMssVo.setTouser(xxx)
Map<String, String> m = new HashMap<>();
m.put("keyword1", "對應模板第一個信息");
m.put("keyword2", "對應模板第二個信息");
...
wxMssVo.setData(m)
//設置點擊模板後跳轉到小程序後的頁面路徑
wxMssVo.setPage("pages/packageA/succeed/succeed?bid="+bid+"&userCode="+xxx);

4.推送

HttpClientPoolUtil.sendPost(sendMessageUrl ,JSON.toJSONString(wxMssVo))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章