Class: YxSdk::Client

Inherits:
Object
  • Object
show all
Includes:
Api::User
Defined in:
lib/yx_sdk/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Api::User

#create, #refreshToken, #update

Constructor Details

#initialize(app_key, app_secret) ⇒ Client

Returns a new instance of Client.



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

def initialize(app_key, app_secret)
  @app_key = app_key
  @app_secret = app_secret
end

Instance Attribute Details

#app_keyObject

Returns the value of attribute app_key.



8
9
10
# File 'lib/yx_sdk/client.rb', line 8

def app_key
  @app_key
end

#app_secretObject

Returns the value of attribute app_secret.



8
9
10
# File 'lib/yx_sdk/client.rb', line 8

def app_secret
  @app_secret
end

Instance Method Details

#get_headerObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/yx_sdk/client.rb', line 21

def get_header
  timestamp = Time.now.to_i
  noncestr = SecureRandom.hex(16)
  str = "#{AppSecret}#{noncestr}#{timestamp}"
  signature = Digest::SHA1.hexdigest(str)
  {
      "AppKey" => @app_key,
      "Nonce" => noncestr,
      "CurTime" => timestamp,
      "CheckSum" => signature,
      "Content-Type" => "application/x-www-form-urlencoded;charset=utf-8"
  }
end

#http_post(url, post_body = {}, url_params = {}, endpoint = "plain") ⇒ Object

暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。



16
17
18
19
# File 'lib/yx_sdk/client.rb', line 16

def http_post(url, post_body={}, url_params={}, endpoint="plain")
  # url_params = url_params.merge(access_token_param)
  YxSdk.http_post_without_token(url, post_body, url_params, get_header, endpoint)
end