Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信营销接口实现与文档描述不一致 #1095

Closed
sinrimin opened this issue Jul 4, 2019 · 8 comments
Closed

微信营销接口实现与文档描述不一致 #1095

sinrimin opened this issue Jul 4, 2019 · 8 comments

Comments

@sinrimin
Copy link

sinrimin commented Jul 4, 2019

简要描述

MarketingService模块实现与文档描述不一致,addUserAction 接口根本无法正常使用

模块版本情况

  • WxJava 模块名: weixin-java-mp
  • WxJava 版本号: 3.4.0

期待结果 和 实际情况

官方文档
请求示例中数据格式为

{
    "actions": [
        {
            "user_action_set_id": "<USER_ACTION_SET_ID>",
            "url": "<URL>",
            "action_time": 1513077790,
            "action_type": "COMPLETE_ORDER",
            "trace": {
                "click_id": "<CLICK_ID>"
            },
            "action_param": {
                "value": 40
            }
        }
    ]
}

通过API调用后的JSON

[
    {
        "user_action_set_id": "<USER_ACTION_SET_ID>",
        "url": "<URL>",
        "action_time": true,
        "trace": {
            "click_id": "<CLICK_ID>"
        }
    }
]

返回结果

{
    "errcode": 900351002,
    "errmsg": "JSON string is malformed."
}

原因分析:
1、action_time 类型为Unix时间戳Integer型,现在被定义为了Boolean型
2、action_type 没有被塞到请求的JSON对象中
3、请求对象最外层是个Json对象,不是数组,对象中的 actions 的内容对应这个数组
4、请求头缺少 application/json

重现步骤

业务代码

       List<WxMpUserAction> wxMpUserActions = Lists.newArrayList();
        WxMpUserAction action = new WxMpUserAction();

        action.setUserActionSetId(sid);
        action.setUrl(url);
        action.setClickId(vid);
        action.setActionType(at);
        action.setActionTime(true);

        wxMpUserActions.add(action);

        service.getMarketingService().addUserAction(wxMpUserActions);

结果

日志

【请求地址】: https://api.weixin.qq.com/marketing/user_actions/add?version=v1.0&access_token=<ACCESS_TOKEN>
【请求参数】:[{"user_action_set_id":<USER_ACTION_SET_ID>,"url":"<URL>","action_time":true,"trace":{"click_id":"<CLICK_ID>"}}]
【错误信息】:{"errcode":900351002,"errmsg":"JSON string is malformed."}
{"errcode":900351002,"errmsg":"JSON string is malformed."}
me.chanjar.weixin.common.error.WxErrorException: {"errcode":900351002,"errmsg":"JSON string is malformed."}
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.executeInternal(BaseWxMpServiceImpl.java:325)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.execute(BaseWxMpServiceImpl.java:264)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.post(BaseWxMpServiceImpl.java:253)
	at me.chanjar.weixin.mp.api.impl.WxMpMarketingServiceImpl.addUserAction(WxMpMarketingServiceImpl.java:61)
	at com.********.***.*******.endpoint.api.MarketingEndpoint.actions(MarketingEndpoint.java:35)
	at com.********.***.*******.endpoint.api.MarketingEndpoint$$FastClassBySpringCGLIB$$db5c5359.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
	at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
Caused by: me.chanjar.weixin.common.error.WxErrorException: {"errcode":900351002,"errmsg":"JSON string is malformed."}
	at me.chanjar.weixin.common.util.http.okhttp.OkHttpSimplePostRequestExecutor.execute(OkHttpSimplePostRequestExecutor.java:38)
	at me.chanjar.weixin.common.util.http.okhttp.OkHttpSimplePostRequestExecutor.execute(OkHttpSimplePostRequestExecutor.java:16)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.executeInternal(BaseWxMpServiceImpl.java:304)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.execute(BaseWxMpServiceImpl.java:264)
	at me.chanjar.weixin.mp.api.impl.BaseWxMpServiceImpl.post(BaseWxMpServiceImpl.java:253)
	at me.chanjar.weixin.mp.api.impl.WxMpMarketingServiceImpl.addUserAction(WxMpMarketingServiceImpl.java:61)
	at com.********.***.*******.endpoint.api.MarketingEndpoint.actions(MarketingEndpoint.java:35)
	at com.********.***.*******.endpoint.api.MarketingEndpoint$$FastClassBySpringCGLIB$$db5c5359.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:736)
@binarywang
Copy link
Owner

@007gzs 帮忙看下这个是不是由于微信接口调整导致的?

@007gzs
Copy link

007gzs commented Jul 9, 2019

action_time 应该是当时写错了,leads_type是新增参数,我改下

@binarywang
Copy link
Owner

@007gzs 什么时间能修复下?

@binarywang
Copy link
Owner

没事,不用了,我来修复

@binarywang
Copy link
Owner

@007gzs leads_type这个参数没找到,其他部分我准备先修复下了

@binarywang binarywang changed the title MarketingService模块实现与文档描述不一致 微信营销接口实现与文档描述不一致 Jul 14, 2019
@binarywang
Copy link
Owner

binarywang commented Jul 14, 2019

#1110

@binarywang
Copy link
Owner

3.4.7.B测试版本 已修复,欢迎试用

@sinrimin
Copy link
Author

抱歉这功能前段时间上线了,现在不敢在生产环境DEBUG,不过 ”请求头缺少 application/json“是肯定会返回错误的,代码里配置的okhttp默认的好像是 "plain/text",这个请求头不影响公众号的接口请求,但微信广告接口不带的话就直接报错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants