Class: Tls::Sig::Api::V2::Server
- Inherits:
-
Object
- Object
- Tls::Sig::Api::V2::Server
- Defined in:
- lib/tls/sig/api/v2.rb
Overview
class Error < StandardError; end Your code goes here…
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
-
#sdkappid ⇒ Object
Returns the value of attribute sdkappid.
Instance Method Summary collapse
-
#gen_sig(identifier, expire) ⇒ Object
/** * 生成 usersig * @param identifier 用户账号 * @param expire 有效期,单位秒 * @returns string 返回的 sig 值 */.
-
#gen_sig_with_userbuf(identifier, expire, userbuf) ⇒ Object
/** * 生成带 userbuf 的 usersig * @param identifier 用户账号 * @param expire 有效期,单位秒 * @param userBuf 用户数据 * @returns string 返回的 sig 值 */.
-
#initialize(sdkappid, key) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(sdkappid, key) ⇒ Server
Returns a new instance of Server.
18 19 20 21 |
# File 'lib/tls/sig/api/v2.rb', line 18 def initialize(sdkappid, key) @sdkappid = sdkappid @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
16 17 18 |
# File 'lib/tls/sig/api/v2.rb', line 16 def key @key end |
#sdkappid ⇒ Object
Returns the value of attribute sdkappid.
16 17 18 |
# File 'lib/tls/sig/api/v2.rb', line 16 def sdkappid @sdkappid end |
Instance Method Details
#gen_sig(identifier, expire) ⇒ Object
/**
* 生成 usersig
* @param identifier 用户账号
* @param expire 有效期,单位秒
* @returns {string} 返回的 sig 值
*/
29 30 31 |
# File 'lib/tls/sig/api/v2.rb', line 29 def gen_sig( identifier, expire) gen_sig_with_userbuf(identifier, expire, nil); end |
#gen_sig_with_userbuf(identifier, expire, userbuf) ⇒ Object
/**
-
生成带 userbuf 的 usersig
-
@param identifier 用户账号
-
@param expire 有效期,单位秒
-
@param userBuf 用户数据
-
@returns string 返回的 sig 值
*/
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/tls/sig/api/v2.rb', line 40 def gen_sig_with_userbuf( identifier, expire, userbuf) currTime = Time.now.to_i sigDoc = { "TLS.ver": "2.0", "TLS.identifier": identifier, "TLS.sdkappid": sdkappid , "TLS.expire": expire , "TLS.time": currTime } base64UserBuf = nil if userbuf != nil base64UserBuf = Base64.strict_encode64(userbuf) sigDoc["TLS.userbuf"] = base64UserBuf end sig = hmacsha256(identifier, currTime, expire, base64UserBuf); if sig == "" return ""; end sigDoc["TLS.sig"] = sig json = sigDoc.to_json data_compressed = Zlib::Deflate.deflate(json) base64str = Base64.strict_encode64(data_compressed) escape(base64str) end |