There is a code on Php:

$timestamp = '1485942173' $api_key = '6t7a7c34914c0fa02f34b4b52d55aa2bb2f3b4b7'; $login = 'admin'; $phone = '79793665627'; $return = 'json'; $sender = 'admin'; $text = 'Hello!'; $params = array( 'timestamp' => $timestamp, 'login' => $login, 'phone' => $phone, 'text' => $text, 'sender' => $sender, 'return' => $return ); ksort( $params ); reset( $params ); $signature = md5( implode( $params ) . $api_key ); $query = "https://test.ru/get/send.php?login=" . $login . "&signature=" . $signature . "&phone=" . $phone . "&sender=" . $sender . "&return=" . $return . "&timestamp=" . $timestamp . "&text=" . urlencode( $text ); $curl = curl_init(); curl_setopt( $curl, CURLOPT_URL, $query ); curl_setopt( $curl, CURLOPT_ENCODING, "utf-8" ); curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 120 ); curl_setopt( $curl, CURLOPT_TIMEOUT, 120 ); curl_setopt( $curl, CURLOPT_MAXREDIRS, 10 ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true ); $result = curl_exec( $curl ); 

I need a similar code on Ruby on Rails. I have already punched and Net::HTTP and OpenUri and Rest::Client answer is not the same as the Php request.

Last that punched:

 timestamp = '1485942173' login = 'admin' sender = 'admin' format = 'json' client_phone = '79793665627' message = 'Hello!' params = { :login => login, :phone => client_phone, :return => format, :sender => sender, :text => message, :timestamp => timestamp } api_key = '6t7a7c34914c0fa02f34b4b52d55aa2bb2f3b4b7' params_string = params.values.join + api_key signature = Digest::MD5.hexdigest(params_string) query = "https://test.ru/get/send.php?login=" + login + "&signature=" + signature + "&phone=" + client_phone + "&sender=" + sender + "&timestamp=" + timestamp + "&text=" + CGI.escape(message) uri = URI(query) res = Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https', :verify_mode => OpenSSL::SSL::VERIFY_NONE) { |http| request = Net::HTTP::Get.new uri.request_uri response = http.request request resp = JSON.parse(response.body) } 
  • I don't see where Rails is. Ruby see. And how does the described code not perform the task? What is the difference from the requested request? - D-side
  • What is the problem? For a minimal reproducible example, you can use httpbin.org, for example. - vp_arth
  • It does not comply with the fact that the error comes in the answer, which says that the variable & signature is not correct, but they are identical I checked. And about the difference can not all parameters are set such as in php. - Gankster
  • There is no magic. If the system says that the signature is incorrect, then it is incorrect. If the signatures are really identical, then what is signed is not identical. - D-side
  • In an amicable way, you need to screen all parameters in the URL. And it is better to build it with the help of the URI from the standard library (which will itself screen the parameters), and not like you, self-made. - D-side

0