easy_wechat 0.1.2 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d8066f4397a6645cdae6c9bc9dc2ae40784fe181cfaaef40a6319ce5e78cac3
4
- data.tar.gz: 64b7c2dbe69defa80b0b1cbb762d0a2cb6c0cb1ba579b2ffb3f738d31c05e08d
3
+ metadata.gz: 48872ad0294d2609473c5b7481f600d9fa254ce2ecae297ff46199a3c70b96ef
4
+ data.tar.gz: 5aed6510ce796d43370a23e3be8fbcd051c0c23b4ba3c2d2d43af2c21442367a
5
5
  SHA512:
6
- metadata.gz: 695251db24a4baf01027b369165a8d6dbb18c054594f330c4ff8950c52b2330ac669a18c5ebf65068a13ee6a36c36f128508c990c399c990b5bf88032bd0b03c
7
- data.tar.gz: e2297653663ddf218abbbf69ce0c13a5a9c95b13a4fcb4829ccd20dd8d650814da287078bc70242183d12671ae0fa9d29f120b5f9f85ed36c654ad16adaaf7a8
6
+ metadata.gz: 84edf00b30e5af1c4dd9b697b98b9f40d84e26a33ba2b3941448e2576e9423d9670aaa1efe073e1e401a76c54b95a5f0ac3e9cd1662674d8db77498d73d1d8cc
7
+ data.tar.gz: 3813a75d9e4d8a5c4bf5847f68dce1ed701714831cad1a0b2408acfdd80d7ccd2fc894de101f0965ecf943a91b787336349afd1a00497aadfcb811060fe0bf20
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- easy_wechat (0.1.2)
4
+ easy_wechat (0.1.8)
5
5
  activesupport
6
6
  http-form_data
7
7
  httpx
data/README.md CHANGED
@@ -23,6 +23,8 @@ Or install it yourself as:
23
23
  ## Usage
24
24
 
25
25
  ```
26
+ rails g easy_wechat:install
27
+
26
28
  EasyWechat.configure do |config|
27
29
  config.appid = ENV.fetch("APPID") || ""
28
30
  config.app_secret = ENV.fetch("APP_SECRET") || ""
@@ -37,6 +39,11 @@ client.get_user_summary(begin_date, end_date)
37
39
  client.get_user_cumulate(begin_date, end_date)
38
40
  ```
39
41
 
42
+ ## FAQ
43
+ 1. 微信api,请求方式有问题,也会报错,所以要注意请求方式
44
+ 2. 先搞清楚你的appid对应的公众号是什么,并且搞清楚你是什么类型的,查看接口权限是否获得,否则有可能会有类似48001的权限未开通错误
45
+ 3. 调用api之前,请确保ip已经加入到服务器白名单
46
+
40
47
  ## Development
41
48
 
42
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -11,6 +11,7 @@ module EasyWechat
11
11
  ADD_NEWS_URL = "https://api.weixin.qq.com/cgi-bin/material/add_news"
12
12
  GET_USER_SUMMARY_URL = "https://api.weixin.qq.com/datacube/getusersummary"
13
13
  GET_USER_CUMULATE_URL = "https://api.weixin.qq.com/datacube/getusercumulate"
14
+ GET_TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
14
15
 
15
16
  def initialize
16
17
  end
@@ -53,47 +54,54 @@ module EasyWechat
53
54
  r
54
55
  end
55
56
 
57
+ # 新增永久图文素材
58
+ # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
59
+ def add_news(articles)
60
+ payload = { articles: articles }
61
+
62
+ resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
63
+
64
+ r = ::JSON.parse(resp.body, quirks_mode: true)
65
+ yield r if block_given?
66
+ r
67
+ end
68
+
69
+ def get_ticket(type)
70
+ resp = HTTPX.get(GET_TICKET_URL, params: { access_token: access_token, type: type })
71
+
72
+ r = ::JSON.parse(resp.body, quirks_mode: true)
73
+ yield r if block_given?
74
+ r
75
+ end
76
+
77
+ # 获取永久素材的列表
78
+ # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
79
+ def batchget_material(type = "image", offset = 0, count = 20)
80
+ # TODO: 检查参数完整性
81
+ # TODO: 检查参数合法性
82
+ payload = { type: type, offset: offset, count: count }
83
+
84
+ resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
85
+
86
+ r = ::JSON.parse(resp.body, quirks_mode: true)
87
+ yield r if block_given?
88
+ r
89
+ end
90
+
56
91
  # 上传图文消息内的图片获取URL
57
92
  # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
58
93
  def uploadimg(media)
59
94
  # https://honeyryderchuck.gitlab.io/httpx/wiki/Multipart-Uploads.html#notes
60
- file = if media.is_a?(String) ? HTTP::FormData::File.new(media) : meida
61
- resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
62
-
63
- r = ::JSON.parse(resp.body, quirks_mode: true)
64
- yield r if block_given?
65
- r
66
- end
67
-
68
- # 获取永久素材的列表
69
- # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_materials_list.html
70
- def batchget_material(type = "image", offset = 0, count = 20)
71
- # TODO: 检查参数完整性
72
- # TODO: 检查参数合法性
73
- payload = { type: type, offset: offset, count: count }
74
-
75
- resp = HTTPX.post(BATCHGET_MATERIAL_URL, params: { access_token: access_token }, json: payload)
76
-
77
- r = ::JSON.parse(resp.body, quirks_mode: true)
78
- yield r if block_given?
79
- r
80
- end
81
-
82
- # 新增永久图文素材
83
- # https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html
84
- def add_news(articles)
85
- payload = { articles: articles }
86
-
87
- resp = HTTPX.post(ADD_NEWS_URL, params: { access_token: access_token }, json: payload)
88
-
89
- r = ::JSON.parse(resp.body, quirks_mode: true)
90
- yield r if block_given?
91
- r
92
- end
93
-
94
- def menu_create
95
- raise NotImplementedError
96
- end
95
+ file = media.is_a?(String) ? HTTP::FormData::File.new(media) : media
96
+ resp = HTTPX.plugin(:multipart).post(UPLOADIMG_URL, params: { access_token: access_token }, form: { media: file })
97
+
98
+ r = ::JSON.parse(resp.body, quirks_mode: true)
99
+ yield r if block_given?
100
+ r
101
+ end
102
+
103
+ def menu_create
104
+ raise NotImplementedError
97
105
  end
98
106
  end
99
107
  end
@@ -1,3 +1,3 @@
1
1
  module EasyWechat
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -0,0 +1,20 @@
1
+ module EasyWechat
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "EasyWechat installation: initializer"
5
+ source_root File.expand_path("../../templates", __FILE__)
6
+
7
+ def install
8
+ puts "==> generate initializer file ..."
9
+ copy_initializer
10
+ puts "Done!"
11
+ end
12
+
13
+ private
14
+
15
+ def copy_initializer
16
+ template "initializer.rb", "config/initializers/easy_wechat.rb"
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,4 @@
1
+ EasyWechat.configure do |config|
2
+ # config.appid = ENV.fetch("APPID") || ""
3
+ # config.app_secret = ENV.fetch("APP_SECRET") || ""
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: easy_wechat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - 42up
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-09 00:00:00.000000000 Z
11
+ date: 2021-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpx
@@ -130,6 +130,8 @@ files:
130
130
  - lib/easy_wechat/client.rb
131
131
  - lib/easy_wechat/configuration.rb
132
132
  - lib/easy_wechat/version.rb
133
+ - lib/generators/easy_wechat/install_generator.rb
134
+ - lib/generators/templates/initializer.rb
133
135
  homepage: https://github.com/42up/easy_wechat
134
136
  licenses:
135
137
  - MIT