HikAdduser.py 1.0 KB

123456789101112131415161718192021222324252627
  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_adduser(hik_access_token,jobid,name):
  8. data = {
  9. "employeeNo": jobid,
  10. "personName": name
  11. }
  12. headers = {"content-type": "application/json"}
  13. response =requests.post(url="https://api2.hik-cloud.com/api/v1/open/basic/persons/create?access_token=%s"%hik_access_token,headers=headers,data=json.dumps(data))
  14. if response.json()["code"] == 200:
  15. print("%s,%s(%s)用户添加成功"%(datetime_now(),name,jobid))
  16. else:
  17. print("%s,%s(%s)%s"%(datetime_now(),name,jobid,response.json()["message"]))
  18. # if __name__ == '__main__':
  19. # with open("config.json") as f:
  20. # data = json.load(f)
  21. # client_id = data["client_id"]
  22. # client_secret = data["client_secret"]
  23. # groupId = data["groupId"]
  24. # hik_accesstoken = hik_access_token(client_id, client_secret)
  25. # hik_adduser(hik_accesstoken,"2254","lisand")