客服接口-发消息API,莫名的返回-1
发布于 7 年前 作者 jun46 6102 次浏览 来自 问答

我们的客服消息不能用了是被封杀了吗?或者被限制了?求官方给个回复。

服务器发客服消息返回码一直是-1。具体代码如下

Type type = new TypeToken<Map<String, String>>() {
    }.getType();
    Map<String, String> bodyMap = gson.fromJson(body, type);
    String openId = bodyMap.get("FromUserName");// 用户的openid
    String msgType = bodyMap.get("MsgType");
    String event = bodyMap.get("Event");
    if ("text".equals(msgType)) {
      HttpHeaders headers = new HttpHeaders();
      // 发送图片消息之前,要把素材图片上传到微信服务器,返回media_id才能发送
      // 获取该小程序的access_token
      String accessToken = redisTemplate.opsForValue().get("program:recommend:access_token");
      String url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=" + accessToken;
      String p = "{ \"touser\":\"OPENID\", \"msgtype\":\"image\", \"image\": { \"media_id\":\"MEDIA_ID\" } }";
      String param = p.replace("OPENID", openId).replace("MEDIA_ID", "固定MEDIA_ID");
      RestTemplate restTemplate = new RestTemplate();
      MediaType mediaType = MediaType.parseMediaType("application/json; charset=UTF-8");
      headers.setContentType(mediaType);
      headers.add("Accept", MediaType.APPLICATION_JSON.toString());
      HttpEntity<String> formEntity = new HttpEntity<String>(param, headers);
      ResponseEntity<String> entity = restTemplate.postForEntity(url, formEntity, String.class);

下图新用户的客服消息

回到顶部