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.

Author:

  • FuShengYang

Defined Under Namespace

Modules: Group

Instance Method Summary collapse

Instance Method Details

#change_remark(access_token, openid, remark) ⇒ Hash

Change the remark of user via post.

Parameters:

  • access_token (Enumerable<String>)
  • openid (Enumerable<String>)
  • remark (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



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.

Parameters:

  • openid (Enumerable<String>)
  • oauth2_token (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



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.

Parameters:

  • app_id (Enumerable<String>)
  • app_secret (Enumerable<String>)
  • code (Enumerable<String>)
  • grant_type (Enumerable<String>) (defaults to: 'authorization_code')

Returns:

  • (Hash)

    Json based hash.



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.

Parameters:

  • access_token (Enumerable<String>)
  • openid (Enumerable<String>)
  • lang (Enumerable<String>) (defaults to: 'zh_CN')

Returns:

  • (Hash)

    Json based hash.



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.

Parameters:

  • oauth2_token (Enumerable<String>)
  • openid (Enumerable<String>)
  • lang (Enumerable<String>)

Returns:

  • (Hash)

    Json based hash.



81
82
83
84
85
# File 'lib/wx_ext/api/user.rb', line 81

def (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.

Parameters:

  • app_id (Enumerable<String>)
  • refresh_token (Enumerable<String>)
  • grant_type (Enumerable<String>) (defaults to: 'refresh_token')

Returns:

  • (Hash)

    Json based hash.



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.

Parameters:

  • access_token (Enumerable<String>)
  • next_openid (Enumerable<String>) (defaults to: nil)

Returns:

  • (Hash)

    Json based hash.



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