示例#1
0
 def gettoken(self):
     """登录账号角色"""
     self.get_deptidANDroleid()
     method = 'get'
     url = self.localhost + '/api/api-uaa/oauth/user/token'
     data1 = {
         'username': self.name,
         'password': self.passwd,
         'deviceId': '7B2E6955-D77A-40F7-A37B-4281E703B2A2',
         'orgId': self.g['orgid'],
         'deptId': self.g['deptId'],
         'roleId': self.g['roleId']
     }
     headers = {'Authorization': self.Authorization}
     respone = R.request(method, url, data1, headers)
     if respone['msg'] == '':
         self.g['token'] = respone['data']['token_type'] + respone['data'][
             'access_token']
         Log.logsinfo('获取token成功:{0}'.format(self.g['token']))
         '''保存token到文件'''
         setdata(self.file, self.g['token'], 1, 0)
         return self.g['token']
     else:
         Log.logsinfo('error!接口返回错误:{0}'.format(respone))
         Log.logtraceback()
示例#2
0
 def get_acctoken(self):
     """验证账号是否正确"""
     method = 'get'
     url = self.localhost + '/api/api-uaa/oauth/user/token'
     self.g['data'] = {
         'username': self.name,
         'password': self.passwd,
         'deviceId': '7B2E6955-D77A-40F7-A37B-4281E703B2A2'
     }
     headers = {'Authorization': self.Authorization}
     respone = R.request(method, url, self.g['data'], headers)
     if respone['msg'] == '':
         self.g['acctoken'] = respone['data']['token_type'] + respone[
             'data']['access_token']
         Log.logsinfo('获取acctoken成功:{0}'.format(self.g['acctoken']))
     else:
         Log.logsinfo('error!接口返回错误:{0}'.format(respone))
         Log.logtraceback()
示例#3
0
 def get_deptidANDroleid(self):
     """获取部门id和角色id"""
     self.get_orgid()
     method = 'get'
     url = self.localhost + '/api/his-user-center/staff_organization/getStaffDeptRoleList/{0}'.format(
         self.g['orgid'])
     data = None
     headers = {'Authorization': self.g['acctoken']}
     respone = R.request(method, url, data, headers)
     if respone['msg'] == '':
         for i in respone['data']:
             if i['roleName'] == self.rolename:
                 self.g['deptId'] = i['deptId']
                 self.g['roleId'] = i['roleId']
         Log.logsinfo('获取deptId成功:{0}'.format(self.g['deptId']))
         Log.logsinfo('获取roleId成功:{0}'.format(self.g['roleId']))
     else:
         Log.logsinfo('error!接口返回错误:{0}'.format(respone))
         Log.logtraceback()
示例#4
0
 def get_orgid(self):
     """如果账号正确,进行下一步,获取账号机构列表"""
     self.get_acctoken()
     method = 'get'
     url = self.localhost + '/api/his-user-center/staff_organization/getStaffOrganizationList'
     data = None
     headers = {'Authorization': self.g['acctoken']}
     respone = R.request(method, url, data, headers)
     if respone['msg'] == '':
         for i in respone['data']:  # 遍历此账户所有机构
             if i['orgName'] == self.orgname:
                 self.g['orgid'] = i['id']
                 '''保存orgid到文件便于引用'''
                 setdata(self.file, self.g['orgid'], 1, 1)
                 return self.g['orgid']
         Log.logsinfo('获取orgId成功:{0}'.format(self.g['orgid']))
     else:
         Log.logsinfo('error!接口返回错误:{0}'.format(respone))
         Log.logtraceback()