下面是最后一步,发送失败的代码,报的错是无效的open_id""{\"errcode\":40003,\"errmsg\":\"invalid openid hint: [A5nx.a00694107]\"}""
@GetMapping (value= "/send-message" ) @ResponseBody public String sendMessage() throws Exception{ String url= "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=12_s8UlgaPk6ZXQb8ONnQhaDsM4zmofZsPJn6J9G5LR22Cw0M6ZYVueQir2ok4nc7cZ0OB2t6ht3mbNT_dWVvbyFKXJczmJYHBYG0eZp6qQmWfA5geZQLLGa_wpJq4opRtAdNoCOkdov2nJVpPCYRGjACAUNC" ; Map<String, String> map= new HashMap<>(); map.put( "template_id" , "7tXGcdQ776bSvHE92yY6Bo4epJ7N6764uf4F1obUods" ); map.put( "touser" , "oqauU03Yql7kdVd-H09pj8lg5psw" ); JSONObject packJsonmsg = packJsonmsg( "first" , "测试" , "2" , "测试" , "2017-5-2 10:49:38" , "mark" ); map.put( "data" ,packJsonmsg.toJSONString()); HttpKit.setCharSet( "UTF-8" ); //执行post请求 String post = HttpKit.post(url, map, packJsonmsg.toJSONString()); return post; } /** * 打包一个模板数据 * auther:W.Z * date:2018年8月8日 */ public JSONObject packJsonmsg(String firstString,String keyword11, String keyword21, String keyword31, String keyword41,String remarkString){ JSONObject json = new JSONObject(); try { JSONObject keywordfirst = new JSONObject(); keywordfirst.put( "value" , firstString); json.put( "first" , keywordfirst); JSONObject keyword1 = new JSONObject(); keyword1.put( "value" , keyword11); json.put( "keyword1" , keyword1); JSONObject keyword2 = new JSONObject(); keyword2.put( "value" , keyword21); json.put( "keyword2" , keyword2); JSONObject keyword3 = new JSONObject(); keyword3.put( "value" , keyword31); // keyword3.put("color", "#173177"); json.put( "keyword3" , keyword3); JSONObject keyword4 = new JSONObject(); keyword4.put( "value" , keyword41); // keyword4.put("color", "#173177"); json.put( "keyword4" , keyword4); JSONObject remark = new JSONObject(); remark.put( "value" , remarkString); // remark.put("color", "#173177"); json.put( "keyword4" , remark); } catch (JSONException e) { e.printStackTrace(); } return json; } |
----------------------------------------------------------------------------------------------------------
附上步骤
1.首先在调试工具获取accessToken----成功
2.第二,获取所有的公众号粉丝 open_id
3.调用相关api接口,见最上面代码
4.执行失败
我的open_id是在微信官方DEBUG地址调试的"https://mp.weixin.qq.com/debug/"取得的应该是对的啊, 有人知道为什么没
已解决,应该是微信本身的问题,第二天我以同样的方式测试了一下可以正常发送
你可以先打印一下post数据。看下和文档对比看看,有啥不一样。