Eric-Guo / wechat

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

临时素材无法获取 #278

Closed 0000sir closed 4 years ago

0000sir commented 4 years ago

微信API变更后,已经无法通过获取永久素材的方式获得用户发来的图片,需要调用获取临时素材接口 https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html

Eric-Guo commented 4 years ago

似乎无需wechat gem端处理,程序员在调用时注意即可。

0000sir commented 4 years ago

直接调用 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
Eric-Guo commented 4 years ago

有临时素材接口的API啊。。。可以直接调用,README里面也写了wechat media [MEDIA_ID, PATH],可以用吗?