UserAuthUtils.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from model.DataBaseUtils import MysqlUtils
  2. import requests
  3. def get_auth_user(user_id):
  4. """获取用户拥有所有用户(包括自己)的权限"""
  5. rsp = requests.get(url=f'http://api.zanxiangnet.com/erp/api/user/subUser/3/{user_id}')
  6. nick_name_list = []
  7. for _ in rsp.json()['data']:
  8. nick_name_list.append(_['nickName'])
  9. return nick_name_list
  10. def get_auth_channel(user_id):
  11. """获取用户拥有的所有公众号权限"""
  12. db = MysqlUtils()
  13. # 普通权限------java,获取本人对应拥有的公众号
  14. rsp = requests.get(f'http://api.zanxiangnet.com/system/api/mp/mpAccount/subAccountWithUser/3/{user_id}')
  15. channel_list = rsp.json()['data']
  16. data1 = []
  17. for _ in channel_list:
  18. data1.append(_['nickName'])
  19. sql2 = f"""select GROUP_CONCAT(channel_ids) from user_channel_group_auth a
  20. left join channel_group b on a.channel_group_id=b.id
  21. where user_id={user_id}"""
  22. data2 = db.quchen_text.getOne(sql2)
  23. data3 = []
  24. if data2:
  25. rsp = requests.get('http://api.zanxiangnet.com/system/api/mp/mpAccount/search/3')
  26. channel_list = []
  27. channel_dict = {}
  28. for _ in rsp.json()['data']:
  29. channel_list.append((_['id'], _['nickName']))
  30. channel_dict[_['id']] = _['nickName']
  31. data2_2 = tuple(data2.split(','))
  32. for _ in data2_2:
  33. data3.append(channel_dict[int(_)])
  34. return tuple(data1 + data3)
  35. def super_auth():
  36. "获取超级数据权限的用户列表"
  37. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=99')
  38. user_list = []
  39. for _ in rsp.json()['data']:
  40. user_list.append(_['userId'])
  41. return user_list
  42. if __name__ == '__main__':
  43. # print(get_auth_channel(109))
  44. # print(get_role(78))
  45. print(f"ssed{tuple([1, 3, 4])}")