mirror of
https://github.com/capricornxl/ad-password-self-service.git
synced 2025-08-12 06:55:50 +08:00
修复utils目录自定义模块中的处理逻辑return结果不正确,导致Django无法正常在前台显示结果的BUG
This commit is contained in:
@@ -11,11 +11,19 @@ import requests
|
||||
from dingtalk.client import AppKeyClient
|
||||
from pwdselfservice import cache_storage
|
||||
|
||||
from pwdselfservice.local_settings import DING_APP_KEY, DING_APP_SECRET, DING_CORP_ID, DING_URL, DING_MO_APP_ID, DING_MO_APP_SECRET
|
||||
import os
|
||||
APP_ENV = os.getenv('APP_ENV')
|
||||
|
||||
if APP_ENV == 'dev':
|
||||
from conf.local_settings_dev import *
|
||||
else:
|
||||
from conf.local_settings import *
|
||||
|
||||
|
||||
class DingDingOps(object):
|
||||
def __init__(self, corp_id=DING_CORP_ID, app_key=DING_APP_KEY, app_secret=DING_APP_SECRET, mo_app_id=DING_MO_APP_ID, mo_app_secret=DING_MO_APP_SECRET, storage=cache_storage):
|
||||
class DingDingOps(AppKeyClient):
|
||||
def __init__(self, corp_id=DING_CORP_ID, app_key=DING_APP_KEY, app_secret=DING_APP_SECRET, mo_app_id=DING_MO_APP_ID, mo_app_secret=DING_MO_APP_SECRET,
|
||||
storage=cache_storage):
|
||||
super().__init__(corp_id, app_key, app_secret, storage)
|
||||
self.corp_id = corp_id
|
||||
self.app_key = app_key
|
||||
self.app_secret = app_secret
|
||||
@@ -23,23 +31,13 @@ class DingDingOps(object):
|
||||
self.mo_app_secret = mo_app_secret
|
||||
self.storage = storage
|
||||
|
||||
@property
|
||||
def _client_connect(self):
|
||||
"""
|
||||
钉钉连接器
|
||||
:return:
|
||||
"""
|
||||
return AppKeyClient(corp_id=self.corp_id, app_key=self.app_key, app_secret=self.app_secret)
|
||||
|
||||
def get_union_id_by_code(self, code):
|
||||
"""
|
||||
通过移动应用接入扫码返回的临时授权码,使用临时授权码换取用户的unionid
|
||||
:param code:
|
||||
:return:
|
||||
通过移动应用接入扫码返回的临时授权码,使用临时授权码换取用户的 unionid
|
||||
:param code: 临时授权码
|
||||
:return: unionid
|
||||
"""
|
||||
# token = self.ding_get_access_token
|
||||
time_stamp = int(round(time.time() * 1000))
|
||||
# 时间戳
|
||||
# 通过appSecret计算出来的签名值,该参数值在HTTP请求参数中需要urlEncode(因为签名中可能包含特殊字符+)。
|
||||
signature = quote(base64.b64encode(hmac.new(
|
||||
self.mo_app_secret.encode('utf-8'),
|
||||
@@ -51,8 +49,8 @@ class DingDingOps(object):
|
||||
url=url,
|
||||
json=dict(tmp_auth_code=code),
|
||||
)
|
||||
resp = resp.json()
|
||||
try:
|
||||
resp = resp.json()
|
||||
if resp['errcode'] != 0:
|
||||
return False, 'get_union_id_by_code: %s' % str(resp)
|
||||
else:
|
||||
@@ -62,13 +60,13 @@ class DingDingOps(object):
|
||||
|
||||
def get_user_id_by_code(self, code):
|
||||
"""
|
||||
通过code获取用户的userid
|
||||
通过code获取用户的 userid
|
||||
:param id: 用户在当前钉钉开放平台账号范围内的唯一标识
|
||||
:return:
|
||||
"""
|
||||
_status, union_id = self.get_union_id_by_code(code)
|
||||
if _status:
|
||||
return True, self._client_connect.user.get_userid_by_unionid(union_id).get('userid')
|
||||
return True, self.user.get_userid_by_unionid(union_id).get('userid')
|
||||
else:
|
||||
return False, 'get_user_id_by_code: %s' % str(union_id)
|
||||
|
||||
@@ -79,9 +77,10 @@ class DingDingOps(object):
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
return True, self._client_connect.user.get(user_id)
|
||||
return True, self.user.get(user_id)
|
||||
except Exception as e:
|
||||
return False, 'get_user_detail_by_user_id: %s' % str(e)
|
||||
|
||||
except (KeyError, IndexError) as k_error:
|
||||
return False, 'get_user_detail_by_user_id: %s' % str(k_error)
|
||||
|
||||
|
Reference in New Issue
Block a user