easy_weixin 0.0.2 → 0.0.3
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/Gemfile +1 -0
- data/README.html +279 -0
- data/README.md +32 -9
- data/lib/easy_weixin/auth.rb +24 -0
- data/lib/easy_weixin/version.rb +1 -1
- data/lib/easy_weixin.rb +7 -0
- data/spec/auth_spec.rb +20 -0
- data/spec/reply_spec.rb +54 -0
- data/spec/test_xml.rb +17 -0
- metadata +23 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 332761963402ed43e415a5bfd2ff20c9dbb764f5
|
4
|
+
data.tar.gz: c6c8b3db010bfba35737ad8c668d5e0e6e6b9e4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c27e61c6d0e9723dfe85a60357bb75758a6823acaf9d1405921d69d65c3e8e53368b6e9170579b8f48f72c3dae89637578ab02c81215b10d38cbbc0f315d0ef
|
7
|
+
data.tar.gz: e2bba922fe354360985ada3841edeb8f17cde2c519803886975ce77dc70ef5f76cff7c66d68bc8e6191eaf47d854e3219db39e7d66aa2fe084e511b52fb8c5da
|
data/Gemfile
CHANGED
data/README.html
ADDED
@@ -0,0 +1,279 @@
|
|
1
|
+
<!DOCTYPE html><html><head><meta charset="utf-8"><style>/* Fonts */
|
2
|
+
@font-face{
|
3
|
+
font-family: octicons-anchor;
|
4
|
+
src: url(data:x-font-woff;charset=utf-8;base64,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) format('woff');
|
5
|
+
}
|
6
|
+
|
7
|
+
/* Body */
|
8
|
+
html { font-size: 100%; overflow-y: scroll; -webkit-text-size-adjust: 100%; -ms-text-size-adjust: 100%; }
|
9
|
+
|
10
|
+
body{
|
11
|
+
color:#4d4d4c;
|
12
|
+
font-family:Georgia, Palatino, 'Palatino Linotype', Times, 'Times New Roman',
|
13
|
+
"Hiragino Sans GB", "STXihei", "微软雅黑", serif;
|
14
|
+
font-size:12px;
|
15
|
+
line-height:1.5em;
|
16
|
+
background:#fefefe;
|
17
|
+
width: 45em;
|
18
|
+
margin: 10px auto;
|
19
|
+
padding: 30px;
|
20
|
+
border: 1px solid #ddd;
|
21
|
+
outline: 1300px solid #f8f8f8;
|
22
|
+
}
|
23
|
+
|
24
|
+
/* Links */
|
25
|
+
a{ color: #06d; text-decoration:none; }
|
26
|
+
a:hover{ color: #06e; text-decoration: underline; }
|
27
|
+
a:active{ color:#faa700; }
|
28
|
+
a:focus{ outline: thin dotted; }
|
29
|
+
a:hover, a:active{ outline: 0; }
|
30
|
+
|
31
|
+
::-moz-selection { background:rgba(255,255,0,0.3); color:#000 }
|
32
|
+
::selection { background:rgba(255,255,0,0.3); color:#000 }
|
33
|
+
|
34
|
+
a::-moz-selection { background:rgba(255,255,0,0.3); color:#0645ad }
|
35
|
+
a::selection { background:rgba(255,255,0,0.3); color:#0645ad }
|
36
|
+
|
37
|
+
/* Header Anchor Links*/
|
38
|
+
a.headeranchor-link {
|
39
|
+
color:#111;
|
40
|
+
border: 0;
|
41
|
+
margin-left: -20px;
|
42
|
+
padding-right: 6px;
|
43
|
+
cursor: pointer;
|
44
|
+
position: absolute;
|
45
|
+
display: block;
|
46
|
+
top: 0;
|
47
|
+
left: 0;
|
48
|
+
bottom: 0;
|
49
|
+
}
|
50
|
+
|
51
|
+
span.headeranchor {
|
52
|
+
font: normal normal 16px octicons-anchor;
|
53
|
+
line-height: 1;
|
54
|
+
-moz-osx-font-smoothing: grayscale;
|
55
|
+
-webkit-user-select: none;
|
56
|
+
-moz-user-select: none;
|
57
|
+
-ms-user-select: none;
|
58
|
+
user-select: none;
|
59
|
+
}
|
60
|
+
|
61
|
+
a.headeranchor-link:hover { text-decoration: none;}
|
62
|
+
a.headeranchor-link:visited { color:#4d4d4c; }
|
63
|
+
a.headeranchor-link:active { color:#4d4d4c; }
|
64
|
+
a.headeranchor-link:hover span.headeranchor:before { content: '\f05c'; }
|
65
|
+
h1:hover a span.headeranchor:before { content: '\f05c'; }
|
66
|
+
h2:hover a span.headeranchor:before { content: '\f05c'; }
|
67
|
+
h3:hover a span.headeranchor:before { content: '\f05c'; }
|
68
|
+
h4:hover a span.headeranchor:before { content: '\f05c'; }
|
69
|
+
h5:hover a span.headeranchor:before { content: '\f05c'; }
|
70
|
+
h6:hover a span.headeranchor:before { content: '\f05c'; }
|
71
|
+
|
72
|
+
/* Paragraphs */
|
73
|
+
p { margin:1em 0; }
|
74
|
+
|
75
|
+
/* Images */
|
76
|
+
img {
|
77
|
+
max-width:100%;
|
78
|
+
border: 0;
|
79
|
+
-ms-interpolation-mode: bicubic;
|
80
|
+
vertical-align: middle;
|
81
|
+
}
|
82
|
+
|
83
|
+
/* Headers */
|
84
|
+
h1,h2,h3,h4,h5,h6 {
|
85
|
+
font-weight:normal;
|
86
|
+
color:#111;
|
87
|
+
line-height: 1.7;
|
88
|
+
position: relative;
|
89
|
+
}
|
90
|
+
h4,h5,h6{ font-weight: bold; }
|
91
|
+
h1 { font-size:2.5em; border-bottom: 1px solid #ddd;}
|
92
|
+
h2 { font-size:2em; border-bottom:1px solid #eee; padding-bottom: 5px; }
|
93
|
+
h3 { font-size:1.5em; }
|
94
|
+
h4 { font-size:1.2em; }
|
95
|
+
h5 { font-size:1em; }
|
96
|
+
h6 { font-size:0.9em; }
|
97
|
+
|
98
|
+
/* Block Quotes */
|
99
|
+
blockquote {
|
100
|
+
color:#666666;
|
101
|
+
margin:0;
|
102
|
+
padding-left: 3em;
|
103
|
+
border-left: 0.5em #EEE solid;
|
104
|
+
}
|
105
|
+
hr { display: block; height: 2px; border: 0; border-top: 1px solid #aaa;border-bottom: 1px solid #eee; margin: 1em 0; padding: 0; }
|
106
|
+
|
107
|
+
/* Raw Blocks */
|
108
|
+
span.backtick {
|
109
|
+
border:1px solid #EAEAEA;
|
110
|
+
border-radius:3px;
|
111
|
+
background:#F8F8F8;
|
112
|
+
padding:0 3px 0 3px;
|
113
|
+
}
|
114
|
+
|
115
|
+
pre, code, kbd, samp {
|
116
|
+
color: #000;
|
117
|
+
font-family: monospace;
|
118
|
+
-webkit-border-radius: 3px;
|
119
|
+
-moz-border-radius: 3px;
|
120
|
+
border-radius: 3px;
|
121
|
+
font-size: 0.88em;
|
122
|
+
background-color: #F8F8F8;
|
123
|
+
border: 1px solid #CCC;
|
124
|
+
}
|
125
|
+
|
126
|
+
pre {
|
127
|
+
white-space: pre;
|
128
|
+
white-space: pre-wrap;
|
129
|
+
word-wrap: break-word;
|
130
|
+
padding: 10px;
|
131
|
+
}
|
132
|
+
|
133
|
+
pre code { border: 0 }
|
134
|
+
|
135
|
+
code { padding: 0 3px 0 3px; }
|
136
|
+
|
137
|
+
/* Multimarkdown Critic Blocks */
|
138
|
+
span.critic_mark { background: #ff0; }
|
139
|
+
span.critic_delete { color: #c82829; text-decoration: line-through; }
|
140
|
+
span.critic_insert { color: #718c00 ; text-decoration: underline; }
|
141
|
+
span.critic_comment { color: #8e908c; font-style: italic; }
|
142
|
+
|
143
|
+
/* Inlines */
|
144
|
+
b, strong { font-weight: bold; }
|
145
|
+
|
146
|
+
ins { background: #ff9; color: #000; text-decoration: none; }
|
147
|
+
|
148
|
+
mark { background: #ff0; color: #000; font-style: italic; font-weight: bold; }
|
149
|
+
|
150
|
+
sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; }
|
151
|
+
sup { top: -0.5em; }
|
152
|
+
sub { bottom: -0.25em; }
|
153
|
+
|
154
|
+
dfn { font-style: italic; }
|
155
|
+
|
156
|
+
/* Lists */
|
157
|
+
ul, ol { margin: 0.5em 0; padding: 0 0 0 2em; }
|
158
|
+
li p:last-child { margin:0 }
|
159
|
+
li.task-list-item { list-style-type: none; margin-left: -1.5em; }
|
160
|
+
li.task-list-item input { margin-right: .5em; }
|
161
|
+
li.task-list-item ul, li.task-list-item ol { margin-left: 1.5em; }
|
162
|
+
dd { margin: 0 0 0 2em; }
|
163
|
+
|
164
|
+
/* Tables */
|
165
|
+
table { border-collapse: collapse; border: 1px solid #ddd; }
|
166
|
+
table tr:nth-child(2n) { background-color: #f8f8f8; }
|
167
|
+
td, th { border: 1px solid #ddd; padding: 6px 13px; }
|
168
|
+
|
169
|
+
/* Codehilite Tables */
|
170
|
+
table.codehilitetable { border: 0; border-spacing: 0; width: 100%; }
|
171
|
+
td.linenos, td.code, table.codehilitetable td { border: 0; padding: 0; }
|
172
|
+
table.codehilitetable td:not(.linenos) div.linenodiv { padding: 0 !important; }
|
173
|
+
td.code { width: 100%; }
|
174
|
+
table.codehilitetable td.linenos div pre, td div.linenodiv pre {
|
175
|
+
border: 0;
|
176
|
+
border-top: 1px solid #CCC;
|
177
|
+
border-left: 1px solid #CCC;
|
178
|
+
border-right: 1px solid #CCC;
|
179
|
+
border-bottom: 1px solid #CCC;
|
180
|
+
-webkit-border-radius: 0;
|
181
|
+
-moz-border-radius: 0;
|
182
|
+
border-radius: 0;
|
183
|
+
-webkit-border-top-left-radius: 3px;
|
184
|
+
-webkit-border-bottom-left-radius: 3px;
|
185
|
+
-moz-border-radius-topleft: 3px;
|
186
|
+
-moz-border-radius-bottomleft: 3px;
|
187
|
+
border-top-left-radius: 3px;
|
188
|
+
border-bottom-left-radius: 3px;
|
189
|
+
}
|
190
|
+
|
191
|
+
table.codehilitetable td.code div pre {
|
192
|
+
border: 0;
|
193
|
+
border-top: 1px solid #CCC;
|
194
|
+
border-right: 1px solid #CCC;
|
195
|
+
border-bottom: 1px solid #CCC;
|
196
|
+
-webkit-border-radius: 0;
|
197
|
+
-moz-border-radius: 0;
|
198
|
+
border-radius: 0;
|
199
|
+
-webkit-border-top-right-radius: 3px;
|
200
|
+
-webkit-border-bottom-right-radius: 3px;
|
201
|
+
-moz-border-radius-topright: 3px;
|
202
|
+
-moz-border-radius-bottomright: 3px;
|
203
|
+
border-top-right-radius: 3px;
|
204
|
+
border-bottom-right-radius: 3px;
|
205
|
+
}
|
206
|
+
|
207
|
+
/* Media */
|
208
|
+
@media only screen and (min-width: 480px) {
|
209
|
+
body{ font-size:14px; }
|
210
|
+
}
|
211
|
+
|
212
|
+
@media only screen and (min-width: 768px) {
|
213
|
+
body{ font-size:16px; }
|
214
|
+
}
|
215
|
+
|
216
|
+
@media print {
|
217
|
+
* { background: transparent !important; color: black !important; filter:none !important; -ms-filter: none !important; }
|
218
|
+
body{ font-size:12pt; max-width:100%; outline:none; border: 0;}
|
219
|
+
a, a:visited { text-decoration: underline; }
|
220
|
+
a.headeranchor-link { display: none; }
|
221
|
+
hr { height: 1px; border:0; border-bottom:1px solid black; }
|
222
|
+
a[href]:after { content: " (" attr(href) ")"; }
|
223
|
+
abbr[title]:after { content: " (" attr(title) ")"; }
|
224
|
+
.ir a:after, a[href^="javascript:"]:after, a[href^="#"]:after { content: ""; }
|
225
|
+
pre, blockquote { border: 1px solid #999; padding-right: 1em; page-break-inside: avoid; }
|
226
|
+
tr, img { page-break-inside: avoid; }
|
227
|
+
img { max-width: 100% !important; }
|
228
|
+
p, h2, h3 { orphans: 3; widows: 3; }
|
229
|
+
h2, h3 { page-break-after: avoid; }
|
230
|
+
}
|
231
|
+
</style><title>README</title></head><body><h1 id="easyweixin"><a name="user-content-easyweixin" href="#easyweixin" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>EasyWeixin</h1>
|
232
|
+
<p>A Simple gem for weixin</p>
|
233
|
+
<h2 id="installation"><a name="user-content-installation" href="#installation" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Installation</h2>
|
234
|
+
<pre><code>gem install easy_weixin
|
235
|
+
</code></pre>
|
236
|
+
<h2 id="usage"><a name="user-content-usage" href="#usage" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Usage</h2>
|
237
|
+
<p>check_valid</p>
|
238
|
+
<h3 id="check"><a name="user-content-check" href="#check" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>check</h3>
|
239
|
+
<pre><code>easy_weixin = EasyWeixin::Auth.new(@token, @timestamp, @nonce, @signature, @echostr)
|
240
|
+
|
241
|
+
easy_weixin.check_valid # => @echostr or false
|
242
|
+
</code></pre>
|
243
|
+
<h3 id="analysis-xml"><a name="user-content-analysis-xml" href="#analysis-xml" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>analysis xml</h3>
|
244
|
+
<pre><code>msg = EasyWeixin::Message.factory(xml)
|
245
|
+
</code></pre>
|
246
|
+
<h3 id="reply"><a name="user-content-reply" href="#reply" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>reply</h3>
|
247
|
+
<ul>
|
248
|
+
<li>ReplyText</li>
|
249
|
+
</ul>
|
250
|
+
<pre><code> msg = EasyWeixin::Message.factory(xml)
|
251
|
+
EasyWeixin.text_msg(msg.ToUserName, msg.FromUserName, 'i am a text reply')
|
252
|
+
</code></pre>
|
253
|
+
|
254
|
+
<ul>
|
255
|
+
<li>ReplyNews</li>
|
256
|
+
</ul>
|
257
|
+
<pre><code> msg = EasyWeixin::Message.factory(xml)
|
258
|
+
if msg.Content == 'Hello2BizUser'
|
259
|
+
item1 = EasyWeixin::Item.new
|
260
|
+
item1.Title = 'title1'
|
261
|
+
item1.Description = 'blah'
|
262
|
+
item2 = EasyWeixin::Item.new
|
263
|
+
item2.Title = 'title2'
|
264
|
+
item2.Description = 'blah blah'
|
265
|
+
Articles = [item1, item2]
|
266
|
+
ArticleCount = Articles.size
|
267
|
+
end
|
268
|
+
|
269
|
+
EasyWeixin.news_msg(msg.ToUserName, msg.FromUserName, Articles, ArticleCount)
|
270
|
+
</code></pre>
|
271
|
+
|
272
|
+
<h2 id="contributing"><a name="user-content-contributing" href="#contributing" class="headeranchor-link" aria-hidden="true"><span class="headeranchor"></span></a>Contributing</h2>
|
273
|
+
<ol>
|
274
|
+
<li>Fork it ( <a href="http://github.com/">http://github.com/</a><my-github-username>/easy_weixin/fork )</li>
|
275
|
+
<li>Create your feature branch (<code>git checkout -b my-new-feature</code>)</li>
|
276
|
+
<li>Commit your changes (<code>git commit -am 'Add some feature'</code>)</li>
|
277
|
+
<li>Push to the branch (<code>git push origin my-new-feature</code>)</li>
|
278
|
+
<li>Create new Pull Request</li>
|
279
|
+
</ol></body></html>
|
data/README.md
CHANGED
@@ -1,24 +1,47 @@
|
|
1
1
|
# EasyWeixin
|
2
2
|
|
3
|
-
|
3
|
+
A Simple gem for weixin
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
gem install easy_weixin
|
8
8
|
|
9
|
-
|
9
|
+
## Usage
|
10
10
|
|
11
|
-
|
11
|
+
check_valid
|
12
12
|
|
13
|
-
|
13
|
+
### check
|
14
14
|
|
15
|
-
|
15
|
+
easy_weixin = EasyWeixin::Auth.new(@token, @timestamp, @nonce, @signature, @echostr)
|
16
16
|
|
17
|
-
|
17
|
+
easy_weixin.check_valid # => @echostr or false
|
18
18
|
|
19
|
-
|
19
|
+
### analysis xml
|
20
|
+
msg = EasyWeixin::Message.factory(xml)
|
21
|
+
|
22
|
+
### reply
|
23
|
+
|
24
|
+
* ReplyText
|
25
|
+
```
|
26
|
+
msg = EasyWeixin::Message.factory(xml)
|
27
|
+
EasyWeixin.text_msg(msg.ToUserName, msg.FromUserName, 'i am a text reply')
|
28
|
+
```
|
29
|
+
* ReplyNews
|
30
|
+
```
|
31
|
+
msg = EasyWeixin::Message.factory(xml)
|
32
|
+
if msg.Content == 'Hello2BizUser'
|
33
|
+
item1 = EasyWeixin::Item.new
|
34
|
+
item1.Title = 'title1'
|
35
|
+
item1.Description = 'blah'
|
36
|
+
item2 = EasyWeixin::Item.new
|
37
|
+
item2.Title = 'title2'
|
38
|
+
item2.Description = 'blah blah'
|
39
|
+
Articles = [item1, item2]
|
40
|
+
ArticleCount = Articles.size
|
41
|
+
end
|
20
42
|
|
21
|
-
|
43
|
+
EasyWeixin.news_msg(msg.ToUserName, msg.FromUserName, Articles, ArticleCount)
|
44
|
+
```
|
22
45
|
|
23
46
|
## Contributing
|
24
47
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# 接入认证
|
2
|
+
|
3
|
+
module EasyWeixin
|
4
|
+
class Auth
|
5
|
+
def initialize(app_token,timestamp,nonce,signature,echostr)
|
6
|
+
@app_token = app_token
|
7
|
+
@timestamp = timestamp
|
8
|
+
@nonce = nonce
|
9
|
+
@signature = signature
|
10
|
+
@echostr = echostr
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_valid
|
14
|
+
array = [@app_token, @timestamp, @nonce].sort
|
15
|
+
secret_str = Digest::SHA1.hexdigest(array.join)
|
16
|
+
|
17
|
+
if @signature == secret_str
|
18
|
+
return @echostr
|
19
|
+
else
|
20
|
+
return false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/easy_weixin/version.rb
CHANGED
data/lib/easy_weixin.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'multi_xml'
|
2
|
+
require 'ostruct'
|
1
3
|
require "easy_weixin/version"
|
2
4
|
require "easy_weixin/controller"
|
3
5
|
require "easy_weixin/model"
|
@@ -21,4 +23,9 @@ module EasyWeixin
|
|
21
23
|
msg.ArticleCount = articleCount
|
22
24
|
msg.to_xml
|
23
25
|
end
|
26
|
+
|
27
|
+
def analysis_xml(xml)
|
28
|
+
hash = MultiXml.parse(xml)['xml']
|
29
|
+
source = OpenStruct.new(hash)
|
30
|
+
end
|
24
31
|
end
|
data/spec/auth_spec.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'easy_weixin/auth'
|
4
|
+
describe "Weixin::Middleware" do
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@token = 'dave'
|
8
|
+
@timestamp = Time.now.to_i.to_s
|
9
|
+
@nonce = '123456'
|
10
|
+
@signature = Digest::SHA1.hexdigest( [@token, @timestamp, @nonce].sort.join )
|
11
|
+
@echostr = 'caishu'
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
it 'function check_valid' do
|
16
|
+
easy_weixin = EasyWeixin::Auth.new(@token, @timestamp, @nonce, @signature, @echostr)
|
17
|
+
easy_weixin.check_valid.should == @echostr
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/reply_spec.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'digest/sha1'
|
3
|
+
require 'easy_weixin/model'
|
4
|
+
require 'easy_weixin'
|
5
|
+
require File.expand_path('../test_xml',__FILE__)
|
6
|
+
|
7
|
+
describe "Weixin::Message" do
|
8
|
+
it 'is a text message' do
|
9
|
+
puts msg = EasyWeixin.analysis_xml($subscribe_xml)
|
10
|
+
|
11
|
+
case msg.MsgType
|
12
|
+
when 'text'
|
13
|
+
# TextMessage.new(hash)
|
14
|
+
puts EasyWeixin.text_msg(msg.ToUserName, msg.FromUserName, '我只是一个回复')
|
15
|
+
when 'image'
|
16
|
+
# ImageMessage.new(hash)
|
17
|
+
when 'location'
|
18
|
+
# LocationMessage.new(hash)
|
19
|
+
when 'link'
|
20
|
+
# LinkMessage.new(hash)
|
21
|
+
when 'event'
|
22
|
+
if msg.Event == "subscribe"
|
23
|
+
puts EasyWeixin.text_msg(msg.ToUserName, msg.FromUserName, 'Hi 欢迎来到顾益峰的个人微信频道,能来到这里的,都是我的朋友,都是一家人,这里你可以很放松!回复joke,听个笑话.回复girl,会显示我的五个女性朋友.回复boy,会显示我的五个男性朋友,回复其他内容,有你意想不到的内容喔~')
|
24
|
+
else
|
25
|
+
puts EasyWeixin.text_msg(msg.ToUserName, msg.FromUserName, '你确定?')
|
26
|
+
end
|
27
|
+
when 'voice'
|
28
|
+
# VoiceMessage.new(hash)
|
29
|
+
when 'video'
|
30
|
+
# VideoMessage.new(hash)
|
31
|
+
else
|
32
|
+
raise 'Unknown Message'
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'is a news' do
|
38
|
+
puts msg = EasyWeixin::Message.factory($text_xml)
|
39
|
+
|
40
|
+
if msg.Content == 'Hello2BizUser'
|
41
|
+
item1 = EasyWeixin::Item.new
|
42
|
+
item1.Title = 'title1'
|
43
|
+
item1.Description = 'blah'
|
44
|
+
item2 = EasyWeixin::Item.new
|
45
|
+
item2.Title = 'title2'
|
46
|
+
item2.Description = 'blah blah'
|
47
|
+
Articles = [item1, item2]
|
48
|
+
ArticleCount = Articles.size
|
49
|
+
end
|
50
|
+
|
51
|
+
puts EasyWeixin.news_msg(msg.ToUserName, msg.FromUserName, Articles, ArticleCount)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
data/spec/test_xml.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
$text_xml = '<xml>
|
2
|
+
<ToUserName><![CDATA[to]]></ToUserName>
|
3
|
+
<FromUserName><![CDATA[from]]></FromUserName>
|
4
|
+
<CreateTime>1360391199</CreateTime>
|
5
|
+
<MsgType><![CDATA[text]]></MsgType>
|
6
|
+
<Content><![CDATA[Hello2BizUser]]></Content>
|
7
|
+
<MsgId>5842835709471227904</MsgId>
|
8
|
+
</xml>'
|
9
|
+
|
10
|
+
$subscribe_xml = '<?xml version="1.0"?>
|
11
|
+
<xml><ToUserName><![CDATA[gh_bfecc3090141]]></ToUserName>
|
12
|
+
<FromUserName><![CDATA[oQzjkju94-eR2IKmlT60-vPANsV8]]></FromUserName>
|
13
|
+
<CreateTime>1404658003</CreateTime>
|
14
|
+
<MsgType><![CDATA[event]]></MsgType>
|
15
|
+
<Event><![CDATA[subscribe]]></Event>
|
16
|
+
<EventKey><![CDATA[]]></EventKey>
|
17
|
+
</xml>'
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_weixin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- menghuanwd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: roxml
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: multi_xml
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: easy to use weixin.
|
@@ -73,15 +73,20 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
- .gitignore
|
76
|
+
- ".gitignore"
|
77
77
|
- Gemfile
|
78
78
|
- LICENSE.txt
|
79
|
+
- README.html
|
79
80
|
- README.md
|
80
81
|
- Rakefile
|
81
82
|
- easy_weixin.gemspec
|
82
83
|
- lib/easy_weixin.rb
|
84
|
+
- lib/easy_weixin/auth.rb
|
83
85
|
- lib/easy_weixin/model.rb
|
84
86
|
- lib/easy_weixin/version.rb
|
87
|
+
- spec/auth_spec.rb
|
88
|
+
- spec/reply_spec.rb
|
89
|
+
- spec/test_xml.rb
|
85
90
|
homepage: https://github.com/menghuanwd/easy_weixin
|
86
91
|
licenses:
|
87
92
|
- MIT
|
@@ -92,18 +97,21 @@ require_paths:
|
|
92
97
|
- lib
|
93
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
94
99
|
requirements:
|
95
|
-
- -
|
100
|
+
- - ">="
|
96
101
|
- !ruby/object:Gem::Version
|
97
102
|
version: '0'
|
98
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
104
|
requirements:
|
100
|
-
- -
|
105
|
+
- - ">="
|
101
106
|
- !ruby/object:Gem::Version
|
102
107
|
version: '0'
|
103
108
|
requirements: []
|
104
109
|
rubyforge_project:
|
105
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.2.2
|
106
111
|
signing_key:
|
107
112
|
specification_version: 4
|
108
113
|
summary: easy to use weixin.
|
109
|
-
test_files:
|
114
|
+
test_files:
|
115
|
+
- spec/auth_spec.rb
|
116
|
+
- spec/reply_spec.rb
|
117
|
+
- spec/test_xml.rb
|