Skip to content

Commit

Permalink
Merge pull request #194 from fogisland/fix_custom_message_json_serial…
Browse files Browse the repository at this point in the history
…izer

custom_message_send 内使用 JSON.generate 来对消息做序列化
  • Loading branch information
Eric-Guo authored Jul 1, 2018
2 parents 5de4131 + 0707bb4 commit a0348f1
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/wechat/concern/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def material_delete(media_id)
end

def custom_message_send(message)
post 'message/custom/send', message.to_json, content_type: :json
post 'message/custom/send', message.is_a?(Wechat::Message) ? message.to_json : JSON.generate(message), content_type: :json
end

def customservice_getonlinekflist
Expand Down
2 changes: 1 addition & 1 deletion lib/wechat/corp_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def message_send(userid, message)
end

def custom_message_send(message)
post 'message/send', message.agent_id(agentid).to_json, content_type: :json
post 'message/send', message.is_a?(Wechat::Message) ? message.agent_id(agentid).to_json : JSON.generate(message.merge(agent_id: agentid)), content_type: :json
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/wechat/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
}

expect(subject.client).to receive(:post)
.with('message/custom/send', payload.to_json,
.with('message/custom/send', JSON.generate(payload),
params: { access_token: 'access_token' }, content_type: :json).and_return(true)

expect(subject.custom_message_send Wechat::Message.to('openid').text('message content')).to be true
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/wechat/corp_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
}

expect(subject.client).to receive(:post)
.with('message/send', payload.to_json,
.with('message/send', JSON.generate(payload),
params: { access_token: 'access_token' }, content_type: :json).and_return(true)

expect(subject.custom_message_send Wechat::Message.to('openid').text('message content')).to be true
Expand Down

0 comments on commit a0348f1

Please sign in to comment.