qplus 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -60,6 +60,11 @@ end
60
60
 
61
61
  + push
62
62
 
63
+ add this to your hosts file for test and remove it when in production
64
+ enviroment
65
+
66
+ `113.108.2.35`
67
+
63
68
  ``` ruby
64
69
  push_data = {
65
70
  "NUM" => 99,
@@ -78,6 +83,13 @@ if result['ERRCODE']==0
78
83
  end
79
84
  ```
80
85
 
86
+ + get login params
87
+
88
+ ``` ruby
89
+ user_ip = "your user ip"
90
+ login_params = qplus.get_login_params user_ip
91
+ ```
92
+
81
93
 
82
94
  ## Contributing
83
95
 
data/lib/qplus.rb CHANGED
@@ -10,10 +10,6 @@ module Qplus
10
10
  PUSH_URL = "http://tpns.qq.com/cgi-bin/app_push"
11
11
  OPEN_URL = "http://openid.qplus.com/cgi-bin/"
12
12
 
13
- def self.get_nonce
14
- rand 1_000_000_000..9_999_999_999
15
- end
16
-
17
13
  class App
18
14
 
19
15
  attr_accessor :app_id, :app_secret, :lang
@@ -24,25 +20,24 @@ module Qplus
24
20
  @lang = lang
25
21
  end
26
22
 
27
- def send_request(action, open_info, options)
28
- open_info.update options
29
- open_info.update :app_id => @app_id,
23
+ def send_request(action, open_data)
24
+ open_data.update :app_id => @app_id,
30
25
  :app_ts => Time.now.utc.to_i,
31
- :app_nonce => Qplus.get_nonce
32
- open_info = Hash[open_info.sort]
33
- sig = get_sig "#{action}&#{URI.encode_www_form open_info}"
34
- open_info.update :sig => sig
26
+ :app_nonce => get_nonce
27
+ open_data = Hash[open_data.sort]
28
+ sig = get_sig "#{action}&#{URI.encode_www_form open_data}"
29
+ open_data.update :sig => sig
35
30
  uri = URI(Qplus::OPEN_URL + action)
36
- res = Net::HTTP.post_form(uri, open_info)
31
+ res = Net::HTTP.post_form(uri, open_data)
37
32
  JSON.parse res.body
38
33
  end
39
34
 
40
- def get_userinfo(open_info, options = {} )
41
- send_request "app_get_userinfo", open_info, options
35
+ def get_userinfo(open_data)
36
+ send_request "app_get_userinfo", open_data
42
37
  end
43
38
 
44
- def check_login(open_info, options = {})
45
- send_request "app_verify", open_info, options
39
+ def check_login(open_data)
40
+ send_request "app_verify", open_data
46
41
  end
47
42
 
48
43
  def check_sig(url)
@@ -51,14 +46,33 @@ module Qplus
51
46
  sig.downcase == get_sig(data)
52
47
  end
53
48
 
49
+ def get_login_params(user_ip)
50
+ data = {
51
+ :app_id => @app_id,
52
+ :app_nonce => get_nonce,
53
+ :app_ts => Time.now.utc.to_i,
54
+ :app_userip => user_ip,
55
+ :app_lang => @lang
56
+ }
57
+
58
+ data = Hash[data.sort]
59
+
60
+ params = URI.encode_www_form data
61
+ login_params = params + "&sig=" + get_sig("app_qqlogin" + params)
62
+ end
63
+
54
64
  def get_sig(data)
55
65
  OpenSSL::HMAC.hexdigest("sha1", @app_secret, data)
56
66
  end
57
67
 
68
+ def get_nonce
69
+ rand 1_000_000_000..9_999_999_999
70
+ end
71
+
58
72
  def push(data)
59
73
  data.update "APPID" => @app_id,
60
74
  "TIME" => Time.now.utc.to_i,
61
- "NONCE" => Qplus.get_nonce
75
+ "NONCE" => get_nonce
62
76
  data = Hash[data.sort]
63
77
  # don't encode here
64
78
  sig = get_sig "app_push&#{ data.collect { |i| "#{i.first}=#{i.last}" }.join("&") }"
@@ -67,5 +81,4 @@ module Qplus
67
81
  JSON Net::HTTP.get(push_uri)
68
82
  end
69
83
  end
70
-
71
84
  end
data/lib/qplus/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qplus
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/spec/qplus_spec.rb CHANGED
@@ -4,19 +4,25 @@ require "qplus"
4
4
  describe Qplus do
5
5
  describe "App" do
6
6
  let(:q) { Qplus::App.new 200072992, "mVXsNvg0AzLk6mb6" }
7
+
7
8
  let(:data) { {
8
9
  :app_openid => "B587BF2B65C9A46EFC0D4CE150AF390C",
9
10
  :app_openkey => "7F8C45941EA5CC54EC2A8663A4F194C8",
10
11
  :app_userip => "127.0.0.1"
11
12
  } }
13
+
12
14
  let(:url) { "http://app.beva.com/qplus/kids?app_id=200072992&app_lang=2052&app_nonce=1969946501&app_openid=B587BF2B65C9A46EFC0D4CE150AF390C&app_openkey=7F8C45941EA5CC54EC2A8663A4F194C8&app_ts=1337848736&pf=qplus&sig=B6FC3D92A48FD2EAC9DEED00E81D486E47678E7B" }
15
+
13
16
  let(:sig) { "B6FC3D92A48FD2EAC9DEED00E81D486E47678E7B" }
17
+
14
18
  let(:params) { "app_id=200072992&app_lang=2052&app_nonce=1969946501&app_openid=B587BF2B65C9A46EFC0D4CE150AF390C&app_openkey=7F8C45941EA5CC54EC2A8663A4F194C8&app_ts=1337848736&pf=qplus" }
19
+
15
20
  let(:user_data) { {
16
21
  :app_openid => "B587BF2B65C9A46EFC0D4CE150AF390C",
17
22
  :app_openkey => "571336875C824D425CC956AE670CC796",
18
23
  :app_userip => "127.0.0.1"
19
24
  } }
25
+
20
26
  let(:push_data) { {
21
27
  "NUM" => 99,
22
28
  "APPCUSTOMIZE" => "param=你好",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-05-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
@@ -91,7 +91,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  segments:
93
93
  - 0
94
- hash: -522089631
94
+ hash: -664767725
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  segments:
102
102
  - 0
103
- hash: -522089631
103
+ hash: -664767725
104
104
  requirements: []
105
105
  rubyforge_project:
106
106
  rubygems_version: 1.8.24