wechat-sns 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8241ec82a3b4c5bc58fa6cef8d01460b8dc8cfe1
4
- data.tar.gz: 979479374d24ec788f4e6072dce4642bedd43ea0
3
+ metadata.gz: e1243379a4457716883ee3744a2c8b617a8d0801
4
+ data.tar.gz: 9611bd6bb6e351571c364cf0166acbcce1e1e7e7
5
5
  SHA512:
6
- metadata.gz: 627cd9f16ec99f45e6cd067302d0214f48e29f83bf61b788a30eff2fd70f1364d727f11b29b1e43ed88be128bf4306b1ab951291c91814e4e4c14cb721c932b0
7
- data.tar.gz: c56980daf80df6ed17d8e3c9adce03c3ecbc34745674366065aea8117d6b10137d404719ce587c2dfe673d94bf401be6c95aebd213ae1b8ea954eb399e17cdd3
6
+ metadata.gz: 2ac83a6c132dd7b6eb7b05fd10e2819757205564f1591dcf31447649cdaa5e60b4655a206ced0c7906d6430003b3068b208e338364d0e171aba6808773eaf5a6
7
+ data.tar.gz: 77faf0979f3346a05a85386ffad25aad19272007305457676524fbd339caee06efe5f9d2000e40c4bfadcda1e0e41c6f8006447bef89a920c7f5de953ac37c06
data/CHANGELOG.md CHANGED
@@ -8,3 +8,6 @@
8
8
 
9
9
  ## v0.3
10
10
  1. User Profile wrapper class.
11
+
12
+ ## v0.4
13
+ 1, Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret.
data/README.md CHANGED
@@ -23,9 +23,50 @@ Or install it yourself as:
23
23
 
24
24
  ## Usage
25
25
 
26
- Generate an authorize URL.
26
+ [Generate an Authorize URL and Redirect 第一步:用户同意授权,获取code](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E7.94.A8.E6.88.B7.E5.90.8C.E6.84.8F.E6.8E.88.E6.9D.83.EF.BC.8C.E8.8E.B7.E5.8F.96code)
27
27
  ```ruby
28
- redirect_to Wechat::SNS::AuthorizeLink.create(Rails.application.secrets.wechat_app_id, 'http://project.company.com/dashboards/~')
28
+ redirect_to Wechat::SNS::AuthorizeLink.create(Rails.application.secrets.wechat_app_id, 'http://product.company.com/promotion/page.html')
29
+ ```
30
+
31
+ [Get Access Token per Code 第二步:通过code换取网页授权access_token](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.80.9A.E8.BF.87code.E6.8D.A2.E5.8F.96.E7.BD.91.E9.A1.B5.E6.8E.88.E6.9D.83access_token)
32
+ ```ruby
33
+ response = Wechat::SNS::AccessToken.create Rails.application.secrets.wechat_app_id, Rails.application.secrets.wechat_app_secret, params[:code]
34
+ if response.present?
35
+ access_token = response['access_token']
36
+ expires_in = response['expires_in']
37
+ refresh_token = response['refresh_token']
38
+ open_id = response['openid']
39
+ scope = response['scope']
40
+ union_id = response['unionid']
41
+ end
42
+ ```
43
+
44
+ [Refresh Access Token 第三步:刷新access_token(如果需要)](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E4.B8.89.E6.AD.A5.EF.BC.9A.E5.88.B7.E6.96.B0access_token.EF.BC.88.E5.A6.82.E6.9E.9C.E9.9C.80.E8.A6.81.EF.BC.89)
45
+ ```ruby
46
+ response = Wechat::SNS::AccessToken.update Rails.application.secrets.wechat_app_id, refresh_token
47
+ if response.present?
48
+ access_token = response['access_token']
49
+ expires_in = response['expires_in']
50
+ refresh_token = response['refresh_token']
51
+ open_id = response['openid']
52
+ scope = response['scope']
53
+ end
54
+ ```
55
+
56
+ [Get User Profile per Access Token 第四步:拉取用户信息(需scope为 snsapi_userinfo)](http://mp.weixin.qq.com/wiki/9/01f711493b5a02f24b04365ac5d8fd95.html#.E7.AC.AC.E5.9B.9B.E6.AD.A5.EF.BC.9A.E6.8B.89.E5.8F.96.E7.94.A8.E6.88.B7.E4.BF.A1.E6.81.AF.28.E9.9C.80scope.E4.B8.BA_snsapi_userinfo.29)
57
+ ```ruby
58
+ response = Wechat::Sns::UserProfile.load access_token, open_id
59
+ if response.present? && response['errcode'].blank?
60
+ open_id = response['openid']
61
+ nick_name = response['nickname']
62
+ sex = response['sex']
63
+ city = response['city']
64
+ province = response['province']
65
+ country = response['country']
66
+ head_image_url = response['headimgurl']
67
+ privilege = response['privilege']
68
+ union_id = response['unionid']
69
+ end
29
70
  ```
30
71
 
31
72
  ## Development
data/ROADMAP.md CHANGED
@@ -8,3 +8,6 @@
8
8
 
9
9
  ## v0.3
10
10
  1. User Profile wrapper class.
11
+
12
+ ## v0.4
13
+ 1, Improved Access Token wrapper class to paramiterize the Wechat App ID and Wechat App Secret.
@@ -44,10 +44,10 @@ class Wechat::SNS::AccessToken
44
44
  # errcode: <ERROR_CODE>,
45
45
  # errmsg: <ERROR_MESSAGE>
46
46
  # }
47
- def self.update(refresh_token)
47
+ def self.update(app_id, refresh_token)
48
48
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/oauth2/refresh_token',
49
49
  {
50
- appid: Rails.application.secrets.wechat_app_id,
50
+ appid: app_id,
51
51
  grant_type: 'refresh_token',
52
52
  refresh_token: refresh_token
53
53
  }
@@ -72,11 +72,11 @@ class Wechat::SNS::AccessToken
72
72
  # errcode: <ERROR_CODE>,
73
73
  # errmsg: <ERROR_MESSAGE>
74
74
  # }
75
- def self.create(code)
75
+ def self.create(app_id, app_secret, code)
76
76
  message = ::JSONClient.new.get 'https://api.weixin.qq.com/sns/oauth2/access_token',
77
77
  {
78
- appid: Rails.application.secrets.wechat_app_id,
79
- secret: Rails.application.secrets.wechat_app_secret,
78
+ appid: app_id,
79
+ secret: app_secret,
80
80
  code: code,
81
81
  grant_type: 'authorization_code'
82
82
  }
@@ -1,5 +1,5 @@
1
1
  module Wechat
2
2
  module SNS
3
- VERSION = '0.3'.freeze
3
+ VERSION = '0.4'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wechat-sns
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler