Exemplo n.º 1
0
    def verify_bk_token(bk_token):
        """
        请求VERIFY_URL,认证bk_token是否正确
        @param bk_token: "_FrcQiMNevOD05f8AY0tCynWmubZbWz86HslzmOqnhk"
        @type bk_token: str
        @return: False,None True,username
        @rtype: bool,None/str
        """
        api_params = {'bk_token': bk_token}

        try:
            response = send(ConfFixture.VERIFY_URL,
                            'GET',
                            api_params,
                            verify=False)
        except Exception:
            logger.exception(u"Abnormal error in verify_bk_token...")
            return False, None

        if response.get('result'):
            data = response.get('data')
            username = data.get('username')
            return True, username
        else:
            error_msg = response.get('message', '')
            error_data = response.get('data', '')
            logger.error(u"Fail to verify bk_token, error=%s, ret=%s" %
                         (error_msg, error_data))
            return False, None
Exemplo n.º 2
0
 def verify_weixin_code(code):
     """
     验证 WEIXIN 认证返回的授权码
     @param {string} code WEIXIN 认证返回的授权码
     @return {tuple} ret
     @return {boolean} ret[0] 是否认证通过
     @return {dict} ret[1] 当 result=True,该字段为用户信息,举例
         {
             u'username': u'',
             u'avatar': u''
         }
     """
     api_params = {
         "code": code,
     }
     try:
         response = send(ConfFixture.WEIXIN_INFO_URL, "GET", api_params)
         ret = response.get("ret")
         if ret == 0:
             return True, response["data"]
         else:
             logger.error(
                 u"通过微信授权码,获取用户信息失败,error={},ret={}".format(response["msg"], ret)
             )
             return False, None
     except Exception:  # pylint: disable=broad-except
         logger.exception(u"通过微信授权码,获取用户信息异常")
         return False, None
Exemplo n.º 3
0
 def verify_weixin_code(code):
     """
     验证 WEIXIN 认证返回的授权码
     @param {string} code WEIXIN 认证返回的授权码
     @return {tuple} ret
     @return {boolean} ret[0] 是否认证通过
     @return {dict} ret[1] 当 result=True,该字段为用户信息,举例
         {
             u'username': u'',
             u'avatar': u''
         }
     """
     api_params = {
         'code': code,
     }
     try:
         response = send(ConfFixture.WEIXIN_INFO_URL, 'GET', api_params)
         ret = response.get('ret')
         if ret == 0:
             return True, response['data']
         else:
             logger.error(u"通过微信授权码,获取用户信息失败,error=%s,ret=%s" %
                          (response['msg'], ret))
             return False, None
     except Exception:
         logger.exception(u"通过微信授权码,获取用户信息异常")
         return False, None
Exemplo n.º 4
0
    def verify_bk_token(bk_token):
        """
        请求VERIFY_URL,认证bk_token是否正确
        @param bk_token: "_FrcQiMNevOD05f8AY0tCynWmubZbWz86HslzmOqnhk"
        @type bk_token: str
        @return: False,None True,username
        @rtype: bool,None/str
        """
        api_params = {"bk_token": bk_token}

        try:
            response = send(ConfFixture.VERIFY_URL,
                            "GET",
                            api_params,
                            verify=False)
        except Exception:  # pylint: disable=broad-except
            logger.exception(u"Abnormal error in verify_bk_token...")
            return False, None

        if response.get("result"):
            data = response.get("data")
            username = data.get("username")
            return True, username
        else:
            error_msg = response.get("message", "")
            error_data = response.get("data", "")
            logger.error(u"Fail to verify bk_token, error={}, ret={}".format(
                error_msg, error_data))
            return False, None