module WechatPublicApi::Material
Public Instance Methods
upload_image_material(file_path)
click to toggle source
新增永久图片素材 @param <string> file_path – 图片素材的路径
@return <json> {“type”:“TYPE”,“media_id”:“MEDIA_ID”,“created_at”:123456789} if false @return <json> {“errcode”:40004,“errmsg”:“invalid media type”}
# File lib/wechat_public_api/material.rb, line 37 def upload_image_material(file_path) # request access_token access_token = get_access_token() response = RestClient.post('https://api.weixin.qq.com/cgi-bin/material/add_material', { access_token: access_token, type: 'image', media: File.new(file_path, 'rb')}) JSON.parse(response) end
upload_image_media(file_path)
click to toggle source
获得临时图片素材的 media_id @param <string> file_path – 图片素材的路径
@return <json> {“type”:“TYPE”,“media_id”:“MEDIA_ID”,“created_at”:123456789} if false @return <json> {“errcode”:40004,“errmsg”:“invalid media type”}
# File lib/wechat_public_api/material.rb, line 18 def upload_image_media(file_path) # request access_token access_token = get_access_token() response = RestClient.post('https://api.weixin.qq.com/cgi-bin/media/upload', { access_token: access_token, type: 'image', media: File.new(file_path, 'rb')}) JSON.parse(response) end