收藏
回答

模板消息发送发送报errcode=47001, errmsg=data format error

{

    "data": {

        "phrase9": {

            "value": "订单审核"

        },

        "character_string2": {

            "value": "59240526999001703"

        },

        "thing8": {

            "value": "测试景区"

        },

        "time5": {

            "value": "2024-05-29"

        }

    },

    "templateId": "RUvEZ6TN0QQjaoIkwi_ICnP58_n1Vr7XRQWBZQYMKhA",

    "toUser": "o0phUw-3rgTqWw7hth5ahyTWFj3A",

    "url": ""

}

https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=80_sm6KWd-Xo4R-RW1t1OnAvA4WTu4vGZzXgCR0Q6aMzcPZN_71fcqWo-GTOa8PG_NszYXO-MmCfTmtsGdGrNiCjzSLoigbuBYU4VE-7RH25P19qoJ97pvJqpax3UYXKRdAFAFSZ

WeiXinResponse result = restTemplate.postForObject(String.format(PUSH_MESSAGE_URL, access_token),
        weChatTemplate.getData(), WeiXinResponse.class);


 WeiXinResponse(errcode=47001, errmsg=data format error rid: 66569ae3-6fe89688-274b3e3b, msgid=null)

回答关注问题邀请回答
收藏

3 个回答

  • klz
    klz
    05-29

     weChatTemplate: WeChatTemplate(touser=o0phUw-3rgTqWw7hth5ahyTWFj3A, template_id=RUvEZ6TN0QQjaoIkwi_ICnP58_n1Vr7XRQWBZQYMKhA, url=null, miniprogram=null, data={phrase9={value=订单审核}, character_string2={value=59240526999001703}, thing8={value=测试景区}, time5={value=2024-05-29}})

    2024-05-29 14:47:45.986 [http-nio-8082-exec-3] INFO  c.e.cloud.service.generator.impl.SmsServiceImpl:313 - url:https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=80_MvwE5V1xEtxA7vvTcptxI6wQ846LJ4N8pnbxvOX0yIrSNPKEYgrq4OdhkVDL45q_yDnFqqGQRl3bE1EcXUqewNohdAQqAO8-OJbGgHvXT3MG_RHZ36cEVQisONMJTLiAGAFPH

    WeiXinResponse result = restTemplate.postForObject(String.format(PUSH_MESSAGE_URL, access_token),
            JSON.toJSON(weChatTemplate), WeiXinResponse.class);
    log.info(result.toString());
    if (result.getErrmsg().equals("ok")) {
        log.info("PMS景区【" + poi.getName() + "】订单【" + orderInfo.getOrderCode() + "】已通知");
    }
    if (result.getErrmsg() == null && !result.getErrmsg().equals("ok")) {
        log.info("出异常了,发送微信通知是吧");
        //return Result.failure(ResultCode.SEND_MESSAGE_FAIL);
    }
    

    05-29
    有用
    回复
  • Mr.Zhao
    Mr.Zhao
    发表于小程序端
    05-29

    为啥不看文档,哪来的toUser,templateId也不对,不是驼峰

    05-29
    有用
    回复 2
    • klz
      klz
      05-29
      weChatTemplate: WeChatTemplate(touser=o0phUw-3rgTqWw7hth5ahyTWFj3A, template_id=RUvEZ6TN0QQjaoIkwi_ICnP58_n1Vr7XRQWBZQYMKhA, url=null, miniprogram=null, data={phrase9={value=订单审核}, character_string2={value=59240526999001703}, thing8={value=测试景区}, time5={value=2024-05-29}})

      2024-05-29 14:47:45.986 [http-nio-8082-exec-3] INFO  c.e.cloud.service.generator.impl.SmsServiceImpl:313 - url:https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=80_MvwE5V1xEtxA7vvTcptxI6wQ846LJ4N8pnbxvOX0yIrSNPKEYgrq4OdhkVDL45q_yDnFqqGQRl3bE1EcXUqewNohdAQqAO8-OJbGgHvXT3MG_RHZ36cEVQisONMJTLiAGAFPH

      WeiXinResponse result = restTemplate.postForObject(String.format(PUSH_MESSAGE_URL, access_token),
              JSON.toJSON(weChatTemplate), WeiXinResponse.class);
      log.info(result.toString());
      if (result.getErrmsg().equals("ok")) {
          log.info("PMS景区【" + poi.getName() + "】订单【" + orderInfo.getOrderCode() + "】已通知");
      }
      if (result.getErrmsg() == null && !result.getErrmsg().equals("ok")) {
          log.info("出异常了,发送微信通知是吧");
          //return Result.failure(ResultCode.SEND_MESSAGE_FAIL);
      }
      05-29
      回复
    • Mr.Zhao
      Mr.Zhao
      发表于移动端
      05-29回复klz
      看官方日志没传json,转成xml了。自查代码
      05-29
      回复
  • 风清雾云开见日出
    风清雾云开见日出
    05-29

    这个没有值就不要传递这个参数

    05-29
    有用
    回复 2
    • klz
      klz
      05-29
      不是这个原因吧
      05-29
      回复
    • 风清雾云开见日出
      风清雾云开见日出
      05-29回复klz
      参数名和值正确,就看到传递给api的参数是否是json格式了
      05-29
      回复
登录 后发表内容