微信-公众号-创建菜单列表 错误40016

运行程序,返回errcode40016:invalid button size hint: [afL4na0498vr21]

1. 到公众号调试页面,输入token和传过去的菜单json串 https://mp.weixin.qq.com/debug/ 

    如果创建成功,说明菜单json串 格式没有错,按钮个数也符合要求。否则请修改你的 json串。

    首先保证json串的格式没有问题,看第2步:

2. 程序的问题: 应该使用 没有参数名的http的post请求。这里我使用的是httpclient工具包:

   /**
     * @Title: sendPostWithoutParamName   
     * @Description: 无参数名,直接传数据 
     * @param: url
     * @param: headers
     * @param: paramValue  参数值
     */
    public static JSONObject sendPostWithoutParamName(String url,String paramValue) throws Exception
    {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(url);
        StringEntity paramEntity = new StringEntity(paramValue,"utf-8"); //防止中文乱码
        
        httpPost.setEntity(paramEntity); //直接放到entity中
        HttpResponse response = httpClient.execute(httpPost);
        return JSONObject.parseObject(EntityUtils.toString(response.getEntity()));
    }

<dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.3</version>
        </dependency>

测试程序:

@Test
    public void testPost() throws Exception
    {
        String createViewUrl = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token={红色替换成你的token}";
 
        JSONObject tokenObj = HttpClientUtils.sendPostWithoutParamName(createViewUrl, "{\"button\":[{\"type\":\"click\",\"name\":\"今日歌曲\",\"key\":\"V1001_TODAY_MUSIC\"}]}");
        Map javaObject = tokenObj.toJavaObject(Map.class);
        System.out.println(javaObject.get("errcode"));
        System.out.println(javaObject.get("errmsg"));
    }

即可解决。

评论 3
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值