weixin_authorize_superayi 1.6.4 → 1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/lib/{weixin_authorize.rb → weixin_authorize_superayi.rb} +12 -12
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api.rb +0 -0
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/custom.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/data_cube.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/groups.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/mass.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/media.rb +2 -2
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/menu.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/oauth.rb +6 -6
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/qrcode.rb +2 -2
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/template.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/api/user.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/carrierwave/weixin_uploader.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/client.rb +3 -3
- data/lib/{weixin_authorize → weixin_authorize_superayi}/config.rb +1 -1
- data/lib/weixin_authorize_superayi/handler.rb +3 -0
- data/lib/{weixin_authorize → weixin_authorize_superayi}/handler/exceptions.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/handler/global_code.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/handler/result_handler.rb +2 -2
- data/lib/{weixin_authorize → weixin_authorize_superayi}/js_ticket/object_store.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/js_ticket/redis_store.rb +2 -2
- data/lib/{weixin_authorize → weixin_authorize_superayi}/js_ticket/store.rb +3 -3
- data/lib/{weixin_authorize → weixin_authorize_superayi}/token/object_store.rb +1 -1
- data/lib/{weixin_authorize → weixin_authorize_superayi}/token/redis_store.rb +2 -2
- data/lib/{weixin_authorize → weixin_authorize_superayi}/token/store.rb +4 -4
- data/lib/weixin_authorize_superayi/version.rb +3 -0
- data/spec/1_fetch_access_token_spec.rb +5 -5
- data/spec/2_fetch_jsticket_spec.rb +1 -1
- data/spec/api/custom_spec.rb +6 -6
- data/spec/api/groups_spec.rb +6 -6
- data/spec/api/mass_spec.rb +7 -7
- data/spec/api/media_spec.rb +9 -9
- data/spec/api/menu_spec.rb +5 -5
- data/spec/api/qrcode_spec.rb +4 -4
- data/spec/api/template_spec.rb +2 -2
- data/spec/api/user_spec.rb +5 -5
- data/spec/spec_helper.rb +4 -4
- data/weixin_authorize_superayi.gemspec +4 -4
- metadata +29 -29
- data/lib/weixin_authorize/handler.rb +0 -3
- data/lib/weixin_authorize/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ab834294810890f57c25f446e5e8a4cbf15fc31
|
4
|
+
data.tar.gz: 30fe6438d59eafc4fb63ff0e848faf1fc0efc574
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 583653bc44edaad1963d4e5bd2d05a604b4dc8ac90ecfd079513c51787a4f1f6ccc53853e388b808cb79d4a607f0578cff009e2061eade46a7221373e048bab8
|
7
|
+
data.tar.gz: c2782589d278b964336e0193822245433df6448ddacf92aedb1de915e023291fdb9aa84b3662da00ec041e271e0a0c584b5fa1c9ecced64bc18a06a4b5729767
|
data/Gemfile
CHANGED
@@ -7,25 +7,25 @@ else
|
|
7
7
|
end
|
8
8
|
require "erb"
|
9
9
|
|
10
|
-
require "
|
11
|
-
require "
|
12
|
-
require "
|
13
|
-
require "
|
14
|
-
require "
|
10
|
+
require "weixin_authorize_superayi/carrierwave/weixin_uploader"
|
11
|
+
require "weixin_authorize_superayi/config"
|
12
|
+
require "weixin_authorize_superayi/handler"
|
13
|
+
require "weixin_authorize_superayi/api"
|
14
|
+
require "weixin_authorize_superayi/client"
|
15
15
|
|
16
|
-
module
|
16
|
+
module WeixinAuthorizeSuperayi
|
17
17
|
|
18
18
|
# token store
|
19
19
|
module Token
|
20
|
-
autoload(:Store, "
|
21
|
-
autoload(:ObjectStore, "
|
22
|
-
autoload(:RedisStore, "
|
20
|
+
autoload(:Store, "weixin_authorize_superayi/token/store")
|
21
|
+
autoload(:ObjectStore, "weixin_authorize_superayi/token/object_store")
|
22
|
+
autoload(:RedisStore, "weixin_authorize_superayi/token/redis_store")
|
23
23
|
end
|
24
24
|
|
25
25
|
module JsTicket
|
26
|
-
autoload(:Store, "
|
27
|
-
autoload(:ObjectStore, "
|
28
|
-
autoload(:RedisStore, "
|
26
|
+
autoload(:Store, "weixin_authorize_superayi/js_ticket/store")
|
27
|
+
autoload(:ObjectStore, "weixin_authorize_superayi/js_ticket/object_store")
|
28
|
+
autoload(:RedisStore, "weixin_authorize_superayi/js_ticket/redis_store")
|
29
29
|
end
|
30
30
|
|
31
31
|
OK_MSG = "ok".freeze
|
File without changes
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
3
|
+
module WeixinAuthorizeSuperayi
|
4
4
|
module Api
|
5
5
|
module Media
|
6
6
|
# 上传多媒体文件
|
@@ -15,7 +15,7 @@ module WeixinAuthorize
|
|
15
15
|
|
16
16
|
# 目前仅仅把下载链接返回给第三方开发者,由第三方开发者处理下载
|
17
17
|
def download_media_url(media_id)
|
18
|
-
download_media_url =
|
18
|
+
download_media_url = WeixinAuthorizeSuperayi.endpoint_url("file", "#{media_base_url}/get")
|
19
19
|
params = URI.encode_www_form("access_token" => get_access_token,
|
20
20
|
"media_id" => media_id)
|
21
21
|
download_media_url += "?#{params}"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
module Api
|
4
4
|
module Oauth
|
5
5
|
|
@@ -7,7 +7,7 @@ module WeixinAuthorize
|
|
7
7
|
# 文档:http://t.cn/RyZVWEY
|
8
8
|
def qrcode_authorize_url(redirect_uri, scope="snsapi_login", state="web_wx_login")
|
9
9
|
uri = encode_url(redirect_uri)
|
10
|
-
|
10
|
+
WeixinAuthorizeSuperayi.open_endpoint("/connect/qrconnect?appid=#{app_id}&redirect_uri=#{uri}&response_type=code&scope=#{scope}&state=#{state}#wechat_redirect")
|
11
11
|
end
|
12
12
|
|
13
13
|
# 应用授权作用域: scope
|
@@ -19,24 +19,24 @@ module WeixinAuthorize
|
|
19
19
|
# 如果用户点击同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE。若用户禁止授权,则重定向后不会带上code参数,仅会带上state参数redirect_uri?state=STATE
|
20
20
|
def authorize_url(redirect_uri, scope="snsapi_base", state="weixin")
|
21
21
|
uri = encode_url(redirect_uri)
|
22
|
-
|
22
|
+
WeixinAuthorizeSuperayi.open_endpoint("/connect/oauth2/authorize?appid=#{app_id}&redirect_uri=#{uri}&response_type=code&scope=#{scope}&state=#{state}#wechat_redirect")
|
23
23
|
end
|
24
24
|
|
25
25
|
# 首先请注意,这里通过code换取的网页授权access_token,与基础支持中的access_token不同。公众号可通过下述接口来获取网页授权access_token。如果网页授权的作用域为snsapi_base,则本步骤中获取到网页授权access_token的同时,也获取到了openid,snsapi_base式的网页授权流程即到此为止。
|
26
26
|
|
27
27
|
# 微信通过请求 #authorize_url 方法后,会返回一个code到redirect_uri中
|
28
28
|
def get_oauth_access_token(code)
|
29
|
-
|
29
|
+
WeixinAuthorizeSuperayi.http_get_without_token("/sns/oauth2/access_token?appid=#{app_id}&secret=#{app_secret}&code=#{code}&grant_type=authorization_code", {}, "api")
|
30
30
|
end
|
31
31
|
|
32
32
|
# refresh_token: 填写通过access_token获取到的refresh_token参数
|
33
33
|
def refresh_oauth2_token(refresh_token)
|
34
|
-
|
34
|
+
WeixinAuthorizeSuperayi.http_get_without_token("/sns/oauth2/refresh_token?appid=#{app_id}&grant_type=refresh_token&refresh_token=#{refresh_token}", {}, "api")
|
35
35
|
end
|
36
36
|
|
37
37
|
# 如果网页授权作用域为snsapi_userinfo,则此时开发者可以通过access_token和openid拉取用户信息了。
|
38
38
|
def get_oauth_userinfo(openid, oauth_token, lang="zh_CN")
|
39
|
-
|
39
|
+
WeixinAuthorizeSuperayi.http_get_without_token("/sns/userinfo?access_token=#{oauth_token}&openid=#{openid}&lang=#{lang}", {}, "api")
|
40
40
|
end
|
41
41
|
|
42
42
|
private
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
module Api
|
4
4
|
module Qrcode
|
5
5
|
# http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
|
@@ -32,7 +32,7 @@ module WeixinAuthorize
|
|
32
32
|
|
33
33
|
# 通过ticket换取二维码, 直接访问即可显示!
|
34
34
|
def qr_code_url(ticket)
|
35
|
-
|
35
|
+
WeixinAuthorizeSuperayi.mp_endpoint("/showqrcode?ticket=#{ticket}")
|
36
36
|
end
|
37
37
|
|
38
38
|
private
|
@@ -2,7 +2,7 @@
|
|
2
2
|
require "monitor"
|
3
3
|
require "redis"
|
4
4
|
require 'digest/md5'
|
5
|
-
module
|
5
|
+
module WeixinAuthorizeSuperayi
|
6
6
|
|
7
7
|
class Client
|
8
8
|
|
@@ -73,12 +73,12 @@ module WeixinAuthorize
|
|
73
73
|
# 暴露出:http_get,http_post两个方法,方便第三方开发者扩展未开发的微信API。
|
74
74
|
def http_get(url, url_params={}, endpoint="plain")
|
75
75
|
url_params = url_params.merge(access_token_param)
|
76
|
-
|
76
|
+
WeixinAuthorizeSuperayi.http_get_without_token(url, url_params, endpoint)
|
77
77
|
end
|
78
78
|
|
79
79
|
def http_post(url, post_body={}, url_params={}, endpoint="plain")
|
80
80
|
url_params = access_token_param.merge(url_params)
|
81
|
-
|
81
|
+
WeixinAuthorizeSuperayi.http_post_without_token(url, post_body, url_params, endpoint)
|
82
82
|
end
|
83
83
|
|
84
84
|
private
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
|
4
4
|
class ResultHandler
|
5
5
|
|
@@ -34,7 +34,7 @@ module WeixinAuthorize
|
|
34
34
|
private
|
35
35
|
|
36
36
|
# if define Rails constant
|
37
|
-
# result =
|
37
|
+
# result = WeixinAuthorizeSuperayi::ResultHandler.new("0", "success", {:ok => "true"})
|
38
38
|
# result.result["ok"] #=> true
|
39
39
|
# result.result[:ok] #=> true
|
40
40
|
# result.result['ok'] #=> true
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module WeixinAuthorizeSuperayi
|
2
2
|
module JsTicket
|
3
3
|
class RedisStore < Store
|
4
4
|
JSTICKET = "jsticket"
|
@@ -34,7 +34,7 @@ module WeixinAuthorize
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def weixin_redis
|
37
|
-
|
37
|
+
WeixinAuthorizeSuperayi.weixin_redis
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
module JsTicket
|
4
4
|
class Store
|
5
5
|
|
@@ -10,7 +10,7 @@ module WeixinAuthorize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.init_with(client)
|
13
|
-
if
|
13
|
+
if WeixinAuthorizeSuperayi.weixin_redis.nil?
|
14
14
|
ObjectStore.new(client)
|
15
15
|
else
|
16
16
|
RedisStore.new(client)
|
@@ -32,7 +32,7 @@ module WeixinAuthorize
|
|
32
32
|
def set_jsticket
|
33
33
|
result = client.http_get("/ticket/getticket", {type: 1}).result
|
34
34
|
client.jsticket = result["ticket"]
|
35
|
-
client.jsticket_expired_at =
|
35
|
+
client.jsticket_expired_at = WeixinAuthorizeSuperayi.calculate_expire(result["expires_in"])
|
36
36
|
end
|
37
37
|
|
38
38
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
module Token
|
4
4
|
class RedisStore < Store
|
5
5
|
|
@@ -30,7 +30,7 @@ module WeixinAuthorize
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def weixin_redis
|
33
|
-
|
33
|
+
WeixinAuthorizeSuperayi.weixin_redis
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
module
|
2
|
+
module WeixinAuthorizeSuperayi
|
3
3
|
module Token
|
4
4
|
class Store
|
5
5
|
|
@@ -10,7 +10,7 @@ module WeixinAuthorize
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.init_with(client)
|
13
|
-
if
|
13
|
+
if WeixinAuthorizeSuperayi.weixin_redis.nil?
|
14
14
|
ObjectStore.new(client)
|
15
15
|
else
|
16
16
|
RedisStore.new(client)
|
@@ -47,11 +47,11 @@ module WeixinAuthorize
|
|
47
47
|
def set_access_token(access_token_infos=nil)
|
48
48
|
token_infos = access_token_infos || http_get_access_token.result
|
49
49
|
client.access_token = token_infos["access_token"]
|
50
|
-
client.expired_at =
|
50
|
+
client.expired_at = WeixinAuthorizeSuperayi.calculate_expire(token_infos["expires_in"])
|
51
51
|
end
|
52
52
|
|
53
53
|
def http_get_access_token
|
54
|
-
|
54
|
+
WeixinAuthorizeSuperayi.http_get_without_token("/token", authenticate_headers)
|
55
55
|
end
|
56
56
|
|
57
57
|
def authenticate_headers
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# NOTE: the rspec should be test alonely.
|
2
|
-
describe
|
2
|
+
describe WeixinAuthorizeSuperayi::Client do
|
3
3
|
describe "#get access_token" do
|
4
4
|
it "return a access_token nil value before authenticate" do
|
5
5
|
expect($client.access_token).to eq(nil)
|
@@ -18,22 +18,22 @@ describe WeixinAuthorize::Client do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
it "return errorcode and errormsg when appid or appsecret is invalid" do
|
21
|
-
$client_1 =
|
21
|
+
$client_1 = WeixinAuthorizeSuperayi::Client.new("appid", "app_secret")
|
22
22
|
valid_info = $client_1.is_valid?
|
23
23
|
expect(valid_info).to eq(false)
|
24
24
|
end
|
25
25
|
|
26
26
|
it "#get_access_token should raise error if app_secret or appid is invalid" do
|
27
|
-
$client_2 =
|
27
|
+
$client_2 = WeixinAuthorizeSuperayi::Client.new("appid_2", "app_secret_2")
|
28
28
|
expect{$client_2.get_access_token}.to raise_error(RuntimeError)
|
29
29
|
end
|
30
30
|
|
31
31
|
it "#token_expired return the different access_token after token is expired" do
|
32
32
|
token_1 = $client.get_access_token
|
33
|
-
if
|
33
|
+
if WeixinAuthorizeSuperayi.weixin_redis.nil?
|
34
34
|
$client.expired_at = Time.now.to_i - 7300
|
35
35
|
else
|
36
|
-
|
36
|
+
WeixinAuthorizeSuperayi.weixin_redis.del($client.redis_key)
|
37
37
|
end
|
38
38
|
token_2 = $client.get_access_token
|
39
39
|
expect(token_1).to_not eq(token_2)
|
data/spec/api/custom_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::Custom do
|
2
2
|
let(:text_message) do
|
3
3
|
"text Custom message"
|
4
4
|
end
|
@@ -13,7 +13,7 @@ describe WeixinAuthorize::Api::Custom do
|
|
13
13
|
|
14
14
|
it "#send_text_custom" do
|
15
15
|
response = $client.send_text_custom(ENV["OPENID"], text_message)
|
16
|
-
expect(response.code).to eq(
|
16
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "#send_news_custom" do
|
@@ -30,14 +30,14 @@ describe WeixinAuthorize::Api::Custom do
|
|
30
30
|
"picurl"=> "http://www.baidu.com/img/bdlogo.gif"
|
31
31
|
}]
|
32
32
|
response = $client.send_news_custom(ENV["OPENID"], articles)
|
33
|
-
expect(response.code).to eq(
|
33
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
34
34
|
end
|
35
35
|
|
36
36
|
it "#send_image_custom" do
|
37
37
|
image = $client.upload_media(image_file, "image")
|
38
38
|
media_id = image.result["media_id"]
|
39
39
|
response = $client.send_image_custom(ENV["OPENID"], media_id)
|
40
|
-
expect(response.code).to eq(
|
40
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
41
41
|
end
|
42
42
|
|
43
43
|
it "#send_video_custom" do
|
@@ -59,13 +59,13 @@ describe WeixinAuthorize::Api::Custom do
|
|
59
59
|
it "#get_custom_msg_record" do
|
60
60
|
option = {pageindex: 1, pagesize: 10}
|
61
61
|
response = $client.get_custom_msg_record(Time.now - 10.days, Time.now, option)
|
62
|
-
expect(response.code).to eq(
|
62
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
63
63
|
expect(response.result.keys).to eq(["recordlist", "retcode"])
|
64
64
|
end
|
65
65
|
|
66
66
|
it "#create_kf_session" do
|
67
67
|
response = $client.create_kf_session("test1@test", ENV["APPID"], "test kfsession")
|
68
|
-
expect(response.code).to eq(
|
68
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
data/spec/api/groups_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::Groups do
|
2
2
|
|
3
3
|
let(:group_name) do
|
4
4
|
"test group_name"
|
@@ -21,14 +21,14 @@ describe WeixinAuthorize::Api::Groups do
|
|
21
21
|
group_ids.each do |group_id|
|
22
22
|
res = $client.delete_group(group_id)
|
23
23
|
if res.code.to_s != "45009"
|
24
|
-
expect(res.code).to eq(
|
24
|
+
expect(res.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
it "create a group" do
|
30
30
|
response = $client.create_group(group_name)
|
31
|
-
if response.code ==
|
31
|
+
if response.code == WeixinAuthorizeSuperayi::OK_CODE
|
32
32
|
expect(response.result["group"]["name"]).to eq(group_name)
|
33
33
|
else
|
34
34
|
expect(response.code).to eq(-1)
|
@@ -47,13 +47,13 @@ describe WeixinAuthorize::Api::Groups do
|
|
47
47
|
|
48
48
|
it "#update_group_name" do
|
49
49
|
response = $client.create_group(group_name)
|
50
|
-
if response.code !=
|
50
|
+
if response.code != WeixinAuthorizeSuperayi::OK_CODE
|
51
51
|
expect(response.code).to eq(-1)
|
52
52
|
puts "WEIXIN says: system error"
|
53
53
|
else
|
54
54
|
expect(response.result["group"]["name"]).to eq(group_name)
|
55
55
|
response = $client.update_group_name(response.result["group"]["id"], group_name_2)
|
56
|
-
expect(response.code).to eq(
|
56
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
57
57
|
groups = $client.groups
|
58
58
|
expect(groups.result["groups"][-1]["name"]).to eq(group_name_2)
|
59
59
|
end
|
@@ -68,7 +68,7 @@ describe WeixinAuthorize::Api::Groups do
|
|
68
68
|
|
69
69
|
it "#batch update group for openids" do
|
70
70
|
res = $client.batch_update_group_for_openids([ENV["OPENID"]], last_group_id)
|
71
|
-
expect(res.code).to eq(
|
71
|
+
expect(res.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
72
72
|
end
|
73
73
|
|
74
74
|
end
|
data/spec/api/mass_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
-
describe
|
3
|
+
describe WeixinAuthorizeSuperayi::Api::Mass do
|
4
4
|
|
5
5
|
let(:image_jpg_path) do
|
6
6
|
"#{File.dirname(__FILE__)}/medias/ruby-logo.jpg"
|
@@ -40,31 +40,31 @@ describe WeixinAuthorize::Api::Mass do
|
|
40
40
|
|
41
41
|
# upload news media
|
42
42
|
response = $client.upload_mass_news([news_media])
|
43
|
-
expect(response.code).to eq(
|
43
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
44
44
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
45
45
|
end
|
46
46
|
|
47
47
|
it "#mass_with_group with mpnews" do
|
48
48
|
response = $client.mass_with_group("1", "mass_group_text", "text")
|
49
|
-
expect(response.code).to eq(
|
49
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
50
50
|
end
|
51
51
|
|
52
52
|
it "#mass_with_groug send to all" do
|
53
53
|
response = $client.mass_with_group("1", "mass_group_text_to_all", "text", true)
|
54
|
-
expect(response.code).to eq(
|
54
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
55
55
|
end
|
56
56
|
|
57
57
|
it "#mass_with_openids with mpnews and can delete message" do
|
58
58
|
response = $client.mass_with_openids([ENV["OPENID"]], mass_media_id)
|
59
|
-
expect(response.code).to eq(
|
59
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
60
60
|
expect(response.result.keys).to eq(["msg_id"])
|
61
61
|
delete_res = $client.mass_delete_with_msgid(response.result["msg_id"])
|
62
|
-
expect(delete_res.code).to eq(
|
62
|
+
expect(delete_res.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
63
63
|
end
|
64
64
|
|
65
65
|
it "#mass_preview can preview by openid" do
|
66
66
|
response = $client.mass_preview(ENV["OPENID"], "mass_text", "text")
|
67
|
-
expect(response.code).to eq(
|
67
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
68
68
|
end
|
69
69
|
|
70
70
|
end
|
data/spec/api/media_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::Media do
|
2
2
|
|
3
3
|
let(:image_jpg_path) do
|
4
4
|
"#{File.dirname(__FILE__)}/medias/ruby-logo.jpg"
|
@@ -26,49 +26,49 @@ describe WeixinAuthorize::Api::Media do
|
|
26
26
|
|
27
27
|
it "can upload a jpg image and get url" do
|
28
28
|
response = $client.upload_image(image_jpg_file)
|
29
|
-
expect(response.code).to eq(
|
29
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
30
30
|
expect(response.result.keys).to eq(["url"])
|
31
31
|
end
|
32
32
|
|
33
33
|
it "can upload a png image and get url" do
|
34
34
|
response = $client.upload_image(remote_png_path)
|
35
|
-
expect(response.code).to eq(
|
35
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
36
36
|
expect(response.result.keys).to eq(["url"])
|
37
37
|
end
|
38
38
|
|
39
39
|
it "can upload a jpg File image" do
|
40
40
|
response = $client.upload_media(image_jpg_file, "image")
|
41
|
-
expect(response.code).to eq(
|
41
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
42
42
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
43
43
|
end
|
44
44
|
|
45
45
|
it "can upload a ico File image" do
|
46
46
|
response = $client.upload_media(image_ico_file, "image")
|
47
|
-
expect(response.code).to eq(
|
47
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
48
48
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
49
49
|
end
|
50
50
|
|
51
51
|
it "can upload a local image" do
|
52
52
|
response = $client.upload_media(image_jpg_path, "image")
|
53
|
-
expect(response.code).to eq(
|
53
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
54
54
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
55
55
|
end
|
56
56
|
|
57
57
|
it "can upload a local ico image" do
|
58
58
|
response = $client.upload_media(image_ico_path, "image")
|
59
|
-
expect(response.code).to eq(
|
59
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
60
60
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
61
61
|
end
|
62
62
|
|
63
63
|
it "can upload a remote png image" do
|
64
64
|
response = $client.upload_media(remote_png_path, "image")
|
65
|
-
expect(response.code).to eq(
|
65
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
66
66
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
67
67
|
end
|
68
68
|
|
69
69
|
it "can upload a remote jpg image" do
|
70
70
|
response = $client.upload_media(remote_jpg_path, "image")
|
71
|
-
expect(response.code).to eq(
|
71
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
72
72
|
expect(response.result.keys).to eq(["type", "media_id", "created_at"])
|
73
73
|
end
|
74
74
|
|
data/spec/api/menu_spec.rb
CHANGED
@@ -1,26 +1,26 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
describe
|
2
|
+
describe WeixinAuthorizeSuperayi::Api::Menu do
|
3
3
|
|
4
4
|
it "can create a menu" do
|
5
5
|
menu = '{"button":[{"type":"click","name":"今日歌曲","key":"V1001_TODAY_MUSIC"},{"type":"click","name":"歌手简介","key":"V1001_TODAY_SINGER"},{"name":"菜单","sub_button":[{"type":"view","name":"搜索","url":"http://www.soso.com/"},{"type":"view","name":"视频","url":"http://v.qq.com/"},{"type":"click","name":"赞一下我们","key":"V1001_GOOD"}]}]}'
|
6
6
|
response = $client.create_menu(JSON.load(menu)) # or Json string
|
7
|
-
expect(response.code).to eq(
|
7
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "can't create a menu if invalid button size" do
|
11
11
|
menu = '{"button":[]}'
|
12
12
|
response = $client.create_menu(menu)
|
13
|
-
expect(response.code).not_to eq(
|
13
|
+
expect(response.code).not_to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "can get a weixin Menu info" do
|
17
17
|
menu_info = $client.menu
|
18
18
|
expect(menu_info.result.keys[0]).to eq("menu")
|
19
|
-
expect(menu_info.code).to eq(
|
19
|
+
expect(menu_info.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "can delete weixin Menu" do
|
23
23
|
response = $client.delete_menu
|
24
|
-
expect(response.code).to eq(
|
24
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
25
25
|
end
|
26
26
|
end
|
data/spec/api/qrcode_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::Qrcode do
|
2
2
|
|
3
3
|
it "#create_qr_scene" do
|
4
4
|
response = $client.create_qr_scene("123")
|
5
|
-
expect(response.code).to eq(
|
5
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
6
6
|
expect(response.result.keys).to eq(["ticket", "expire_seconds", "url"])
|
7
7
|
expect(response.result["expire_seconds"]).to eq(1800)
|
8
8
|
end
|
9
9
|
|
10
10
|
it "#create_qr_limit_scene" do
|
11
11
|
response = $client.create_qr_limit_scene(scene_id: 1234, scene_str: "wechat")
|
12
|
-
expect(response.code).to eq(
|
12
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
13
13
|
expect(response.result.keys).to eq(["ticket", "url"])
|
14
14
|
end
|
15
15
|
|
16
16
|
it "#return_qr_url" do
|
17
17
|
response = $client.create_qr_limit_scene(scene_id: 1234, scene_str: "wechat")
|
18
18
|
qr_url = $client.qr_code_url(response.result["ticket"])
|
19
|
-
expect(response.code).to eq(
|
19
|
+
expect(response.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
20
20
|
expect(qr_url).to match(/(\S+\.(com|net|org|edu|gov)(\/\S+)?)/)
|
21
21
|
end
|
22
22
|
end
|
data/spec/api/template_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::Template do
|
2
2
|
# {{first.DATA}}
|
3
3
|
# 项目名称:{{class.DATA}}
|
4
4
|
# 时间:{{time.DATA}}
|
@@ -35,6 +35,6 @@ describe WeixinAuthorize::Api::Template do
|
|
35
35
|
"#173177",
|
36
36
|
data
|
37
37
|
)
|
38
|
-
expect(msg_result.code).to eq(
|
38
|
+
expect(msg_result.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
39
39
|
end
|
40
40
|
end
|
data/spec/api/user_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
describe
|
1
|
+
describe WeixinAuthorizeSuperayi::Api::User do
|
2
2
|
it "can get a weixin User info" do
|
3
3
|
user_info = $client.user(ENV["OPENID"])
|
4
|
-
expect(user_info.code).to eq(
|
4
|
+
expect(user_info.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
5
5
|
expect(user_info.result["openid"]).to eq(ENV["OPENID"])
|
6
6
|
end
|
7
7
|
|
@@ -9,18 +9,18 @@ describe WeixinAuthorize::Api::User do
|
|
9
9
|
valid_info = $client.is_valid?
|
10
10
|
expect(valid_info).to eq(true)
|
11
11
|
followers = $client.followers
|
12
|
-
expect(followers.code).to eq(
|
12
|
+
expect(followers.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
13
13
|
expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
|
14
14
|
|
15
15
|
valid_info = $client.is_valid?
|
16
16
|
expect(valid_info).to eq(true)
|
17
17
|
followers = $client.followers
|
18
|
-
expect(followers.code).to eq(
|
18
|
+
expect(followers.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
19
19
|
expect(followers.result.keys).to eq(["total", "count", "data", "next_openid"])
|
20
20
|
end
|
21
21
|
|
22
22
|
it "can update user remark" do
|
23
23
|
user_info = $client.update_remark(ENV["OPENID"], "dylan")
|
24
|
-
expect(user_info.code).to eq(
|
24
|
+
expect(user_info.code).to eq(WeixinAuthorizeSuperayi::OK_CODE)
|
25
25
|
end
|
26
26
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
#
|
15
15
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
16
|
require "rspec"
|
17
|
-
require "
|
17
|
+
require "weixin_authorize_superayi"
|
18
18
|
require "redis"
|
19
19
|
require "redis-namespace"
|
20
20
|
|
@@ -45,7 +45,7 @@ ENV["TEMPLATE_ID"]="-8ooXrOK3VD3HuSS8--nH154PO9Lw2E7T-RV1uTaGLc"
|
|
45
45
|
# Comment to test for ClientStorage
|
46
46
|
redis = Redis.new(host: "127.0.0.1", port: "6379", db: 15)
|
47
47
|
|
48
|
-
namespace = "weixin_test:
|
48
|
+
namespace = "weixin_test:weixin_authorize_superayi"
|
49
49
|
|
50
50
|
# cleanup keys in the current namespace when restart server everytime.
|
51
51
|
exist_keys = redis.keys("#{namespace}:*")
|
@@ -53,13 +53,13 @@ exist_keys.each{|key|redis.del(key)}
|
|
53
53
|
|
54
54
|
redis_with_ns = Redis::Namespace.new("#{namespace}", :redis => redis)
|
55
55
|
|
56
|
-
|
56
|
+
WeixinAuthorizeSuperayi.configure do |config|
|
57
57
|
config.redis = redis_with_ns
|
58
58
|
# config.key_expired = 200
|
59
59
|
config.rest_client_options = {timeout: 10, open_timeout: 10, verify_ssl: true}
|
60
60
|
end
|
61
61
|
|
62
|
-
$client =
|
62
|
+
$client = WeixinAuthorizeSuperayi::Client.new(ENV["APPID"], ENV["APPSECRET"])
|
63
63
|
|
64
64
|
RSpec.configure do |config|
|
65
65
|
# The settings below are suggested to provide a good initial experience
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require '
|
4
|
+
require 'weixin_authorize_superayi/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "weixin_authorize_superayi"
|
8
|
-
spec.version =
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
8
|
+
spec.version = WeixinAuthorizeSuperayi::VERSION
|
9
|
+
spec.authors = ["jeffsonit"]
|
10
|
+
spec.email = ["jeffsonit@gmial.com"]
|
11
11
|
spec.description = %q{weixin api authorize access_token}
|
12
12
|
spec.summary = %q{weixin api authorize access_token}
|
13
13
|
spec.homepage = "https://github.com/randeeshen/weixin_authorize_suerpayi"
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weixin_authorize_superayi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.6.
|
4
|
+
version: 1.6.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- jeffsonit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
@@ -208,7 +208,7 @@ dependencies:
|
|
208
208
|
version: '0'
|
209
209
|
description: weixin api authorize access_token
|
210
210
|
email:
|
211
|
-
-
|
211
|
+
- jeffsonit@gmial.com
|
212
212
|
executables: []
|
213
213
|
extensions: []
|
214
214
|
extra_rdoc_files: []
|
@@ -221,32 +221,32 @@ files:
|
|
221
221
|
- LICENSE.txt
|
222
222
|
- README.md
|
223
223
|
- Rakefile
|
224
|
-
- lib/
|
225
|
-
- lib/
|
226
|
-
- lib/
|
227
|
-
- lib/
|
228
|
-
- lib/
|
229
|
-
- lib/
|
230
|
-
- lib/
|
231
|
-
- lib/
|
232
|
-
- lib/
|
233
|
-
- lib/
|
234
|
-
- lib/
|
235
|
-
- lib/
|
236
|
-
- lib/
|
237
|
-
- lib/
|
238
|
-
- lib/
|
239
|
-
- lib/
|
240
|
-
- lib/
|
241
|
-
- lib/
|
242
|
-
- lib/
|
243
|
-
- lib/
|
244
|
-
- lib/
|
245
|
-
- lib/
|
246
|
-
- lib/
|
247
|
-
- lib/
|
248
|
-
- lib/
|
249
|
-
- lib/
|
224
|
+
- lib/weixin_authorize_superayi.rb
|
225
|
+
- lib/weixin_authorize_superayi/api.rb
|
226
|
+
- lib/weixin_authorize_superayi/api/custom.rb
|
227
|
+
- lib/weixin_authorize_superayi/api/data_cube.rb
|
228
|
+
- lib/weixin_authorize_superayi/api/groups.rb
|
229
|
+
- lib/weixin_authorize_superayi/api/mass.rb
|
230
|
+
- lib/weixin_authorize_superayi/api/media.rb
|
231
|
+
- lib/weixin_authorize_superayi/api/menu.rb
|
232
|
+
- lib/weixin_authorize_superayi/api/oauth.rb
|
233
|
+
- lib/weixin_authorize_superayi/api/qrcode.rb
|
234
|
+
- lib/weixin_authorize_superayi/api/template.rb
|
235
|
+
- lib/weixin_authorize_superayi/api/user.rb
|
236
|
+
- lib/weixin_authorize_superayi/carrierwave/weixin_uploader.rb
|
237
|
+
- lib/weixin_authorize_superayi/client.rb
|
238
|
+
- lib/weixin_authorize_superayi/config.rb
|
239
|
+
- lib/weixin_authorize_superayi/handler.rb
|
240
|
+
- lib/weixin_authorize_superayi/handler/exceptions.rb
|
241
|
+
- lib/weixin_authorize_superayi/handler/global_code.rb
|
242
|
+
- lib/weixin_authorize_superayi/handler/result_handler.rb
|
243
|
+
- lib/weixin_authorize_superayi/js_ticket/object_store.rb
|
244
|
+
- lib/weixin_authorize_superayi/js_ticket/redis_store.rb
|
245
|
+
- lib/weixin_authorize_superayi/js_ticket/store.rb
|
246
|
+
- lib/weixin_authorize_superayi/token/object_store.rb
|
247
|
+
- lib/weixin_authorize_superayi/token/redis_store.rb
|
248
|
+
- lib/weixin_authorize_superayi/token/store.rb
|
249
|
+
- lib/weixin_authorize_superayi/version.rb
|
250
250
|
- spec/1_fetch_access_token_spec.rb
|
251
251
|
- spec/2_fetch_jsticket_spec.rb
|
252
252
|
- spec/api/custom_spec.rb
|