公众号推送模板消息,跳转小程序报错invalid weapp pagepath
这是微信示例:
在检查自己代码发现并无错误时,修改 miniprogram中参数pagepath改为path即发送模板消息成功,特此记录。
/以下是自己的代码片段/
public static void main(String[] args) {
try {
//获取access_token
String result2 = HttpUtils.sendGet("https://api.weixin.qq.com/cgi-bin/token","grant_type=client_credential&appid="+WechatConfig.appidByGzh+"&secret="+WechatConfig.appsecretByGzh);
System.out.println(result2);
//解析请求
String access_token=JSON.parseObject(result2).get("access_token").toString();
String open_id="推送用户";
String regUser = "http://wxdemo.xxxx.com/wxdevices/bodycompositionmain?openId="+open_id;
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="+access_token;
Map<String, Object> map = new HashMap<String, Object>();
map.put("touser", open_id); //推送用户openid
map.put("template_id", "111"); //指定模版ID
Map<String, Object> xcx = new HashMap<String, Object>();
xcx.put("appid", "111");
xcx.put("path", "pages/lunar/index");
map.put("miniprogram", xcx); //点击模版跳转地址
Map<String, Object> data_map =new HashMap<String, Object>();
Map<String, Object> first = new HashMap<String, Object>();
first.put("value", "您好,你有一条信息");
first.put("color", "#000000");
Map<String, Object> keynote1 = new HashMap<String, Object>();
keynote1.put("value", "123");
keynote1.put("color", "#000000");
Map<String, Object> keynote2 = new HashMap<String, Object>();
keynote2.put("value", "2020-09-18");
keynote2.put("color", "#000000");
Map<String, Object> remark = new HashMap<String, Object>();
remark.put("value", "点击查看详情");
remark.put("color", "#000000");
data_map.put("first", first);
data_map.put("keyword1", keynote1);
data_map.put("keyword2", keynote2);
data_map.put("remark", remark);
map.put("data", data_map);
JSONObject json = new JSONObject(map);
String result = HttpUtils.sendPost(url, json.toString());
System.out.println(result);
JSONObject json_arr = JSONObject.parseObject(result);
String isOk = String.valueOf(json_arr.get("errmsg"));
if(isOk.equals("ok")){
System.out.println("推送成功 , ");
}else{
System.out.println("推送失败 , ");
}
} catch (Exception e) {
}
}