lib/alipay/service/wap.rb in alipay-0.5.0 vs lib/alipay/service/wap.rb in alipay-0.6.0.beta1

- old
+ new

@@ -1,7 +1,5 @@ -require 'open-uri' - module Alipay module Service module Wap GATEWAY_URL = 'https://wappaygw.alipay.com/service/rest.htm' @@ -30,17 +28,17 @@ 'v' => '2.0' }.merge(options) Alipay::Service.check_required_options(options, WAP_TRADE_REQUIRED_OPTIONS) - xml = open("#{GATEWAY_URL}?#{query_string(options)}").read + xml = Net::HTTP.get(request_uri(options)) CGI.unescape(xml).scan(/\<request_token\>(.*)\<\/request_token\>/).flatten.first end AUTH_AND_EXECUTE_REQUIRED_OPTIONS = %w( service format v partner ) - def self.auth_and_execute(options) + def self.auth_and_execute_url(options) options = Utils.stringify_keys(options) Alipay::Service.check_required_options(options, ['request_token']) req_data_xml = "<auth_and_execute_req><request_token>#{options.delete('request_token')}</request_token></auth_and_execute_req>" @@ -51,18 +49,21 @@ 'format' => 'xml', 'v' => '2.0' }.merge(options) Alipay::Service.check_required_options(options, AUTH_AND_EXECUTE_REQUIRED_OPTIONS) - "#{GATEWAY_URL}?#{query_string(options)}" + request_uri(options).to_s end - def self.query_string(options) - options.merge!('sec_id' => 'MD5') + def self.request_uri(options) + uri = URI(GATEWAY_URL) + uri.query = URI.encode_www_form(sign_params(options)) + uri + end - options.merge('sign' => Alipay::Sign.generate(options)).map do |key, value| - "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" - end.join('&') + def self.sign_params(params) + sign_type = (params['sec_id'] ||= Alipay.sign_type) + params.merge('sign' => Alipay::Sign.generate(params.merge('sign_type' => sign_type))) end end end end