wechat-core 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 909f6fdb0dd2d9e9bf2ca933bd4416df32d467eb
4
+ data.tar.gz: 71e13a45b2a2a4bd0880411c568e80d34a63d7a4
5
+ SHA512:
6
+ metadata.gz: 5982714b3356256db2fba6ee4a7c643474343ddc4fcf37d4de7b0ae65609c1d70c71a1f4d250e8ef77dfe6ee820d6c48e0e6ad9e1aa93dac47dfc74db78bb526
7
+ data.tar.gz: fe58f5ba626aaf1a89e20fb11846a18ebc20d8dd372552df2d6753148ced1f0186952e5dbdbbd2fe6744424421e0a82a96240e8451ad4466bafb53c2f567f0cc
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/CHANGELOG.md ADDED
@@ -0,0 +1 @@
1
+ # Wechat Core Change Log 微信核心库变更日志
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at topbit.du@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wechat-core.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Topbit Du
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Wechat::Core 微信核心库
2
+
3
+ The Wechat Core Library is a code base to call the Wechat Core APIs.
4
+ 微信核心库用于调用微信核心API。
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'wechat-core'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install wechat-core
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ response = ::Wechat::Core::AccessToken.load Rails.application.secrets.wechat_app_id, Rails.application.secrets.wechat_app_secret
26
+ if response.present?
27
+ access_token = response['access_token']
28
+ expires_in = response['expires_in']
29
+ end
30
+ ```
31
+
32
+ ## Development
33
+
34
+ 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.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/topbitdu/wechat-core. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
41
+
42
+
43
+ ## License
44
+
45
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
46
+
data/ROADMAP.md ADDED
@@ -0,0 +1,20 @@
1
+ # Wechat Core Road Map 微信核心库线路图
2
+
3
+ ## v0.1
4
+
5
+ - Common module
6
+ - Access Token wrapper class
7
+
8
+ ## v0.2
9
+
10
+ - Server Address wrapper class
11
+ - Tiny Link wrapper class
12
+
13
+ ## v0.3
14
+
15
+ - Follower wrapper class
16
+ - Follower Profile wrapper class
17
+
18
+ # v0.4
19
+
20
+ - Logo wrapper class
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wechat/core"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ require 'jsonclient'
2
+
3
+ class Wechat::Core::AccessToken
4
+
5
+ # 获取 Access Token
6
+ # http://mp.weixin.qq.com/wiki/11/0e4b294685f817b95cbed85ba5e82b8f.html
7
+ #
8
+ # Return hash format if success:
9
+ # {
10
+ # access_token: <ACCESS_TOKEN>,
11
+ # expires_in: 7200
12
+ # }
13
+ # The ACCESS_TOKEN is 107 characters in 2015.
14
+ def self.load(app_id, app_secret)
15
+ message = ::JSONClient.new.get 'https://api.weixin.qq.com/cgi-bin/token',
16
+ {
17
+ grant_type: 'client_credential',
18
+ appid: app_id, # Rails.application.secrets.wechat_app_id,
19
+ secret: app_secret, # Rails.application.secrets.wechat_app_secret
20
+ }
21
+ message.body
22
+ end
23
+
24
+ end
@@ -0,0 +1,139 @@
1
+ module Wechat::Core::Common
2
+
3
+ # http://mp.weixin.qq.com/wiki/17/fa4e1434e57290788bde25603fa2fcbd.html
4
+ # $('table#ec-t').find('tr').each(function(index, line)
5
+ # {
6
+ # console.log($(line).find('td:first').text().trim()+" => '"+$(line).find('td:last').text().trim()+"',");
7
+ # });
8
+ ERROR_CODES =
9
+ {
10
+ -1 => '系统繁忙,此时请开发者稍候再试',
11
+ 0 => '请求成功',
12
+ 40001 => '获取access_token时AppSecret错误,或者access_token无效。请开发者认真比对AppSecret的正确性,或查看是否正在为恰当的公众号调用接口',
13
+ 40002 => '不合法的凭证类型',
14
+ 40003 => '不合法的OpenID,请开发者确认OpenID(该用户)是否已关注公众号,或是否是其他公众号的OpenID',
15
+ 40004 => '不合法的媒体文件类型',
16
+ 40005 => '不合法的文件类型',
17
+ 40006 => '不合法的文件大小',
18
+ 40007 => '不合法的媒体文件id',
19
+ 40008 => '不合法的消息类型',
20
+ 40009 => '不合法的图片文件大小',
21
+ 40010 => '不合法的语音文件大小',
22
+ 40011 => '不合法的视频文件大小',
23
+ 40012 => '不合法的缩略图文件大小',
24
+ 40013 => '不合法的AppID,请开发者检查AppID的正确性,避免异常字符,注意大小写',
25
+ 40014 => '不合法的access_token,请开发者认真比对access_token的有效性(如是否过期),或查看是否正在为恰当的公众号调用接口',
26
+ 40015 => '不合法的菜单类型',
27
+ 40016 => '不合法的按钮个数',
28
+ 40017 => '不合法的按钮个数',
29
+ 40018 => '不合法的按钮名字长度',
30
+ 40019 => '不合法的按钮KEY长度',
31
+ 40020 => '不合法的按钮URL长度',
32
+ 40021 => '不合法的菜单版本号',
33
+ 40022 => '不合法的子菜单级数',
34
+ 40023 => '不合法的子菜单按钮个数',
35
+ 40024 => '不合法的子菜单按钮类型',
36
+ 40025 => '不合法的子菜单按钮名字长度',
37
+ 40026 => '不合法的子菜单按钮KEY长度',
38
+ 40027 => '不合法的子菜单按钮URL长度',
39
+ 40028 => '不合法的自定义菜单使用用户',
40
+ 40029 => '不合法的oauth_code',
41
+ 40030 => '不合法的refresh_token',
42
+ 40031 => '不合法的openid列表',
43
+ 40032 => '不合法的openid列表长度',
44
+ 40033 => '不合法的请求字符,不能包含\uxxxx格式的字符',
45
+ 40035 => '不合法的参数',
46
+ 40038 => '不合法的请求格式',
47
+ 40039 => '不合法的URL长度',
48
+ 40050 => '不合法的分组id',
49
+ 40051 => '分组名字不合法',
50
+ 40117 => '分组名字不合法',
51
+ 40118 => 'media_id大小不合法',
52
+ 40119 => 'button类型错误',
53
+ 40120 => 'button类型错误',
54
+ 40121 => '不合法的media_id类型',
55
+ 40132 => '微信号不合法',
56
+ 40137 => '不支持的图片格式',
57
+ 41001 => '缺少access_token参数',
58
+ 41002 => '缺少appid参数',
59
+ 41003 => '缺少refresh_token参数',
60
+ 41004 => '缺少secret参数',
61
+ 41005 => '缺少多媒体文件数据',
62
+ 41006 => '缺少media_id参数',
63
+ 41007 => '缺少子菜单数据',
64
+ 41008 => '缺少oauth code',
65
+ 41009 => '缺少openid',
66
+ 42001 => 'access_token超时,请检查access_token的有效期,请参考基础支持-获取access_token中,对access_token的详细机制说明',
67
+ 42002 => 'refresh_token超时',
68
+ 42003 => 'oauth_code超时',
69
+ 43001 => '需要GET请求',
70
+ 43002 => '需要POST请求',
71
+ 43003 => '需要HTTPS请求',
72
+ 43004 => '需要接收者关注',
73
+ 43005 => '需要好友关系',
74
+ 44001 => '多媒体文件为空',
75
+ 44002 => 'POST的数据包为空',
76
+ 44003 => '图文消息内容为空',
77
+ 44004 => '文本消息内容为空',
78
+ 45001 => '多媒体文件大小超过限制',
79
+ 45002 => '消息内容超过限制',
80
+ 45003 => '标题字段超过限制',
81
+ 45004 => '描述字段超过限制',
82
+ 45005 => '链接字段超过限制',
83
+ 45006 => '图片链接字段超过限制',
84
+ 45007 => '语音播放时间超过限制',
85
+ 45008 => '图文消息超过限制',
86
+ 45009 => '接口调用超过限制',
87
+ 45010 => '创建菜单个数超过限制',
88
+ 45015 => '回复时间超过限制',
89
+ 45016 => '系统分组,不允许修改',
90
+ 45017 => '分组名字过长',
91
+ 45018 => '分组数量超过上限',
92
+ 46001 => '不存在媒体数据',
93
+ 46002 => '不存在的菜单版本',
94
+ 46003 => '不存在的菜单数据',
95
+ 46004 => '不存在的用户',
96
+ 47001 => '解析JSON/XML内容错误',
97
+ 48001 => 'api功能未授权,请确认公众号已获得该接口,可以在公众平台官网-开发者中心页中查看接口权限',
98
+ 50001 => '用户未授权该api',
99
+ 50002 => '用户受限,可能是违规后接口被封禁',
100
+ 61451 => '参数错误(invalid parameter)',
101
+ 61452 => '无效客服账号(invalid kf_account)',
102
+ 61453 => '客服帐号已存在(kf_account exsited)',
103
+ 61454 => '客服帐号名长度超过限制(仅允许10个英文字符,不包括@及@后的公众号的微信号)(invalid kf_acount length)',
104
+ 61455 => '客服帐号名包含非法字符(仅允许英文+数字)(illegal character in kf_account)',
105
+ 61456 => '客服帐号个数超过限制(10个客服账号)(kf_account count exceeded)',
106
+ 61457 => '无效头像文件类型(invalid file type)',
107
+ 61450 => '系统错误(system error)',
108
+ 61500 => '日期格式错误',
109
+ 61501 => '日期范围错误',
110
+ 9001001 => 'POST数据参数不合法',
111
+ 9001002 => '远端服务不可用',
112
+ 9001003 => 'Ticket不合法',
113
+ 9001004 => '获取摇周边用户信息失败',
114
+ 9001005 => '获取商户信息失败',
115
+ 9001006 => '获取OpenID失败',
116
+ 9001007 => '上传文件缺失',
117
+ 9001008 => '上传素材的文件类型不合法',
118
+ 9001009 => '上传素材的文件尺寸不合法',
119
+ 9001010 => '上传失败',
120
+ 9001020 => '帐号不合法',
121
+ 9001021 => '已有设备激活率低于50%,不能新增设备',
122
+ 9001022 => '设备申请数不合法,必须为大于0的数字',
123
+ 9001023 => '已存在审核中的设备ID申请',
124
+ 9001024 => '一次查询设备ID数量不能超过50',
125
+ 9001025 => '设备ID不合法',
126
+ 9001026 => '页面ID不合法',
127
+ 9001027 => '页面参数不合法',
128
+ 9001028 => '一次删除页面ID数量不能超过10',
129
+ 9001029 => '页面已应用在设备中,请先解除应用关系再删除',
130
+ 9001030 => '一次查询页面ID数量不能超过50',
131
+ 9001031 => '时间区间不合法',
132
+ 9001032 => '保存设备与页面的绑定关系参数错误',
133
+ 9001033 => '门店ID不合法',
134
+ 9001034 => '设备备注信息过长',
135
+ 9001035 => '设备申请参数不合法',
136
+ 9001036 => '查询起始值begin不合法'
137
+ }
138
+
139
+ end
@@ -0,0 +1,5 @@
1
+ module Wechat
2
+ module Core
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'wechat/core/version'
2
+
3
+ module Wechat
4
+ module Core
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wechat/core/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = 'wechat-core'
9
+ spec.version = Wechat::Core::VERSION
10
+ spec.authors = [ 'Topbit Du' ]
11
+ spec.email = [ 'topbit.du@gmail.com' ]
12
+
13
+ spec.summary = %q{Wechat Core Library}
14
+ spec.description = %q{The Wechat Core Library is a code base to handle the core Wechat API calls.}
15
+ spec.homepage = 'https://github.com/topbitdu/wechat-core'
16
+ spec.license = 'MIT'
17
+
18
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
19
+ # delete this section to allow pushing this gem to any host.
20
+ #if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ #else
23
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
24
+ #end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ spec.bindir = 'exe'
28
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
+ spec.require_paths = [ 'lib' ]
30
+
31
+ spec.add_development_dependency 'bundler', '~> 1.11'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec', '~> 3.0'
34
+
35
+ spec.add_dependency 'httpclient', '~> 2.7'
36
+
37
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wechat-core
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httpclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ description: The Wechat Core Library is a code base to handle the core Wechat API
70
+ calls.
71
+ email:
72
+ - topbit.du@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - ROADMAP.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/setup
89
+ - lib/wechat/core.rb
90
+ - lib/wechat/core/access_token.rb
91
+ - lib/wechat/core/common.rb
92
+ - lib/wechat/core/version.rb
93
+ - wechat-core.gemspec
94
+ homepage: https://github.com/topbitdu/wechat-core
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.4.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Wechat Core Library
118
+ test_files: []