wechat_public_api 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/README.md +6 -162
- data/lib/wechat_public_api/access_token.rb +33 -35
- data/lib/wechat_public_api/account.rb +89 -96
- data/lib/wechat_public_api/aes.rb +28 -31
- data/lib/wechat_public_api/kf_message.rb +117 -125
- data/lib/wechat_public_api/material.rb +36 -41
- data/lib/wechat_public_api/menu.rb +58 -63
- data/lib/wechat_public_api/templet_message.rb +87 -92
- data/lib/wechat_public_api/user.rb +30 -35
- data/lib/wechat_public_api/utils.rb +2 -5
- data/lib/wechat_public_api/version.rb +2 -2
- data/lib/wechat_public_api.rb +25 -5
- data/wechat_public_api-0.1.3.gem +0 -0
- data/wechat_public_api-0.1.4.gem +0 -0
- metadata +4 -2
@@ -5,105 +5,100 @@
|
|
5
5
|
# Wechat number: zmx119966
|
6
6
|
####################################################
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module WechatPublicApi
|
8
|
+
class WechatPublicApi
|
11
9
|
module Tp
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
# get access_token
|
20
|
-
access_token = AccessToken.get()
|
10
|
+
###
|
11
|
+
# @param <JSON> message
|
12
|
+
# @param <string> url_params -- 消息路径
|
13
|
+
# 发送模板消息接口
|
14
|
+
def post_template_message(message, url_params)
|
15
|
+
# get access_token
|
16
|
+
access_token = get_access_token()
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
@access_token = Wxutils.get_access_token wx_account
|
19
|
+
uri = URI.parse("https://api.weixin.qq.com/cgi-bin/message/template/#{url_params}?access_token=#{@access_token}")
|
20
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
21
|
+
http.use_ssl = true
|
22
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
23
|
+
request = Net::HTTP::Post.new("/cgi-bin/message/template/#{url_params}?access_token=#{@access_token}")
|
24
|
+
request.add_field('Content-Type', 'application/json')
|
25
|
+
# 部分字符转换为json后 成为unicode编码
|
26
|
+
request.body = message.to_json.gsub(/\\u([0-9a-z]{4})/) {|s| [$1.to_i(16)].pack("U")}
|
27
|
+
response = http.request(request)
|
28
|
+
JSON.parse(response.body)
|
29
|
+
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
31
|
+
###
|
32
|
+
# @param <string> openid -- 用户的openid
|
33
|
+
# @param <string> templet_id -- 微信公众号后台提供的模板ID
|
34
|
+
# @param <string> url -- 模板跳转链接
|
35
|
+
# @param <string> appid -- 小程序的appid
|
36
|
+
# @param <string> pagepath -- 小程序页面路径 (eq: /index/index)
|
37
|
+
# @param <JSON> data -- 模板数据
|
38
|
+
# => data example
|
39
|
+
# data = {
|
40
|
+
# "first": {
|
41
|
+
# "value":"恭喜你购买成功!",
|
42
|
+
# "color":"#173177"
|
43
|
+
# },
|
44
|
+
# "keyword1":{
|
45
|
+
# "value":"巧克力",
|
46
|
+
# "color":"#173177"
|
47
|
+
# },
|
48
|
+
# "keyword2": {
|
49
|
+
# "value":"39.8元",
|
50
|
+
# "color":"#173177"
|
51
|
+
# },
|
52
|
+
# "keyword3": {
|
53
|
+
# "value":"2014年9月22日",
|
54
|
+
# "color":"#173177"
|
55
|
+
# },
|
56
|
+
# "remark":{
|
57
|
+
# "value":"欢迎再次购买!",
|
58
|
+
# "color":"#173177"
|
59
|
+
# }
|
60
|
+
# }
|
61
|
+
# 小程序模板消息
|
62
|
+
def tp_miniprogram_message(openid, templet_id, url, appid, pagepath, data)
|
63
|
+
message = {
|
64
|
+
'touser': openid,
|
65
|
+
'template_id': templet_id,
|
66
|
+
'url': url,
|
67
|
+
"miniprogram":{
|
68
|
+
"appid": appid,
|
69
|
+
"pagepath": pagepath
|
70
|
+
},
|
71
|
+
'data': data
|
72
|
+
}
|
77
73
|
|
78
|
-
|
79
|
-
|
74
|
+
post_template_message message, 'send'
|
75
|
+
end
|
80
76
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
77
|
+
# 普通的模板消息,不跳转小程序
|
78
|
+
def tp_general_message(openid, templet_id, url, data)
|
79
|
+
message = {
|
80
|
+
'touser': openid,
|
81
|
+
'template_id': templet_id,
|
82
|
+
'url': url,
|
83
|
+
'data': data
|
84
|
+
}
|
85
|
+
post_template_message message, 'send'
|
86
|
+
end
|
91
87
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
88
|
+
# 删除模板
|
89
|
+
def tp_delete_template(templet_id)
|
90
|
+
message = {
|
91
|
+
'template_id': template_id
|
92
|
+
}
|
93
|
+
post_template_message message, 'del_private_template'
|
94
|
+
end
|
99
95
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
end
|
96
|
+
# 获得模板列表
|
97
|
+
def tp_get_all()
|
98
|
+
access_token = get_access_token()
|
99
|
+
response = HTTParty.get("https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=#{access_token}").body
|
100
|
+
response_body = (JSON.parse response)
|
101
|
+
response_body
|
107
102
|
end
|
108
103
|
end
|
109
104
|
end
|
@@ -5,42 +5,37 @@
|
|
5
5
|
# Wechat number: zmx119966
|
6
6
|
####################################################
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
module WechatPublicApi
|
8
|
+
class WechatPublicApi
|
11
9
|
module User
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
#
|
39
|
-
|
40
|
-
|
41
|
-
access_token = AccessToken.get()
|
42
|
-
JSON.parse HTTParty.get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=#{access_token}&openid=#{openid}&lang=zh_CN").body
|
43
|
-
end
|
10
|
+
# 获取用户信息
|
11
|
+
# @return <JSON>
|
12
|
+
# {
|
13
|
+
# "subscribe": 1,
|
14
|
+
# "openid": "o6_bmjrPTlm6_2sgVt7hMZOPfL2M",
|
15
|
+
# "nickname": "Band",
|
16
|
+
# "sex": 1,
|
17
|
+
# "language": "zh_CN",
|
18
|
+
# "city": "广州",
|
19
|
+
# "province": "广东",
|
20
|
+
# "country": "中国",
|
21
|
+
# "headimgurl":"http://thirdwx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
|
22
|
+
# "subscribe_time": 1382694957,
|
23
|
+
# "unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
|
24
|
+
# "remark": "",
|
25
|
+
# "groupid": 0,
|
26
|
+
# "tagid_list":[128,2],
|
27
|
+
# "subscribe_scene": "ADD_SCENE_QR_CODE",
|
28
|
+
# "qr_scene": 98765,
|
29
|
+
# "qr_scene_str": ""
|
30
|
+
# }
|
31
|
+
#
|
32
|
+
# if failed
|
33
|
+
# {"errcode":40013,"errmsg":"invalid appid"}
|
34
|
+
#
|
35
|
+
def get_userinfo(openid)
|
36
|
+
# request access_token
|
37
|
+
access_token = get_access_token()
|
38
|
+
JSON.parse HTTParty.get("https://api.weixin.qq.com/cgi-bin/user/info?access_token=#{access_token}&openid=#{openid}&lang=zh_CN").body
|
44
39
|
end
|
45
40
|
end
|
46
41
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.1.
|
1
|
+
class WechatPublicApi
|
2
|
+
VERSION = "0.1.5"
|
3
3
|
end
|
data/lib/wechat_public_api.rb
CHANGED
@@ -9,10 +9,30 @@ require "wechat_public_api/utils"
|
|
9
9
|
require "wechat_public_api/user"
|
10
10
|
require "wechat_public_api/material"
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
class WechatPublicApi
|
13
|
+
include AccessToken
|
14
|
+
include Account
|
15
|
+
include Aes
|
16
|
+
include Kf
|
17
|
+
include Material
|
18
|
+
include Menu
|
19
|
+
include Tp
|
20
|
+
include User
|
21
|
+
include Utils
|
22
|
+
|
23
|
+
# 默认不缓存 access_token, access_token_cache = True 缓存
|
24
|
+
# @param <hash> aoptions
|
25
|
+
# => example
|
26
|
+
# wechat_api = WechatPublicApi.new appid: 'xx', app_secret: 'xx', access_token_cache: true
|
27
|
+
# wechat_api.app_id -- get appid
|
28
|
+
#
|
29
|
+
# api.get_access_token
|
30
|
+
#
|
31
|
+
|
32
|
+
attr_accessor :app_id, :app_secret, :access_token_cache
|
33
|
+
def initialize(options={})
|
34
|
+
@app_id = options[:app_id]
|
35
|
+
@app_secret = options[:app_secret]
|
36
|
+
@access_token_cache = options[:access_token_cache]
|
17
37
|
end
|
18
38
|
end
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wechat_public_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '张明鑫 wechat number: zmx119966'
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-05-
|
11
|
+
date: 2018-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -137,6 +137,8 @@ files:
|
|
137
137
|
- lib/wechat_public_api/version.rb
|
138
138
|
- wechat_public_api-0.1.1.gem
|
139
139
|
- wechat_public_api-0.1.2.gem
|
140
|
+
- wechat_public_api-0.1.3.gem
|
141
|
+
- wechat_public_api-0.1.4.gem
|
140
142
|
- wechat_public_api.gemspec
|
141
143
|
homepage: https://github.com/Diyilou/wechat_public_api.git
|
142
144
|
licenses:
|