Skip to content

Commit 126fb7a

Browse files
committed
Correct way to fix material_delete issue #78.
1 parent 8f3bb59 commit 126fb7a

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

lib/wechat/api.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def material_add(type, file)
143143
end
144144

145145
def material_delete(media_id)
146-
post 'material/del_material', media_id: media_id
146+
post 'material/del_material', JSON.generate(media_id: media_id)
147147
end
148148

149149
def custom_message_send(message)

lib/wechat/http_client.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get(path, get_header = {})
2222
def post(path, payload, post_header = {})
2323
request(path, post_header) do |url, header|
2424
params = header.delete(:params)
25-
httprb.headers(header).post(url, params: params, body: payload.to_json, ssl_context: ssl_context)
25+
httprb.headers(header).post(url, params: params, body: payload, ssl_context: ssl_context)
2626
end
2727
end
2828

spec/lib/wechat/api_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,9 @@
470470
specify 'will post material/del_material with access_token and media_id in payload' do
471471
media_id = 'media_id'
472472
material_delete_result = { errcode: 0, errmsg: 'deleted' }
473+
payload = { media_id: media_id }
473474
expect(subject.client).to receive(:post)
474-
.with('material/del_material', { media_id: media_id },
475+
.with('material/del_material', payload.to_json,
475476
params: { access_token: 'access_token' }).and_return(material_delete_result)
476477
expect(subject.material_delete(media_id)).to eq material_delete_result
477478
end

0 commit comments

Comments
 (0)