Module: WxExt::Api::User
- Extended by:
- User
- Included in:
- User
- Defined in:
- lib/wx_ext/api/user.rb,
lib/wx_ext/api/user/group.rb
Overview
User api of weixin.
Defined Under Namespace
Modules: Group
Instance Method Summary collapse
-
#change_remark(access_token, openid, remark) ⇒ Hash
Change the remark of user via post.
-
#check_oauth2_token(openid, oauth2_token) ⇒ Hash
Check the oauth2_token.
-
#get_oauth2_token_with_code(app_id, app_secret, code, grant_type = 'authorization_code') ⇒ Hash
Get oauth2 token with code.
-
#get_user_base_info(access_token, openid, lang = 'zh_CN') ⇒ Hash
Get the user base info.
-
#get_user_info_with_snsapi_userinfo(oauth2_token, openid, lang) ⇒ Hash
Get user info with snsapi_userinfo.
-
#refresh_oauth2_token(app_id, refresh_token, grant_type = 'refresh_token') ⇒ Hash
Refresh oauth2 token.
-
#user_list(access_token, next_openid = nil) ⇒ Hash
Get user list of weixin.
Instance Method Details
#change_remark(access_token, openid, remark) ⇒ Hash
Change the remark of user via post.
20 21 22 23 24 |
# File 'lib/wx_ext/api/user.rb', line 20 def change_remark(access_token, openid, remark) url = 'https://api.weixin.qq.com/cgi-bin/user/info/updateremark'\ "?access_token=#{access_token}" Helper.http_post(url, { openid: openid, remark: remark }.to_json) end |
#check_oauth2_token(openid, oauth2_token) ⇒ Hash
Check the oauth2_token.
92 93 94 95 96 |
# File 'lib/wx_ext/api/user.rb', line 92 def check_oauth2_token(openid, oauth2_token) url = 'https://api.weixin.qq.com/sns/auth'\ "?access_token=#{oauth2_token}&openid=#{openid}" Helper.http_get(url, { accept: :json }) end |
#get_oauth2_token_with_code(app_id, app_secret, code, grant_type = 'authorization_code') ⇒ Hash
Get oauth2 token with code.
57 58 59 60 61 |
# File 'lib/wx_ext/api/user.rb', line 57 def get_oauth2_token_with_code(app_id, app_secret, code, grant_type='authorization_code') url = 'https://api.weixin.qq.com/sns/oauth2/access_token'\ "?appid=#{app_id}&secret=#{app_secret}&code=#{code}&grant_type=#{grant_type}" Helper.http_get(url, { accept: :json }) end |
#get_user_base_info(access_token, openid, lang = 'zh_CN') ⇒ Hash
Get the user base info.
32 33 34 35 36 |
# File 'lib/wx_ext/api/user.rb', line 32 def get_user_base_info(access_token, openid, lang='zh_CN') url = 'https://api.weixin.qq.com/cgi-bin/user/info'\ "?access_token=#{access_token}&openid=#{openid}&lang=#{lang}" Helper.http_get(url, { accept: :json }) end |
#get_user_info_with_snsapi_userinfo(oauth2_token, openid, lang) ⇒ Hash
Get user info with snsapi_userinfo.
81 82 83 84 85 |
# File 'lib/wx_ext/api/user.rb', line 81 def get_user_info_with_snsapi_userinfo(oauth2_token, openid, lang) url = 'https://api.weixin.qq.com/sns/userinfo'\ "?access_token=#{oauth2_token}&#{openid}=OPENID&lang=#{lang}" Helper.http_get(url, { accept: :json }) end |
#refresh_oauth2_token(app_id, refresh_token, grant_type = 'refresh_token') ⇒ Hash
Refresh oauth2 token.
69 70 71 72 73 |
# File 'lib/wx_ext/api/user.rb', line 69 def refresh_oauth2_token(app_id, refresh_token, grant_type='refresh_token') url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token'\ "?appid=#{app_id}&grant_type=#{grant_type}&refresh_token=#{refresh_token}" Helper.http_get(url, { accept: :json }) end |
#user_list(access_token, next_openid = nil) ⇒ Hash
Get user list of weixin.
43 44 45 46 47 48 |
# File 'lib/wx_ext/api/user.rb', line 43 def user_list(access_token, next_openid=nil) url = 'https://api.weixin.qq.com/cgi-bin/user/get'\ "?access_token=#{access_token}" url += "&next_openid=#{next_openid}" if next_openid Helper.http_get(url, { accept: :json }) end |