Eric-Guo / wechat

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

material 永久素材命令调用接口变了? #275

Closed 0000sir closed 4 years ago

0000sir commented 4 years ago

用Wechat.api.material media_id(永久素材列表获取的media_id)获取媒体文件时总是提示40007,翻代码翻到 common.rb 中

def material(media_id)
        get 'material/get', params: { media_id: media_id }, as: :file
end

推测调用的url是 material/get,微信文档中 material/get_material 是获取永久素材的接口,且调用方式是post(文档地址 https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Getting_Permanent_Assets.html

微信改接口了?

0000sir commented 4 years ago

直接改成 post 'material/get_material' 会报以下 cannot determine size of body 错误

HTTP::RequestError: cannot determine size of body: {:params=>{:media_id=>"nONZrMG8hS8nglm-8PuJBe7AD_0sUBmKdyWFm7P0Eds"}, :as=>:file}

不知道能如何处理,拼凑curl命令能够勉强使用:

token = Wechat.api.access_token.token
        output = Tempfile.new
        cmd = "curl \"https://api.weixin.qq.com/cgi-bin/material/get_material?access_token=#{token}\" -d '{\"media_id\":\"#{media_id}\"}' > #{output.path}"
        p output.path
        system(cmd)
Eric-Guo commented 4 years ago

确实变了,已发新版本0.11.8修正。