Commit 1e7e29a7 by lanrion

Merge branch 'santochan-add_media_uploade_image'

parents b45f27ad fce497b5
language: ruby
bundler_args: --without development
bundler_args:
rvm:
- 2.0.0
script:
......
......@@ -68,6 +68,19 @@ module WeixinAuthorize
http_post("#{media_base_url}/uploadvideo", video_msg)
end
# 上传图文消息内的图片获取URL
# https://api.weixin.qq.com/cgi-bin/media/uploadimg?access_token=ACCESS_TOKEN
#
# return:
# {
# "url": "http://mmbiz.qpic.cn/mmbiz/gLO17UPS6FS2xsypf378iaNhWacZ1G1UplZYWEYfwvuU6Ont96b1roYs CNFwaRrSaKTPCUdBK9DgEHicsKwWCBRQ/0"
# }
def upload_image(image)
file = process_file(image)
upload_image_url = "#{media_base_url}/uploadimg"
http_post(upload_image_url, {media: file}, {type: 'image'}, 'file')
end
private
def media_base_url
......
......@@ -17,13 +17,25 @@ describe WeixinAuthorize::Api::Media do
end
let(:remote_png_path) do
"https://ruby-china-files.b0.upaiyun.com/user/big_avatar/273.jpg"
"https://ruby-china-files.b0.upaiyun.com/photo/5982eaaa64f467d9dbda03ad4f40ea27.png"
end
let(:remote_jpg_path) do
"http://g.hiphotos.baidu.com/baike/c0%3Dbaike80%2C5%2C5%2C80%2C26/sign=ce55457e4334970a537e187df4a3baad/03087bf40ad162d99455ef4d13dfa9ec8b13632762d0ed14.jpg"
end
it "can upload a jpg image and get url" do
response = $client.upload_image(image_jpg_file)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["url"])
end
it "can upload a png image and get url" do
response = $client.upload_image(remote_png_path)
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
expect(response.result.keys).to eq(["url"])
end
it "can upload a jpg File image" do
response = $client.upload_media(image_jpg_file, "image")
expect(response.code).to eq(WeixinAuthorize::OK_CODE)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment