wx_ext 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +1 -1
- data/lib/wx_ext/version.rb +1 -1
- data/lib/wx_ext/wechat_pay.rb +18 -0
- data/lib/wx_ext/wei_xin.rb +49 -1
- data/spec/wx_ext/wechat_pay_spec.rb +13 -0
- data/spec/wx_ext/weixin_spec.rb +17 -4
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbd36c9af9e81974bf676416525cd2fefcf36768
|
4
|
+
data.tar.gz: db1866071d6956595ac1af08f0491251963eb24b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bb4994398f50a74a9e7fb9175a36e80a50943edb20fed3b07f03f4eec391efe0cdfd62444397f974f54eee55228850c46457bcc2d29745776e9706929964cba
|
7
|
+
data.tar.gz: 58876dd96a9d09896e3901597e95541580e2366f5ce9576bdacd756d9664b263a62ed2b83d1fd8f845e4e2c11519a7c246f50bf57a65ed12a141ed3f5e677316
|
data/README.md
CHANGED
data/lib/wx_ext/version.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
require 'rest_client'
|
5
|
+
require 'json'
|
6
|
+
require 'open-uri'
|
7
|
+
|
8
|
+
module WxExt
|
9
|
+
|
10
|
+
BASE_PAY_URL = 'https://api.mch.weixin.qq.com/'
|
11
|
+
|
12
|
+
# Spider post from http://weixin.sogou.com
|
13
|
+
#
|
14
|
+
# @author FuShengYang
|
15
|
+
class WechatPay
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/wx_ext/wei_xin.rb
CHANGED
@@ -4,6 +4,7 @@ require 'digest'
|
|
4
4
|
require 'rest_client'
|
5
5
|
require 'json'
|
6
6
|
require 'nokogiri'
|
7
|
+
require 'uri'
|
7
8
|
|
8
9
|
module WxExt
|
9
10
|
# weixin extention of mp.weixin.qq.com
|
@@ -85,10 +86,39 @@ module WxExt
|
|
85
86
|
#
|
86
87
|
# @return [Boolean] Init ticket, cookies, operation_seq, user_name true or false.
|
87
88
|
def init
|
89
|
+
home_url = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&lang=zh_CN&token=#{@token}"
|
90
|
+
headers = {
|
91
|
+
host: 'mp.weixin.qq.com',
|
92
|
+
referer: 'https://mp.weixin.qq.com/'
|
93
|
+
}
|
94
|
+
|
95
|
+
@cookies = {
|
96
|
+
data_bizuin: URI.unescape(cookies['data_bizuin']),
|
97
|
+
data_ticket: URI.unescape(cookies['data_ticket']),
|
98
|
+
slave_user: URI.unescape(cookies['slave_user']),
|
99
|
+
slave_sid: URI.unescape(cookies['slave_sid']),
|
100
|
+
bizuin: URI.unescape(cookies['bizuin'])
|
101
|
+
}
|
102
|
+
|
103
|
+
cookie_page = RestClient.get home_url, cookies: @cookies, headers: headers
|
104
|
+
@cookies = cookie_page.cookies
|
105
|
+
|
106
|
+
@cookies = {
|
107
|
+
slave_user: URI.unescape(cookies['slave_user']),
|
108
|
+
slave_sid: URI.unescape(cookies['slave_sid']),
|
109
|
+
bizuin: URI.unescape(cookies['bizuin'])
|
110
|
+
}
|
111
|
+
|
88
112
|
msg_send_url = 'https://mp.weixin.qq.com/cgi-bin/masssendpage'\
|
89
113
|
"?t=mass/send&token=#{@token}&lang=zh_CN"
|
90
114
|
msg_send_page = RestClient.get msg_send_url, cookies: @cookies
|
91
|
-
@cookies =
|
115
|
+
@cookies = msg_send_page.cookies
|
116
|
+
|
117
|
+
@cookies = {
|
118
|
+
slave_user: URI.unescape(cookies['slave_user']),
|
119
|
+
slave_sid: URI.unescape(cookies['slave_sid']),
|
120
|
+
bizuin: URI.unescape(cookies['bizuin'])
|
121
|
+
}
|
92
122
|
|
93
123
|
ticket_reg = /.*ticket\s*:\s*\"(\w+)\".*user_name\s*:\s*\"(.*)\",.*nick_name\s*:\s*\"(.*)\".*/m
|
94
124
|
operation_seq_reg = /.*operation_seq\s*:\s*\"(\d+)\".*/
|
@@ -429,5 +459,23 @@ module WxExt
|
|
429
459
|
res = resource[uri].post params
|
430
460
|
JSON.parse res.to_s
|
431
461
|
end
|
462
|
+
|
463
|
+
private
|
464
|
+
|
465
|
+
def decode_cookies(cookies)
|
466
|
+
need_decode = [
|
467
|
+
'data_bizuin',
|
468
|
+
'data_ticket',
|
469
|
+
'slave_user',
|
470
|
+
'slave_sid',
|
471
|
+
'bizuin'
|
472
|
+
]
|
473
|
+
cookies.each do |key, val|
|
474
|
+
if need_decode.include?(key)
|
475
|
+
cookies[key] = URI.unescape(cookies[val])
|
476
|
+
end
|
477
|
+
end
|
478
|
+
cookies
|
479
|
+
end
|
432
480
|
end
|
433
481
|
end
|
data/spec/wx_ext/weixin_spec.rb
CHANGED
@@ -3,22 +3,35 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe WxExt::WeiXin do
|
5
5
|
before(:all) do
|
6
|
-
@weixin = WxExt::WeiXin.new '
|
6
|
+
@weixin = WxExt::WeiXin.new 'flowerwrong@hotmail.com', '1*flower@wrong*1'
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
9
|
it 'should login to the mp' do
|
11
10
|
res_hash = @weixin.login
|
12
11
|
expect(res_hash[:status]).to eql(0)
|
13
12
|
end
|
14
|
-
|
13
|
+
|
15
14
|
it 'should init method should init all params' do
|
16
15
|
res_hash = @weixin.login
|
17
16
|
flag = @weixin.init
|
18
17
|
if flag
|
19
18
|
token = @weixin.token
|
20
|
-
puts "token = #{token}"
|
21
19
|
expect(token).to match(/\d+/)
|
20
|
+
else
|
21
|
+
expect(flag).to eql(true)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
=begin
|
26
|
+
it 'should search msg with keyword' do
|
27
|
+
res_hash = @weixin.login
|
28
|
+
flag = @weixin.init
|
29
|
+
puts flag
|
30
|
+
if flag
|
31
|
+
require 'uri'
|
32
|
+
ha = @weixin.get_msg_items(20, 7, 1, 'search', URI.encode('呢'), '', '')
|
33
|
+
puts '-' * 20
|
34
|
+
puts ha
|
22
35
|
end
|
23
36
|
end
|
24
37
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wx_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- flowerwrong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/wx_ext/helper.rb
|
123
123
|
- lib/wx_ext/sougou_weixin.rb
|
124
124
|
- lib/wx_ext/version.rb
|
125
|
+
- lib/wx_ext/wechat_pay.rb
|
125
126
|
- lib/wx_ext/wei_xin.rb
|
126
127
|
- spec/spec_helper.rb
|
127
128
|
- spec/test.png
|
@@ -136,6 +137,7 @@ files:
|
|
136
137
|
- spec/wx_ext/api/user/group_spec.rb
|
137
138
|
- spec/wx_ext/api/user_spec.rb
|
138
139
|
- spec/wx_ext/sougou_weixin_spec.rb
|
140
|
+
- spec/wx_ext/wechat_pay_spec.rb
|
139
141
|
- spec/wx_ext/weixin_spec.rb
|
140
142
|
- wx_ext.gemspec
|
141
143
|
homepage: http://thecampus.cc
|
@@ -158,7 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
160
|
version: '0'
|
159
161
|
requirements: []
|
160
162
|
rubyforge_project:
|
161
|
-
rubygems_version: 2.4.
|
163
|
+
rubygems_version: 2.4.3
|
162
164
|
signing_key:
|
163
165
|
specification_version: 4
|
164
166
|
summary: A gem to hack mp.weixin.qq.com and weixin base api.
|
@@ -176,5 +178,6 @@ test_files:
|
|
176
178
|
- spec/wx_ext/api/user/group_spec.rb
|
177
179
|
- spec/wx_ext/api/user_spec.rb
|
178
180
|
- spec/wx_ext/sougou_weixin_spec.rb
|
181
|
+
- spec/wx_ext/wechat_pay_spec.rb
|
179
182
|
- spec/wx_ext/weixin_spec.rb
|
180
183
|
has_rdoc:
|