wx_ext 0.2.0 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8434606cb698fb7489cda2f0b39e56e8615a272a
4
- data.tar.gz: c6ed9bf66acb4333f904942c7e81dee03d76f041
3
+ metadata.gz: cbd36c9af9e81974bf676416525cd2fefcf36768
4
+ data.tar.gz: db1866071d6956595ac1af08f0491251963eb24b
5
5
  SHA512:
6
- metadata.gz: 9f937a2306a7cc16ab6b4432afaec0814866817ffe95c95cc9e05f68fbc8010fab8685cabf201c4cdc8cfc6ace15c0b4a22faa8560d7ac81688bce4e7a6bee3d
7
- data.tar.gz: 520dad2ed787bd420470fd8671a04078c85079f38f671638a924580e91465755ae5a7c669d8d58504ddd2ace2338d67538c38bf1d70b8ddc30d4be664f90addb
6
+ metadata.gz: 2bb4994398f50a74a9e7fb9175a36e80a50943edb20fed3b07f03f4eec391efe0cdfd62444397f974f54eee55228850c46457bcc2d29745776e9706929964cba
7
+ data.tar.gz: 58876dd96a9d09896e3901597e95541580e2366f5ce9576bdacd756d9664b263a62ed2b83d1fd8f845e4e2c11519a7c246f50bf57a65ed12a141ed3f5e677316
data/.gitignore CHANGED
@@ -13,3 +13,5 @@
13
13
  *.a
14
14
  mkmf.log
15
15
  *.gem
16
+
17
+ /.idea/
data/README.md CHANGED
@@ -7,7 +7,7 @@ Weixin extention, sougou weixin post spider and weixin api gem
7
7
  Add this line to your application's Gemfile:
8
8
 
9
9
  ```ruby
10
- gem 'wx_ext', '~> 0.2.0'
10
+ gem 'wx_ext', '~> 0.2.2'
11
11
  ```
12
12
 
13
13
  And then execute:
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module WxExt
3
- VERSION = '0.2.0'
3
+ VERSION = '0.2.2'
4
4
  end
@@ -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
@@ -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 = @cookies.merge msg_send_page.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
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+ require 'spec_helper'
3
+
4
+ describe WxExt::WechatPay do
5
+ before(:all) do
6
+ end
7
+
8
+ it 'should login to the mp' do
9
+ res_hash = @weixin.login
10
+ puts res_hash
11
+ expect(res_hash[:status]).to eql(0)
12
+ end
13
+ end
@@ -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 'username', 'pass'
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
- =begin
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.0
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-01-22 00:00:00.000000000 Z
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.5
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: