Closed 0000sir closed 4 years ago
似乎无需wechat gem端处理,程序员在调用时注意即可。
直接调用 Wechat.api.get_material 调用的是获取永久素材接口,如果是用户发来的图片,会提示 invalid media id,这个get_material还有高级用法?
我目前的方案还是直接访问接口的url
require "down"
require "fileutils"
access_token = Wechat.api.access_token
url = "https://api.weixin.qq.com/cgi-bin/media/get?access_token=#{access_token.token}&media_id=#{media_id}"
begin
temp = Down.download(url)
images.attach io: temp, filename: temp.original_filename
rescue => e
p e.message
end
微信API变更后,已经无法通过获取永久素材的方式获得用户发来的图片,需要调用获取临时素材接口 https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html