Class: Haoyaoshi::Client
- Inherits:
-
Object
- Object
- Haoyaoshi::Client
- Includes:
- Api::Drug, Api::EInvoice, Api::Image, Api::Logistics, Api::Order, Api::OrderCenter, Api::Stock, MonitorMixin
- Defined in:
- lib/haoyaoshi/client.rb
Instance Attribute Summary collapse
-
#access_token ⇒ Object
Returns the value of attribute access_token.
-
#channel ⇒ Object
Time.now + expires_in.
-
#client_id ⇒ Object
Time.now + expires_in.
-
#client_secret ⇒ Object
Time.now + expires_in.
-
#custom_access_token ⇒ Object
Returns the value of attribute custom_access_token.
-
#expired_at ⇒ Object
Time.now + expires_in.
-
#grant_type ⇒ Object
Time.now + expires_in.
-
#parnterkey ⇒ Object
Time.now + expires_in.
-
#redis_key ⇒ Object
Returns the value of attribute redis_key.
-
#scope ⇒ Object
Time.now + expires_in.
-
#token_type ⇒ Object
Returns the value of attribute token_type.
-
#token_type_token ⇒ Object
Returns the value of attribute token_type_token.
Instance Method Summary collapse
-
#get_access_token ⇒ Object
return token.
-
#get_token_type ⇒ Object
return token.
- #http_delete(url, delete_body = {}, url_params = {}, endpoint = "plain") ⇒ Object
-
#http_drug_get(url, url_params = {}, path = nil, endpoint = "plain") ⇒ Object
暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。.
-
#http_get(url, url_params = {}, endpoint = "plain") ⇒ Object
暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。.
- #http_post(url, post_body = {}, url_params = {}, endpoint = "plain") ⇒ Object
-
#initialize(client_id, client_secret, channel, parnterkey, grant_type = "client_credentials", scope = "order", options = {}) ⇒ Client
constructor
options: redis_key, custom_access_token.
-
#is_valid? ⇒ Boolean
检查appid和app_secret是否有效。.
- #token_store ⇒ Object
Methods included from Api::OrderCenter
Methods included from Api::Stock
#get_branch_stocks, #get_stock
Methods included from Api::EInvoice
Methods included from Api::Image
Methods included from Api::Logistics
#get_company, #get_deliveries, #get_deliveries_list
Methods included from Api::Order
#delete_batch_order, #delete_order, #get_order_rx, #post_order, #post_order_prescription_img, #post_order_prescription_url, #post_order_rx
Methods included from Api::Drug
#get_drug_image, #get_drug_list, #get_drug_price
Constructor Details
#initialize(client_id, client_secret, channel, parnterkey, grant_type = "client_credentials", scope = "order", options = {}) ⇒ Client
options: redis_key, custom_access_token
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/haoyaoshi/client.rb', line 23 def initialize(client_id, client_secret, channel , parnterkey, grant_type = "client_credentials" , scope = "order", ={}) @client_id = client_id @client_secret = client_secret @expired_at = Time.now.to_i @channel = channel @parnterkey = parnterkey @grant_type = grant_type if grant_type.present? @scope = scope @redis_key = security_redis_key([:redis_key] || "haoyaoshi_#{client_id}") @custom_access_token = [:custom_access_token] @custom_token_type = [:custom_token_type] super() # Monitor#initialize end |
Instance Attribute Details
#access_token ⇒ Object
Returns the value of attribute access_token.
20 21 22 |
# File 'lib/haoyaoshi/client.rb', line 20 def access_token @access_token end |
#channel ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def channel @channel end |
#client_id ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def client_id @client_id end |
#client_secret ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def client_secret @client_secret end |
#custom_access_token ⇒ Object
Returns the value of attribute custom_access_token.
20 21 22 |
# File 'lib/haoyaoshi/client.rb', line 20 def custom_access_token @custom_access_token end |
#expired_at ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def expired_at @expired_at end |
#grant_type ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def grant_type @grant_type end |
#parnterkey ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def parnterkey @parnterkey end |
#redis_key ⇒ Object
Returns the value of attribute redis_key.
20 21 22 |
# File 'lib/haoyaoshi/client.rb', line 20 def redis_key @redis_key end |
#scope ⇒ Object
Time.now + expires_in
19 20 21 |
# File 'lib/haoyaoshi/client.rb', line 19 def scope @scope end |
#token_type ⇒ Object
Returns the value of attribute token_type.
20 21 22 |
# File 'lib/haoyaoshi/client.rb', line 20 def token_type @token_type end |
#token_type_token ⇒ Object
Returns the value of attribute token_type_token.
20 21 22 |
# File 'lib/haoyaoshi/client.rb', line 20 def token_type_token @token_type_token end |
Instance Method Details
#get_access_token ⇒ Object
return token
38 39 40 41 |
# File 'lib/haoyaoshi/client.rb', line 38 def get_access_token return custom_access_token if !custom_access_token.nil? synchronize{ token_store.access_token } end |
#get_token_type ⇒ Object
return token
44 45 46 47 |
# File 'lib/haoyaoshi/client.rb', line 44 def get_token_type return custom_token_type if !custom_token_type.nil? synchronize{ token_store.token_type } end |
#http_delete(url, delete_body = {}, url_params = {}, endpoint = "plain") ⇒ Object
70 71 72 73 74 |
# File 'lib/haoyaoshi/client.rb', line 70 def http_delete(url, delete_body={}, url_params={}, endpoint="plain") url_params = access_token_param.merge(url_params) url = "#{url}?access_token=#{get_access_token}" Haoyaoshi.http_delete_without_token(url, delete_body, url_params, endpoint) end |
#http_drug_get(url, url_params = {}, path = nil, endpoint = "plain") ⇒ Object
暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。
77 78 79 80 81 82 83 |
# File 'lib/haoyaoshi/client.rb', line 77 def http_drug_get(url, url_params = {}, path = nil, endpoint="plain") url_params = {channel: @channel}.merge(url_params) tmp_option = url_params.deep_dup url_params[:sign] = sign(tmp_option,path) Rails.logger.info("#{url_params[:sign]}") Haoyaoshi.http_get_without_token(url, url_params, endpoint) end |
#http_get(url, url_params = {}, endpoint = "plain") ⇒ Object
暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。
60 61 62 63 |
# File 'lib/haoyaoshi/client.rb', line 60 def http_get(url, url_params={}, endpoint="plain") url_params = url_params.merge(access_token_param) Haoyaoshi.http_get_without_token(url, url_params, endpoint) end |
#http_post(url, post_body = {}, url_params = {}, endpoint = "plain") ⇒ Object
65 66 67 68 |
# File 'lib/haoyaoshi/client.rb', line 65 def http_post(url, post_body={}, url_params={}, endpoint="plain") url_params = access_token_param.merge(url_params) Haoyaoshi.http_post_without_token(url, post_body, url_params, endpoint) end |
#is_valid? ⇒ Boolean
检查appid和app_secret是否有效。
50 51 52 53 |
# File 'lib/haoyaoshi/client.rb', line 50 def is_valid? return true if !custom_access_token.nil? token_store.valid? end |