Module: WeixinAuthorize
- Defined in:
- lib/weixin_authorize.rb,
lib/weixin_authorize/client.rb,
lib/weixin_authorize/config.rb,
lib/weixin_authorize/version.rb,
lib/weixin_authorize/api/mass.rb,
lib/weixin_authorize/api/menu.rb,
lib/weixin_authorize/api/user.rb,
lib/weixin_authorize/api/media.rb,
lib/weixin_authorize/api/oauth.rb,
lib/weixin_authorize/api/custom.rb,
lib/weixin_authorize/api/groups.rb,
lib/weixin_authorize/api/qrcode.rb,
lib/weixin_authorize/token/store.rb,
lib/weixin_authorize/api/template.rb,
lib/weixin_authorize/api/data_cube.rb,
lib/weixin_authorize/js_ticket/store.rb,
lib/weixin_authorize/token/redis_store.rb,
lib/weixin_authorize/handler/exceptions.rb,
lib/weixin_authorize/token/object_store.rb,
lib/weixin_authorize/handler/global_code.rb,
lib/weixin_authorize/js_ticket/redis_store.rb,
lib/weixin_authorize/handler/result_handler.rb,
lib/weixin_authorize/js_ticket/object_store.rb,
lib/weixin_authorize/carrierwave/weixin_uploader.rb
Defined Under Namespace
Modules: Api, JsTicket, Token Classes: Client, Config, ResultHandler, ValidAccessTokenException, WeixinUploader
Constant Summary collapse
- OK_MSG =
"ok"
- OK_CODE =
0
- GRANT_TYPE =
"client_credential"
- VERSION =
"1.6.2"
- GLOBAL_CODES =
{ -1 => "系统繁忙", 0 => "请求成功", 40001 => "获取access_token时AppSecret错误,或者access_token无效", 40002 => "不合法的凭证类型", 40003 => "不合法的OpenID", 40004 => "不合法的媒体文件类型", 40005 => "不合法的文件类型", 40006 => "不合法的文件大小", 40007 => "不合法的媒体文件id", 40008 => "不合法的消息类型", 40009 => "不合法的图片文件大小", 40010 => "不合法的语音文件大小", 40011 => "不合法的视频文件大小", 40012 => "不合法的缩略图文件大小", 40013 => "不合法的APPID", 40014 => "不合法的access_token", 40015 => "不合法的菜单类型", 40016 => "不合法的按钮个数", 40017 => "不合法的按钮个数", 40018 => "不合法的按钮名字长度", 40019 => "不合法的按钮KEY长度", 40020 => "不合法的按钮URL长度", 40021 => "不合法的菜单版本号", 40022 => "不合法的子菜单级数", 40023 => "不合法的子菜单按钮个数", 40024 => "不合法的子菜单按钮类型", 40025 => "不合法的子菜单按钮名字长度", 40026 => "不合法的子菜单按钮KEY长度", 40027 => "不合法的子菜单按钮URL长度", 40028 => "不合法的自定义菜单使用用户", 40029 => "不合法的oauth_code", 40030 => "不合法的refresh_token", 40031 => "不合法的openid列表", 40032 => "不合法的openid列表长度", 40033 => "不合法的请求字符,不能包含xxxx格式的字符", 40035 => "不合法的参数", 40038 => "不合法的请求格式", 40039 => "不合法的URL长度", 40050 => "不合法的分组id", 40051 => "分组名字不合法", 41001 => "缺少access_token参数", 41002 => "缺少appid参数", 41003 => "缺少refresh_token参数", 41004 => "缺少secret参数", 41005 => "缺少多媒体文件数据", 41006 => "缺少media_id参数", 41007 => "缺少子菜单数据", 41008 => "缺少oauth code", 41009 => "缺少openid", 42001 => "access_token超时", 42002 => "refresh_token超时", 42003 => "oauth_code超时", 43001 => "需要GET请求", 43002 => "需要POST请求", 43003 => "需要HTTPS请求", 43004 => "需要接收者关注", 43005 => "需要好友关系", 44001 => "多媒体文件为空", 44002 => "POST的数据包为空", 44003 => "图文消息内容为空", 44004 => "文本消息内容为空", 45001 => "多媒体文件大小超过限制", 45002 => "消息内容超过限制", 45003 => "标题字段超过限制", 45004 => "描述字段超过限制", 45005 => "链接字段超过限制", 45006 => "图片链接字段超过限制", 45007 => "语音播放时间超过限制", 45008 => "图文消息超过限制", 45009 => "接口调用超过限制", 45010 => "创建菜单个数超过限制", 45015 => "回复时间超过限制", 45016 => "系统分组,不允许修改", 45017 => "分组名字过长", 45018 => "分组数量超过上限", 46001 => "不存在媒体数据", 46002 => "不存在的菜单版本", 46003 => "不存在的菜单数据", 46004 => "不存在的用户", 47001 => "解析JSON/XML内容错误", 48001 => "api功能未授权", 50001 => "用户未授权该api" }
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
- .api_endpoint ⇒ Object
- .configure {|self.config ||= Config.new| ... } ⇒ Object
- .endpoint_url(endpoint, url) ⇒ Object
- .file_endpoint ⇒ Object
- .http_get_without_token(url, headers = {}, endpoint = "plain") ⇒ Object
- .http_post_without_token(url, payload = {}, headers = {}, endpoint = "plain") ⇒ Object
-
.load_json(string) ⇒ Object
return hash.
- .mp_endpoint(url) ⇒ Object
- .open_endpoint(url) ⇒ Object
- .plain_endpoint ⇒ Object
- .resource(url) ⇒ Object
-
.rest_client_options ⇒ Object
可选配置: RestClient timeout, etc.
- .weixin_redis ⇒ Object
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
5 6 7 |
# File 'lib/weixin_authorize/config.rb', line 5 def config @config end |
Class Method Details
.api_endpoint ⇒ Object
63 64 65 |
# File 'lib/weixin_authorize.rb', line 63 def api_endpoint "https://api.weixin.qq.com" end |
.configure {|self.config ||= Config.new| ... } ⇒ Object
7 8 9 |
# File 'lib/weixin_authorize/config.rb', line 7 def configure yield self.config ||= Config.new end |
.endpoint_url(endpoint, url) ⇒ Object
55 56 57 |
# File 'lib/weixin_authorize.rb', line 55 def endpoint_url(endpoint, url) send("#{endpoint}_endpoint") + url end |
.file_endpoint ⇒ Object
67 68 69 |
# File 'lib/weixin_authorize.rb', line 67 def file_endpoint "http://file.api.weixin.qq.com/cgi-bin" end |
.http_get_without_token(url, headers = {}, endpoint = "plain") ⇒ Object
32 33 34 35 |
# File 'lib/weixin_authorize.rb', line 32 def http_get_without_token(url, headers={}, endpoint="plain") get_api_url = endpoint_url(endpoint, url) load_json(resource(get_api_url).get(params: headers)) end |
.http_post_without_token(url, payload = {}, headers = {}, endpoint = "plain") ⇒ Object
37 38 39 40 41 |
# File 'lib/weixin_authorize.rb', line 37 def http_post_without_token(url, payload={}, headers={}, endpoint="plain") post_api_url = endpoint_url(endpoint, url) payload = JSON.dump(payload) if endpoint == "plain" # to json if invoke "plain" load_json(resource(post_api_url).post(payload, params: headers)) end |
.load_json(string) ⇒ Object
return hash
48 49 50 51 52 53 |
# File 'lib/weixin_authorize.rb', line 48 def load_json(string) result_hash = JSON.parse(string) code = result_hash.delete("errcode") en_msg = result_hash.delete("errmsg") ResultHandler.new(code, en_msg, result_hash) end |
.mp_endpoint(url) ⇒ Object
71 72 73 |
# File 'lib/weixin_authorize.rb', line 71 def mp_endpoint(url) "https://mp.weixin.qq.com/cgi-bin#{url}" end |
.open_endpoint(url) ⇒ Object
75 76 77 |
# File 'lib/weixin_authorize.rb', line 75 def open_endpoint(url) "https://open.weixin.qq.com#{url}" end |
.plain_endpoint ⇒ Object
59 60 61 |
# File 'lib/weixin_authorize.rb', line 59 def plain_endpoint "#{api_endpoint}/cgi-bin" end |
.resource(url) ⇒ Object
43 44 45 |
# File 'lib/weixin_authorize.rb', line 43 def resource(url) RestClient::Resource.new(url, ) end |
.rest_client_options ⇒ Object
可选配置: RestClient timeout, etc. key 必须是符号
18 19 20 21 22 23 |
# File 'lib/weixin_authorize/config.rb', line 18 def if config.nil? return {timeout: 5, open_timeout: 5, verify_ssl: true} end config. end |
.weixin_redis ⇒ Object
11 12 13 14 |
# File 'lib/weixin_authorize/config.rb', line 11 def weixin_redis return nil if config.nil? @redis ||= config.redis end |