<commit_before># encoding: utf-8
module Alipay
  module Open
    module Service
      GATEWAY_URL = 'https://openapi.alipay.com/gateway.do'
      
      TRADE_PRECREATE_REQUIRED_PARAMS = %w( out_trade_no subject total_amount time_expire )
      # 扫描支付 － 预下单请求
      def self.trade_precreate(params, options = {})
        
        Alipay::Service.check_required_params(params, TRADE_PRECREATE_REQUIRED_PARAMS)

        puts "+++++ Params= #{params}"

        full_params = {
          'app_id'        => Alipay.open_pid,
          'method'        => 'alipay.trade.precreate',
          'charset'       => 'UTF-8',
          'sign_type'     => 'RSA',
          'timestamp'     =>  "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}",
          'version'       => "1.0",
          'notify_url'    => options['notify_url']
        }.merge('biz_content' => params)

        string_params = Utils.stringify_keys_with_hash_value(full_params)

        sign = rsa_sign(string_params)

        puts "+++++ Sign = #{sign}"

        url = request_uri(full_params.merge('sign' => sign))

        puts "+++++ URL = #{url}"

        post_params = post_params(params)

        puts "+++++ Post Params = #{post_params}"

        execution_options = {
          :method => :post, 
          :url => url, 
          :payload => post_params, 
          :timeout => 10, 
          :open_timeout => 10, 
          headers: {content_type: "application/x-www-form-urlencoded", accept: :json, charset: "UTF-8"}
        }

        RestClient::Request.execute(execution_options) { |response, request, result|
          case result.code
          when "200"
            result = JSON.parse response
            puts "Result: #{result}"
            ali_res = result["alipay_trade_precreate_response"]
            code = ali_res["code"]
            puts "Code: #{code}"<commit_msg>try again<commit_after># encoding: utf-8
module Alipay
  module Open
    module Service
      GATEWAY_URL = 'https://openapi.alipay.com/gateway.do'
      
      TRADE_PRECREATE_REQUIRED_PARAMS = %w( out_trade_no subject total_amount time_expire )
      # 扫描支付 － 预下单请求
      def self.trade_precreate(params, options = {})
        
        Alipay::Service.check_required_params(params, TRADE_PRECREATE_REQUIRED_PARAMS)

        puts "+++++ Params= #{params}"

        full_params = {
          'app_id'        => Alipay.open_pid,
          'method'        => 'alipay.trade.precreate',
          'charset'       => 'UTF-8',
          'sign_type'     => 'RSA',
          'timestamp'     =>  "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}",
          'version'       => "1.0",
          'notify_url'    => options['notify_url']
        }.merge('biz_content' => params)

        puts "+++++ Full Params = #{full_params}"

        string_params = Utils.stringify_keys_with_hash_value(full_params)

        puts "+++++ String Params = #{string_params}"

        sign = rsa_sign(string_params)

        puts "+++++ Sign = #{sign}"

        url = request_uri(full_params.merge('sign' => sign))

        puts "+++++ URL = #{url}"

        post_params = post_params(params)

        puts "+++++ Post Params = #{post_params}"

        execution_options = {
          :method => :post, 
          :url => url, 
          :payload => post_params, 
          :timeout => 10, 
          :open_timeout => 10, 
          headers: {content_type: "application/x-www-form-urlencoded", accept: :json, charset: "UTF-8"}
        }

        RestClient::Request.execute(execution_options) { |response, request, result|
          case result.code
          when "200"
            result = JSON.parse response
            puts "Result: #{result}"
            ali_res = result["alipay_trade_precreate_response"]
            code = ali_res["code"]
            puts "Code: #{code}"
{'fraction_non_alphanumeric': 0.14308342133051744, 'fraction_numerical': 0.006335797254487857, 'mean_word_length': 2.105737704918033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4409428', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1207, 'n_words': 214}