HikPermissionGroupsPersons.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import requests
  2. import json
  3. import datetime
  4. def datetime_now():
  5. datetimenow = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
  6. return datetimenow
  7. def hik_permissiongroupspersons(hik_accesstoken,groupId,jobids):
  8. headers = {"content-type": "application/json"}
  9. data = {
  10. "groupId": groupId,
  11. "employeeNos": jobids,
  12. "autoIssue": "true"
  13. }
  14. response = requests.post(
  15. url="https://api2.hik-cloud.com/api/v1/open/accessControl/permissionGroups/actions/addPersons?access_token=%s" % hik_accesstoken,
  16. headers=headers,
  17. data=json.dumps(data)
  18. )
  19. if response.json()["code"] == 200:
  20. print("%s,权限组绑定人员成功"%(datetime_now()))
  21. else:
  22. print(datetime_now(),jobids,response.json()["message"])
  23. # return response.json()
  24. # if __name__ == '__main__':
  25. # with open("config.json") as f:
  26. # data = json.load(f)
  27. # client_id = data["client_id"]
  28. # client_secret = data["client_secret"]
  29. # groupId = data["groupId"]
  30. # accesstoken = hik_access_token(client_id, client_secret)
  31. #
  32. # jobids = ["10","11"]
  33. # hik_permissiongroupspersons(accesstoken,jobids)