2,245
社区成员
发帖
与我相关
我的任务
分享
@authorization.gsub!("\n", '')
require 'rubygems'
require 'net/http'
require 'net/https'
require 'base64'
require 'md5'
require 'rubygems'
require 'json'
# @host = 'sandboxapp.cloopen.com'
# @port = '8883'
@app_id = ""
@account_sid = ""
@auth_token = ""@to = ""
@time = Time.now.strftime('%Y%m%d%H%M%S')
puts @time
@authorization = Base64.encode64("#{@account_sid}:#{@time.to_s}")
@authorization.gsub!("\n", '')
# puts @authorization
# puts @authorization
# puts Base64.decode64(@authorization)
@sig_parameter = MD5.hexdigest("#{@account_sid}#{@auth_token}#{@time.to_s}").upcase
@post_ws = "/2013-12-26/Accounts/#{@account_sid}/Calls/VoiceVerify?sig=#{@sig_parameter}"
@url = URI.parse("https://sandboxapp.cloopen.com:8883")
@http=Net::HTTP.new(@url.host, @url.port)
@http.use_ssl = true if @url.scheme == 'https'
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@payload ={
"appId" => "#{@app_id}",
"verifyCode" => "1a8d9u",
"playTimes" => "2",
"to"=>"#{@to}"
}.to_json
# def post
req = Net::HTTP::Post.new(@post_ws, initheader = {
"Content-Type" => "application/json;charset=utf-8",
"Accept" => "application/json",
'Authorization' => @authorization
})
# req.basic_auth @user, @pass
req.body = @payload
response = @http.start {|http| http.request(req) }
puts "Response #{response.code} #{response.message}:#{response.body}"
# end