Eric-Guo / wechat

API, command and message handling for WeChat in Rails
MIT License
1.31k stars 372 forks source link

创建菜单:invalid button size hint: [IiheJA07521960](40016) #273

Closed sitoto closed 4 years ago

sitoto commented 4 years ago

pry(main)> Wechat.api('pcc').menu_create("/tmp/hIFs-a-67Ty2yOUljVyIuA.yml")

WechatConfig Load (0.8ms)  SELECT "wechat_configs".* FROM "wechat_configs" WHERE "wechat_configs"."environment" = $1 AND "wechat_configs"."enabled" = $2  [["environment", "development"], ["enabled", true]]

Wechat::ResponseError: invalid button size hint: [3fHDGA09521978](40016)

from /home/mw-hw/.rvm/gems/ruby-2.6.3/gems/wechat-0.11.6/lib/wechat/http_client.rb:72:in `block in request'

pry(main)> cat /tmp/hIFs-a-67Ty2yOUljVyIuA.yml

button:
 -
  type: "view"
  name: "About"
  url:  "https://pcc.xxx.com/"

本地测试就是就是错误,但是使用'微信公众平台接口调试工具' 测试的时正常的.如下


请求地址:
https://api.weixin.qq.com/cgi-bin/menu/create?access_token=28_MHgO67_ImWVqkpkDRd7F0g0stbgksj3wZM-tsC9v2Y1c3If1JlWn5D6qwUQIq5A47NtDKNxXCVPR2TmPHEh_ZNh2wTnzWHaAQ_Cv8-h-q2ZHqG7T24pgtbXnSZOgWlkI2ujQ9RLIBoUJdXKjOKBaACAAWN
返回结果:
200 OK
Connection: keep-alive
Date: Mon, 02 Dec 2019 05:16:19 GMT
Content-Type: application/json; encoding=utf-8
Content-Length: 27
{
    "errcode": 0, 
    "errmsg": "ok"
}
提示:
Request successful
Eric-Guo commented 4 years ago

看一下是否允许API改菜单,好像微信后台现在有一个toggle,如果不启用,就不能API改,只能手工维护。

sitoto commented 4 years ago

通过接口调用的参数是hash, 而不能是文件路径.如下: 错误:

Wechat.api('pcc').menu_create("/tmp/hIFs-a-67Ty2yOUljVyIuA.yml")

正确的调用方式:

menu = {}
menu[:button] = []
menu = menu[:button][0] = {"type": "view", "name": "about", "url": "https://pcc.xxx.com"}
Wechat.api('pcc').menu_create(menu)