Skip to content

Commit 4d5ee8c

Browse files
committed
First try #78, not working yet.
httprb/http#293
1 parent 298387b commit 4d5ee8c

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

bin/wechat

+1-2
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,7 @@ class App < Thor
334334

335335
desc 'material_add [MEDIA_TYPE, PATH]', '永久媒体上传'
336336
def material_add(type, path)
337-
file = File.new(path)
338-
puts wechat_api.material_add(type, file)
337+
puts wechat_api.material_add(type, path)
339338
end
340339

341340
desc 'material_delete [MEDIA_ID]', '删除永久素材'

lib/wechat/corp_api.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'wechat/token/corp_access_token'
44
require 'wechat/ticket/corp_jsapi_ticket'
55
require 'cgi'
6+
require 'http/form_data'
67

78
module Wechat
89
class CorpApi < ApiBase
@@ -151,8 +152,9 @@ def material(media_id)
151152
get 'material/get', params: { media_id: media_id, agentid: agentid }, as: :file
152153
end
153154

154-
def material_add(type, file)
155-
post 'material/add_material', { upload: { media: file } }, params: { type: type, agentid: agentid }
155+
def material_add(type, file_path)
156+
form = HTTP::FormData.create(media: HTTP::FormData::File.new(file_path)).to_s
157+
post 'material/add_material', "#{form}\r\n", params: { type: type, agentid: agentid }
156158
end
157159

158160
def material_delete(media_id)

0 commit comments

Comments
 (0)