final String COLOR = "#173177"; // WechatMessage weChatTemplate = new WechatMessage(); // 设置模板id weChatTemplate.setTemplateId( "id"); // 设置接收用户openId,这里填接收者的openid weChatTemplate.setToUser("openId"); //点击详情跳转的地址 weChatTemplate.setUrl("http://weixin.qq.com/download"); //设置模板dada参数 weChatTemplate.getData().put("short_thing6",WechatMessage.initData("xx",COLOR)); weChatTemplate.getData().put("thing3",WechatMessage.initData("xx",COLOR)); weChatTemplate.getData().put("character_string13",WechatMessage.initData("xx",COLOR)); weChatTemplate.getData().put("character_string14",WechatMessage.initData("xx",COLOR)); weChatTemplate.getData().put("thing4",WechatMessage.initData( "xx",COLOR)); String s1 = JSON.toJSONString(weChatTemplate); System.out.println(s1); // 发送消息的接口 String sendUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=72_Db3yAk_gw8gHTb8NWg8afz8kXQ65piD1qUAz7BH7E8gpDtaBuJ1LuNjsKg-ij14hWTDQ6_h-ycrLFxZtC1AoHtY_sg0flFF6a2BfFKeUqKW_hzQ2Z3o7FaniVl8FCBhAHAZWV"; //调用微信接口,发送模板消息 String s = JSON.toJSONString(weChatTemplate); // HashMap<String, String> map = JSON.parseObject(s, HashMap.class); // WeiXinResponse weiXinResponse = OkHttpUtils2.builder() // .url(url) // .addParams(map) // .post(Boolean.FALSE) // .sync(WeiXinResponse.class); WeiXinResponse weiXinResponse = OkHttpUtils2.builder() .url(sendUrl) .postJson(s1) .sync(WeiXinResponse.class); System.out.println(weiXinResponse); 这个是main方法的调用
模板消息推送异常https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html 一直如下提示:单独调用又可以 invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r rid: 64f6e41f-75b28dfe-43715394
2023-09-05楼主解决这个问题了么
invalid credential, access_token is invalid?invalid credential, access_token is invalid or not latest, could get access_token by getStableAccessToken, more details at https://mmbizurl.cn/s/JtxxFh33r rid: 642f77f4-5d54800a-10ddf101
2023-09-05