UserAuthUtils.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. if channel_list:
  18. for _ in channel_list:
  19. data1.append(_['nickName'])
  20. sql2 = f"""select GROUP_CONCAT(channel_ids) from user_channel_group_auth a
  21. left join channel_group b on a.channel_group_id=b.id
  22. where user_id={user_id}"""
  23. data2 = db.quchen_text.getOne(sql2)
  24. data3 = []
  25. if data2:
  26. rsp = requests.get('http://api.zanxiangnet.com/system/api/mp/mpAccount/search/3')
  27. channel_list = []
  28. channel_dict = {}
  29. for _ in rsp.json()['data']:
  30. channel_list.append((_['id'], _['nickName']))
  31. channel_dict[_['id']] = _['nickName']
  32. data2_2 = tuple(data2.split(','))
  33. for _ in data2_2:
  34. data3.append(channel_dict[int(_)])
  35. return tuple(data1 + data3)
  36. def super_auth():
  37. "获取超级数据权限的用户列表"
  38. rsp = requests.get('http://api.zanxiangnet.com/erp/api/user/search/3?powerLevelMin=99')
  39. user_list = []
  40. for _ in rsp.json()['data']:
  41. user_list.append(_['userId'])
  42. return user_list
  43. if __name__ == '__main__':
  44. # print(get_auth_channel(109))
  45. # print(get_role(78))
  46. print(f"ssed{tuple([1, 3, 4])}")