From 5e09b59eca5384a156e3f9f4f7df4af96e19fe85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E4=B9=90=F0=9F=8C=8C?= Date: Tue, 27 Apr 2021 14:12:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E9=92=89=E9=92=89=E5=9B=9E=E8=B0=83=E8=8E=B7=E5=8F=96=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BF=A1=E6=81=AF=E5=A4=B1=E8=B4=A5=E6=97=B6=20?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=87=86=E7=A1=AE=E7=9A=84=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/dingding_ops.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/utils/dingding_ops.py b/utils/dingding_ops.py index a4377cc..a93aff6 100644 --- a/utils/dingding_ops.py +++ b/utils/dingding_ops.py @@ -68,10 +68,14 @@ class DingDingOps(object): json=dict(tmp_auth_code=code), ) resp = resp.json() + print(resp) try: - return True, resp["user_info"]["unionid"] - except Exception as e: - return False, 'ding_get_union_id_by_code: {}' .format(e) + if resp['errcode'] != 0: + return False, 'ding_get_union_id_by_code: %s' % str(resp) + else: + return True, resp["user_info"]["unionid"] + except Exception: + return False, 'ding_get_union_id_by_code: %s' % str(resp) def ding_get_userid_by_union_id(self, union_id): """ @@ -82,7 +86,10 @@ class DingDingOps(object): try: return True, self.ding_client_connect.user.get_userid_by_unionid(union_id)['userid'] except Exception as e: - return False, 'ding_get_userid_by_union_id: {}' .format(e) + return False, 'ding_get_union_id_by_code: %s' % str(e) + + except (KeyError, IndexError) as k_error: + return False, 'ding_get_union_id_by_code: %s' % str(k_error) @property def ding_get_org_user_count(self): @@ -102,13 +109,16 @@ class DingDingOps(object): try: return True, self.ding_client_connect.user.get(user_id) except Exception as e: - return False, 'ding_get_userinfo_detail: {}' .format(e) + return False, 'ding_get_union_id_by_code: %s' % str(e) + + except (KeyError, IndexError) as k_error: + return False, 'ding_get_union_id_by_code: %s' % str(k_error) if __name__ == '__main__': start = time.time() - d = DingDingOps() - print(d.ding_get_access_token) - # print(d.user.getuserinfo('2ecebee187863a8ea2863a7a2fa17b49')) + d = DingDingOps().ding_client_connect + unicode = '' + # print(d.) end = time.time() print("running:" + str(round((end - start), 3)))