Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 网页授权获取用户基本信息 #31

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions docs/basic.rst
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,83 @@
:param str group_id: 分组 ID
:return: 返回的 JSON 数据包

.. py:method:: get_oauth2_userinfo_one_step(code)

一步网页授权获取用户基本信息

运行时检查:``appid``, ``appsecret``

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html`_

:param str code: 通过oauth2 authorize获取的code
:return: JSON 数据包,包含用户的基本信息
:raises: HTTPError: 微信api http 请求失败
OfficialAPIError: 获取信息api出错

.. py:method:: generate_oauth2_authorize_url(redirect_uri [, response_type='code', scope='snsapi_userinfo', state=''])

生成获取用户信息的url

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E7.AC.AC.E4.B8.80.E6.AD.A5.EF.BC.9A.E7.94.A8.E6.88.B7.E5.90.8C.E6.84.8F.E6.8E.88.E6.9D.83.EF.BC.8C.E8.8E.B7.E5.8F.96code`_

:param str redirect_uri: 授权后重定向的回调链接地址,该方法内自动使用urlencode对链接进行处理
:param str response_type: 返回类型,默认为code
:param str scope: 应用授权作用域,snsapi_base (不弹出授权页面,直接跳转,只能获取用户openid),
snsapi_userinfo (弹出授权页面,可通过openid拿到昵称、性别、所在地。
并且,即使在未关注的情况下,只要用户授权,也能获取其信息)。
默认为snsapi_userinfo
:param str state: 重定向后会带上state参数,开发者可以填写a-zA-Z0-9的参数值,最多128字节
:return: 用户授权的url链接字符串

.. py:method:: get_oauth2_access_token(code [, grant_type='authorization_code'])

通过code换取网页授权access_token

运行时检查:``appid``, ``appsecret``

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E7.AC.AC.E4.BA.8C.E6.AD.A5.EF.BC.9A.E9.80.9A.E8.BF.87code.E6.8D.A2.E5.8F.96.E7.BD.91.E9.A1.B5.E6.8E.88.E6.9D.83access_token`_

:param str code: 通过oauth2 authorize获取的code
:param str grant_type: 授权类型,默认为authorization_code
:return: 返回的 JSON 数据包
:raise HTTPError: 微信api http 请求失败

.. py:method:: refresh_oauth2_access_token(self, code, grant_type='authorization_code')

刷新access_token(如果需要)

运行时检查:``appid``, ``appsecret``

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E7.AC.AC.E4.B8.89.E6.AD.A5.EF.BC.9A.E5.88.B7.E6.96.B0access_token.EF.BC.88.E5.A6.82.E6.9E.9C.E9.9C.80.E8.A6.81.EF.BC.89`_

:param str code: 通过oauth2 authorize获取的code
:param str grant_type: 授权类型,默认为authorization_code
:return: 返回的 JSON 数据包
:raise HTTPError: 微信api http 请求失败

.. py:method:: get_oauth2_userinfo(access_token, user_id [, lang='zh_CN'])

拉取用户信息(需scope为 snsapi_userinfo)

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E7.AC.AC.E5.9B.9B.E6.AD.A5.EF.BC.9A.E6.8B.89.E5.8F.96.E7.94.A8.E6.88.B7.E4.BF.A1.E6.81.AF.28.E9.9C.80scope.E4.B8.BA_snsapi_userinfo.29`_

:param str access_token: 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
:param str user_id: 用户的唯一标识
:param str lang: 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
:return: 返回的 JSON 数据包
:raise HTTPError: 微信api http 请求失败

.. py:method:: check_oauth2_access_token(access_token, user_id)

检验授权凭证(oauth2 access_token)是否有效

详情请参考 `http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html#.E9.99.84.EF.BC.9A.E6.A3.80.E9.AA.8C.E6.8E.88.E6.9D.83.E5.87.AD.E8.AF.81.EF.BC.88access_token.EF.BC.89.E6.98.AF.E5.90.A6.E6.9C.89.E6.95.88`_

:param str access_token: 网页授权接口调用凭证,注意:此access_token与基础支持的access_token不同
:param str user_id: 用户的唯一标识
:return: 返回的 JSON 数据包
:raise HTTPError: 微信api http 请求失败

.. py:method:: get_user_info(user_id [, lang='zh_CN'])

获取用户基本信息
Expand Down
6 changes: 6 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
* 主动对指定用户发送图片消息
* 主动对指定用户发送语音消息
* 主动对指定用户发送视频消息
* oauth2 一步网页授权获取用户基本信息
* oauth2 生成获取用户信息的url
* oauth2 通过code换取网页授权access_token
* oauth2 刷新access_token
* oauth2 拉取用户信息
* oauth2 检验授权凭证(oauth2 access_token)是否有效
* 获取指定用户的个人信息
* 获取用户列表
* 获取分组列表
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from setuptools import setup, find_packages

setup(
name='wechat-sdk',
version='0.5.8',
name='wechat-python-sdk',
version='0.6.1',
keywords=('wechat', 'sdk', 'wechat sdk'),
description=u'微信公众平台Python开发包',
long_description=open("README.rst").read(),
license='BSD License',

url='https://github.com/doraemonext/wechat-python-sdk',
author='doraemonext',
author_email='doraemonext@gmail.com',
url='https://github.com/bowenpay/wechat-python-sdk',
author='doraemonext jingpingyi',
author_email='doraemonext@gmail.com, jingping.yi@gmail.com',

packages=find_packages(),
include_package_data=True,
Expand Down
Loading