def send_from_rong
rc_rand = rand(100000)
time = Time.now.to_i
sign = signature({'rc_rand' => rc_rand, 'time' => time})
headers = {"RC-App-Key" => Rails.application.secrets.rongcloud.try(:[], "app_key"),
"RC-Nonce" => rc_rand.to_s, "RC-Timestamp" => time.to_s, 'RC-Signature' => sign.to_s,
"Content-Type" => "Application/x-www-form-urlencoded"}
body = (os == 'all' ? {
'fromUserId' => sendor_id, 'objectName' => object_name, 'content' => content, 'pushContent' => push_content, 'pushData' => push_data} : {
'fromUserId' => sendor_id, 'objectName' => object_name, 'content' => content, 'pushContent' => push_content, 'pushData' => push_data, 'os' => os})
response = HTTParty.post("https://api.cn.ronghub.com/message/broadcast.json", {
body: body,
headers: headers
})
if response['code'] == 200
self.status = 1
self.save
end
end
现在 response 对象一直报如下错误:
#<HTTParty::Response:0x7f806c6c8e98 parsed_response={"url"=>"/message/broadcast.json", "code"=>1002, "errorMessage"=>"Parameter content should be JSON format."}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"server"=>["nginx"], "date"=>["Wed, 31 Aug 2016 03:28:17 GMT"], "content-type"=>["application/json"], "content-length"=>["103"], "connection"=>["close"]}>
然后我给 body.to_json 之后如下错误:
#<HTTParty::Response:0x7f80748ebe48 parsed_response={"url"=>"/message/broadcast.json", "code"=>1002, "errorMessage"=>"content is required."}, @response=#<Net::HTTPBadRequest 400 Bad Request readbody=true>, @headers={"server"=>["nginx"], "date"=>["Wed, 31 Aug 2016 03:28:45 GMT"], "content-type"=>["application/json"], "content-length"=>["83"], "connection"=>["close"]}>
奇怪啊,我的 content 明明已经有了,为什么还让我加呢?求大神指点