module WxExt::Api::User

User api of weixin.

@author FuShengYang

User api of weixin.

@author FuShengYang

Public Instance Methods

change_remark(access_token, openid, remark) click to toggle source

Change the remark of user via post.

@param [Enumerable<String>] access_token @param [Enumerable<String>] openid @param [Enumerable<String>] remark @return [Hash] Json based hash.

# 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) click to toggle source

Check the oauth2_token.

@param [Enumerable<String>] openid @param [Enumerable<String>] oauth2_token @return [Hash] Json based hash.

# 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') click to toggle source

Get oauth2 token with code.

@param [Enumerable<String>] app_id @param [Enumerable<String>] app_secret @param [Enumerable<String>] code @param [Enumerable<String>] grant_type @return [Hash] Json based hash.

# 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') click to toggle source

Get the user base info.

@param [Enumerable<String>] access_token @param [Enumerable<String>] openid @param [Enumerable<String>] lang @return [Hash] Json based hash.

# 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) click to toggle source

Get user info with snsapi_userinfo.

@param [Enumerable<String>] oauth2_token @param [Enumerable<String>] openid @param [Enumerable<String>] lang @return [Hash] Json based hash.

# 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') click to toggle source

Refresh oauth2 token.

@param [Enumerable<String>] app_id @param [Enumerable<String>] refresh_token @param [Enumerable<String>] grant_type @return [Hash] Json based hash.

# 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) click to toggle source

Get user list of weixin.

@param [Enumerable<String>] access_token @param [Enumerable<String>] next_openid @return [Hash] Json based hash.

# 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