优化工单模块,增加企微模块
This commit is contained in:
53
sg_wechat_enterprise/models/client/api/jkm_oauth.py
Normal file
53
sg_wechat_enterprise/models/client/api/jkm_oauth.py
Normal file
@@ -0,0 +1,53 @@
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import six
|
||||
from wechatpy.client.api.base import BaseWeChatAPI
|
||||
|
||||
|
||||
class JkmWechatOauth(BaseWeChatAPI):
|
||||
OAUTH_BASE_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize'
|
||||
|
||||
def authorize_url(self, redirect_uri, state=None, agent_id=None, scope='snsapi_base'):
|
||||
"""
|
||||
构造网页授权链接
|
||||
详情请参考
|
||||
https://work.weixin.qq.com/api/doc#90000/90135/91022
|
||||
|
||||
:param redirect_uri: 授权后重定向的回调链接地址
|
||||
:param state: 重定向后会带上 state 参数
|
||||
:param agent_id: 企业应用的id
|
||||
:param scope: 应用授权作用域
|
||||
:return: 返回的 JSON 数据包
|
||||
"""
|
||||
redirect_uri = six.moves.urllib.parse.quote(redirect_uri, safe=b'')
|
||||
url_list = [
|
||||
self.OAUTH_BASE_URL,
|
||||
'?appid=',
|
||||
self._client.corp_id,
|
||||
'&redirect_uri=',
|
||||
redirect_uri,
|
||||
'&response_type=code&scope=',
|
||||
scope,
|
||||
]
|
||||
if state:
|
||||
url_list.extend(['&state=', state])
|
||||
url_list.append('#wechat_redirect')
|
||||
if agent_id:
|
||||
url_list.extend(['&agentid=', str(agent_id)])
|
||||
return ''.join(url_list)
|
||||
|
||||
def get_user_info(self, code):
|
||||
"""
|
||||
获取访问用户身份
|
||||
详情请参考
|
||||
https://work.weixin.qq.com/api/doc#90000/90135/91023
|
||||
|
||||
:param code: 通过成员授权获取到的code
|
||||
:return: 返回的 JSON 数据包
|
||||
"""
|
||||
|
||||
return self._get(
|
||||
'user/getuserinfo',
|
||||
params={
|
||||
'code': code,
|
||||
}
|
||||
)
|
||||
Reference in New Issue
Block a user