Class: TencentTrustsql::Client

Inherits:
Object
  • Object
show all
Includes:
Api::AssetIssue, Api::Tpki
Defined in:
lib/tencent_trustsql/client.rb

Constant Summary

Constants included from Api::Tpki

Api::Tpki::URL_BASE

Constants included from Api::AssetIssue

Api::AssetIssue::URL_BASE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::Tpki

#account_apply, #account_get_list, #tpki_base_params, #user_apply, #user_get

Methods included from Api::AssetIssue

#asset_apply, #asset_apply_base, #asset_base_params, #asset_commit_base, #asset_transfer_apply, #asset_transfer_submit, #commit, #trans_batch_query

Constructor Details

#initialize(mch_private_key = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
# File 'lib/tencent_trustsql/client.rb', line 9

def initialize mch_private_key = nil
  @mch_private_key = mch_private_key || TencentTrustsql.mch_private_key_local
  @mch_id = TencentTrustsql.mch_id
  @mch_public_key_out = TencentTrustsql.encoded_public_key  @mch_private_key
end

Instance Attribute Details

#mch_idObject

Returns the value of attribute mch_id.



7
8
9
# File 'lib/tencent_trustsql/client.rb', line 7

def mch_id
  @mch_id
end

#mch_private_keyObject

Returns the value of attribute mch_private_key.



7
8
9
# File 'lib/tencent_trustsql/client.rb', line 7

def mch_private_key
  @mch_private_key
end

#mch_public_key_outObject

Returns the value of attribute mch_public_key_out.



7
8
9
# File 'lib/tencent_trustsql/client.rb', line 7

def mch_public_key_out
  @mch_public_key_out
end

Instance Method Details

#http_post(url, params) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/tencent_trustsql/client.rb', line 37

def http_post url, params
  # sign
  query = TencentTrustsql.params_to_string(params)
  mch_sign = TencentTrustsql.output_formatter.out_sign(TencentTrustsql.sign(mch_private_key, query))
  p 'http_post mch_sign used query' + query
  params.merge!(mch_sign: mch_sign)

  p params
  p url

  response =HTTP.post(url, json:  params)
  puts response.body
  JSON.parse(response.body) rescue nil
end

#sign_list_sign(user_private_key, sign_list) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tencent_trustsql/client.rb', line 16

def sign_list_sign user_private_key, sign_list
  signed_list = []
  p "count ------ #{sign_list.count}"
  sign_list.each do |obj|
    signed_obj = {}
    p "obj --------- #{obj}"
    p obj.keys
    [:account, :sign_str, :id].each do |key|
      signed_obj["#{key.to_s}"] = obj[key] || obj[key.to_s]
    end
    p signed_obj['sign_str']
    sign = TencentTrustsql.trans_sign user_private_key, signed_obj['sign_str']
    p a = TencentTrustsql.output_formatter.out_sign(sign)
    signed_obj['sign'] = a#TencentTrustsql.output_formatter.out_sign sign
    signed_list.push signed_obj
  end
  p 'sign_list signed'
  p signed_list
  signed_list
end