123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833 |
- """
- 中建八局一公司业务接口
- """
- from urllib import parse
- import requests
- import time
- import traceback
- import sys
- import importlib
- sys.path.append('/home/server/projects/taiwuict/cscec-8bur-vms/supplement-python')
- methods = importlib.import_module(f"libraries.base_original")
- class Api(object):
-
- def __init__(self, username='500A7062', password='198797#cjhxbin',
- project_id='d0f254cc-8196-499a-8f0d-52bf8ba91486',
- project_name='山东省公共卫生临床中心(济南市传染病医院二期)项目工程总承包(EPC)'):
- """
- 第1现场:
- 济南市中心医院(东院区)项目工程总承包(EPC)
- 7eeb53a1-2bbd-4efa-8c8e-66936476226c
- 第2现场:
- 山东省大数据产业基地建设项目施工总承包
- 项目编号:500D10301958
- ORGID:63729db2-ea9c-4096-b5d9-3ad0369903c8
- 第3现场:
- 山东省公共卫生临床中心(济南市传染病医院二期)项目工程总承包(EPC)
- ORGID:d0f254cc-8196-499a-8f0d-52bf8ba91486
- 第4现场:
- 济南奥体东 13 及 17-2 号地块开发项目工程总 承包(EPC)
- a8defc53-76b3-4f4e-931d-8dd35ba310c7
- """
-
- self.service_url = 'http://app.cscec81.com/api'
-
-
-
-
- self.project_id = project_id
- self.project_name = project_name
-
- self.token = None
- if username and password:
- session_id, user_code, user_id = self.get_user_info(username, password)
- self.token = f"Bearer {self.get_token(session_id, user_code, user_id)}"
-
-
- @staticmethod
- def get_user_info(username, password):
- """
- 获取用户信息
- url: http://pmdev.cscec81.com/Login/Login.ashx?t=' + new Date().getTime() + '&method=CheckLogin
- """
-
- url = f"http://app.cscec81.com/Login/Login.ashx"
-
-
- url += f"?t={int(time.time() * 1000)}&method=CheckLogin"
- data = {
- 'Username': username,
- 'password': password,
- 'usertype': '0',
- 'sys': 'sitemanage',
- 'clientType': '5',
- }
- payload = parse.urlencode(data, encoding='utf-8')
- headers = {
- 'Content-Type': 'application/x-www-form-urlencoded',
- 'Cookie': 'ASP.NET_SessionId=luy3wg10b2kymc2nbiytn4xt'
- }
- print('Api.get_user_info.url:', url)
-
-
- response = requests.request('POST', url, headers=headers, data=payload)
- if response.status_code > 300:
- print('Api.get_user_info.result:', response.status_code)
- print('Api.get_user_info.detail:', response.text)
- return '', '', ''
- print('Api.get_user_info.result:', response.status_code)
- json_data = response.json()
-
- if not json_data or not json_data.get('data'):
- return '', '', ''
- session_id = json_data.get('data').get('ticketID')
- user_code = json_data.get('data').get('userCode')
- user_id = json_data.get('data').get('userID')
-
-
-
- return session_id, user_code, user_id
- @staticmethod
- def get_token(session_id, user_code, user_id):
- """
- 获取令牌
- url: http://pmdev.cscec81.com/api/oauth/token?grant_type=session&sessionId="
- + ticketID + "&userCode=" + userCode + "&userId=" + userID + "&client_type=web&system=1
- """
-
- url = f"http://app.cscec81.com/api/oauth/token"
-
- url += f"?grant_type=session&sessionId={session_id}&userCode={user_code}&userId={user_id}"
- url += f"&client_type=web&system=1"
- headers = {
- 'Authorization': 'Basic YnJvd3Nlcjo='
- }
- print('Api.get_token.url:', url)
-
- response = requests.post(url=url, headers=headers)
- if response.status_code > 300:
- print('Api.get_token.result:', response.status_code)
- print('Api.get_token.detail:', response.text)
- return ''
- else:
- print('Api.get_token.result:', response.status_code)
-
- return response.json().get('access_token')
- def get_cscec8_user_list(self):
- """
- 获取八局管理人员
- /api/economic/indoor/getProjectUserList?projectId=05037f9b-5cb6-4a43-9410-c0e6a83f280e
- return [
- {
- cardId: 身份证号
- imgUrl: 人脸图片
- dutyId: 职务id
- dutyName: 职务名称
- }
- ]
- """
- url = f"http://app.cscec81.com/api/economic/indoor/getProjectUserFaceList?projectId={self.project_id}"
- print('Api.get_cscec8_user_list.url:', url)
- response = requests.get(url, headers={'content-type': 'application/json'})
- if response.status_code > 300:
- print('Api.get_cscec8_user_list.result:', response.status_code)
- print('Api.get_cscec8_user_list.detail:', response.text)
- return []
- json_data = response.json()
-
- return json_data
- def get_worker_list(self):
- """
- 获取工人列表(云筑网工人信息)
- url: http://app.cscec81.com/api/safeeducation/workerInfo/workers?projectName=济南市中心医院(东院区)项目工程总承包(EPC)
- url: http://221.214.64.195:31229/api/safeeducation/workerInfo/workers?projectName=丽泽SOHO项目
- return [
- {
- headImagePath: 人脸图像地址
- subContractorName: 劳务公司
- workTypeName: 工种
- }
- ]
- """
- url = f"http://app.cscec81.com/api/safeeducation/workerInfo/workers?projectName={self.project_name}"
- url += f"&page=0&size=5000"
- print('Api.get_worker_list.url:', url)
- response = requests.get(url, headers={'content-type': 'application/json'})
- print('Api.get_worker_list.result:', response.status_code)
- if response.status_code > 300:
- print('Api.get_worker_list.result:', response.status_code)
- print('Api.get_worker_list.detail:', response.text)
- return []
- json_data = response.json()
-
-
- if not json_data or not json_data.get('success') or not json_data.get('data'):
- return []
- if not json_data.get('data').get('content'):
- return []
-
-
-
-
- return json_data.get('data').get('content')
- @staticmethod
- def get_face_image_by_path(image_path):
- """
- 获取工人照片
- url: https://lwres.yzw.cn/worker-avatar/Original/2018/0612/f3230a72-57ab-4aaf-a741-61d8c078fe89.jpg
- """
- while True:
- try:
- url = f"https://lwres.yzw.cn/{image_path}"
-
- response = requests.get(url, headers={'content-type': 'application/json'})
-
- if response.status_code > 300:
- print('Api.get_face_image_by_path.result:', response.status_code)
- print('Api.get_face_image_by_path.detail:', response.text)
- return b''
- else:
- return response.content
- except Exception as exception:
- if exception.__class__.__name__ == 'ConnectionError':
- print(f"Api.get_face_image_by_path: sleep 60s")
- time.sleep(60)
- else:
- print(f"Api.get_face_image_by_path.exception:{exception.__class__.__name__}")
- print(f"Api.get_face_image_by_path.traceback:{traceback.format_exc()}")
- return b''
- @staticmethod
- def get_face_image_by_path_v2(image_path):
- """
- 获取工人高清头像
- url: http://app.cscec81.com/media/202110/25/20211025-161726-381-4862.jpg
- """
- while True:
- try:
- url = f"http://app.cscec81.com/media/{image_path}"
-
- response = requests.get(url, headers={'content-type': 'application/json'})
-
- if response.status_code > 300:
- print('Api.get_face_image_by_path_v2.result:', response.status_code)
- print('Api.get_face_image_by_path_v2.detail:', response.text)
- return b''
- else:
- return response.content
- except Exception as exception:
- if exception.__class__.__name__ == 'ConnectionError':
- print(f"Api.get_face_image_by_path_v2: sleep 60s")
- time.sleep(60)
- else:
- print(f"Api.get_face_image_by_path_v2.exception:{exception.__class__.__name__}")
- print(f"Api.get_face_image_by_path_v2.traceback:{traceback.format_exc()}")
- return b''
- @staticmethod
- def get_face_image_by_url(image_url):
- """
- 获取八局管理人员人脸图像
- url: https://hcm.cscec81.com/img?type=photo&size=120&index=ae2f8424-c63f-11ea-b0a9-ea6f5cf6388d&rnd=1653618903725
- """
- while True:
- try:
-
- response = requests.get(image_url, headers={'content-type': 'application/json'})
-
- if response.status_code > 300:
- print('Api.get_face_image_by_url.result:', response.status_code)
- print('Api.get_face_image_by_url.detail:', response.text)
- return b''
- else:
- return response.content
- except Exception as exception:
- if exception.__class__.__name__ == 'ConnectionError':
- print(f"Api.get_face_image_by_url: sleep 60s")
- time.sleep(60)
- else:
- print(f"Api.get_face_image_by_url.exception:{exception.__class__.__name__}")
- print(f"Api.get_face_image_by_url.traceback:{traceback.format_exc()}")
- return b''
- def upload_file(self, face_uuid, file_path):
- """
- 上传文件图片
- """
-
-
- url = f"{self.service_url}/storages/files/anonymousUpload"
- files = {
- 'id': (None, face_uuid),
- 'file': ('1.jpg', open(file_path, 'rb'), 'image/jpg'),
- }
- headers = {
- 'Authorization': self.token,
- }
- print('Api.upload_file.url:', url)
- response = requests.post(url=url, files=files, headers=headers)
- if response.status_code > 300:
- print('Api.upload_file.result:', response.status_code)
-
- return ''
- else:
- print('Api.upload_file.result:', response.status_code)
- """
- 原地址
- http://10.198.6.181:31900/cscec81-cloud/202110/12/20211012-161022-713-7035.jpg
- http://10.198.6.173:30900/cscec81-cloud/202206/13/20220613-022118-96-3795.jpg
- 替换后地址
- http://221.214.64.195:31229/media/202110/12/20211012-161022-713-7035.jpg
- http://app.cscec81.com/media/202110/12/20211012-161022-713-7035.jpg
- """
- link = response.json().get('link')
-
-
-
- link = f"http://app.cscec81.com/media{link.split('cscec81-cloud')[1]}"
- return link
- def get_user_list(self):
- """
- 获取在职人员列表
- """
- url = f"{self.service_url}/system/users/getUserList"
- data = {
- 'companyId': self.project_id,
- 'userName': '',
- 'isMainPosition': '',
- 'postId': '',
- 'postName': '',
- }
- headers = {
- 'Authorization': self.token
- }
-
- response = requests.get(url, params=data, headers=headers)
-
- if response.status_code > 300:
- print('Api.get_user_list.result:', response.status_code)
- print('Api.get_user_list.detail:', response.text)
- return []
- json_data = response.json()
- if not json_data.get('content'):
- return []
- print(json_data.get('content')[0])
- return json_data.get('content')
- def push_face(self, send_at, face_file_link, face_name, cscec8_duty_name, cscec8_id, age, group, source):
- """
- 上传新增人脸(上传八局管理人员接口)
- """
-
-
- url = f"{self.service_url}/worker/userInfo"
- data = [{
- 'groupId': group,
- 'equipmentId': self.project_id,
- 'userId': cscec8_id,
- 'userName': face_name,
- 'age': age,
- 'postInfoName': cscec8_duty_name,
- 'lastEnterTime': send_at,
- 'faceInfo': face_file_link,
- 'sourceType': source,
- }]
-
-
- headers = {
- 'Authorization': self.token,
-
- }
-
- response = requests.post(url, json=data, headers=headers)
- if response.status_code > 300:
- print('Api.push_face.result:', response.status_code)
- print('Api.push_face.detail:', response.text)
- methods.debug_log('apis.u3_for_cscec', f"m-395: url -> {url}")
- methods.debug_log('apis.u3_for_cscec', f"m-395: data -> {data}")
- methods.debug_log('apis.u3_for_cscec', f"m-395: result -> {response.status_code}")
- methods.debug_log('apis.u3_for_cscec', f"m-395: detail -> {response.text}")
- return False
- else:
-
-
- return True
- def push_work_info(self, send_at, face_file_link, face_name, prc_id, worker_contractor, worker_type_name, age,
- find_at):
- """
- 添加劳务人员接口(上传农民工接口)
- """
-
-
- url = f"{self.service_url}/worker/userInfo/workerInfo"
- data = [{
- 'equipmentId': self.project_id,
- 'userId': prc_id,
- 'userName': face_name,
- 'userCerd': prc_id,
- 'age': age,
- 'postInfoName': '',
- 'workType': worker_type_name,
- 'labourCompany': worker_contractor,
- 'enterState': '',
- 'enterTime': '',
- 'synTime': find_at,
- 'lastEnterTime': send_at,
- 'faceInfo': face_file_link,
- 'labourSource': str(0),
- }]
-
-
-
-
-
-
-
-
- headers = {
- 'Authorization': self.token,
-
- }
-
- response = requests.post(url, json=data, headers=headers)
- if response.status_code > 300:
-
-
- methods.debug_log('apis.u3_for_cscec', f"m-457: url -> {url}")
- methods.debug_log('apis.u3_for_cscec', f"m-457: data -> {data}")
- methods.debug_log('apis.u3_for_cscec', f"m-457: result -> {response.status_code}")
- methods.debug_log('apis.u3_for_cscec', f"m-457: detail -> {response.text}")
- return False
- else:
-
- return True
- def pull_update_info(self, start_at):
- """
- 获取线上更新数据 todo 定时请求更新本地数据相关的数据
- """
-
-
- url = f"{self.service_url}/worker/userInfo/findUpdateUserByTime"
-
-
- url += f"?queryStartTime={start_at}"
- data = {
-
-
-
- }
- headers = {
- 'Authorization': self.token,
-
- }
- print('Api.pull_update_info.url:', url)
- response = requests.get(url, params=data, headers=headers)
- print('Api.pull_update_info.result:', response.status_code)
- print('Api.pull_update_info:text:', response.json())
- return []
-
-
-
-
-
-
-
-
- def pull_alarm_list(self, create_at):
- """
- 获取告警列表
- """
-
-
-
- url = f"{self.service_url}/worker/alarm/alarmPageList"
- url += f"?createTime={create_at}"
- params = {
-
- }
- headers = {
- 'Authorization': self.token,
-
- }
- print('Api.pull_alarm_list.url:', url)
- response = requests.get(url, params=params, headers=headers)
- if response.status_code > 300:
- print('Api.pull_alarm_list.result:', response.status_code)
- print('Api.pull_alarm_list.detail:', response.text)
- return {}
- else:
- print('Api.pull_alarm_list.result:', response.status_code)
- return response.json()
- def pull_alarm_group_list(self, create_at):
- """
- 获取报警分组列表
- return [
- {
- ALARM_GROUP_STRATEGY_IDS: 1 现场屏显报警 2 现场语音报警 3 微信报警
- }
- ]
- """
-
-
- url = f"{self.service_url}/worker/alarm/alarmGroupList"
- params = {
- 'projectId': self.project_id,
- 'createTime': create_at,
- }
- headers = {
- 'Authorization': self.token,
-
- }
- print('Api.pull_alarm_group_list.url:', url)
- response = requests.get(url, params=params, headers=headers)
- if response.status_code > 300:
- print('Api.pull_alarm_group_list.result:', response.status_code)
- print('Api.pull_alarm_group_list.detail:', response.text)
- return []
- else:
- print('Api.pull_alarm_group_list.result:', response.status_code)
- return response.json()
- def push_message(self):
- """
- 推送微信消息
- {'ALARM_TYPE': 1, 'ALARM_USER_ID': 'f6bae517-0a28-429c-b65b-b16548ab2ca4', 'ALARM_GROUP_NAME': '屏显报警',
- 'id': '17ee224382634361bc5b9ef41ce09eb1', 'ALARM_STRATEGY_GROUP_ID': '5e58ed8828c84c779b3cddb0257d6f5f',
- 'ALARM_PROJECT_ID': '63729db2-ea9c-4096-b5d9-3ad0369903c8', 'ALARM_NAME': '刘美琪'}
- {'ALARM_TYPE': 1, 'ALARM_USER_ID': '7a574580-6af1-40af-a3c8-1c0d5aee567b', 'ALARM_GROUP_NAME': '微信报警',
- 'id': '04bb6b4628954b2282b15a3cb2e74ab8', 'ALARM_STRATEGY_GROUP_ID': '0f695744b43447b2b4cbad8dc78389f4',
- 'ALARM_PROJECT_ID': '63729db2-ea9c-4096-b5d9-3ad0369903c8', 'ALARM_NAME': '吴非'}
- 微信推送结果查询接口 worker/alarm/getWxPushState
- 状态 00 未发送 01 发送成功 02 发送失败 03 发送异常
- """
-
-
- url = f"{self.service_url}/worker/alarm/getWxAlarmUser"
- data = {
- 'projectId': self.project_id,
-
- 'groupId': '0f695744b43447b2b4cbad8dc78389f4',
-
- 'userId': '7a574580-6af1-40af-a3c8-1c0d5aee567b',
- }
- print(f"Api.push_message:data: {data}")
- headers = {
- 'Authorization': self.token,
-
- }
- print('Api.push_message.url:', url)
- response = requests.post(url, json=data, headers=headers)
- if response.status_code > 300:
- print('Api.push_message.result:', response.status_code)
- print('Api.push_message.detail:', response.text)
- return {}
- else:
- print('Api.push_message.result:', response.status_code)
- return response.json()
- def check_message_state(self):
- """
- 微信推送结果查询接口 worker/alarm/getWxPushState
- 状态 00 未发送 01 发送成功 02 发送失败 03 发送异常
- """
-
-
- url = f"{self.service_url}/worker/alarm/getWxPushState"
-
- url += f"?wxPushId=77c36ad2-ad35-464b-bf52-6d16fd9c74e0"
- data = {
-
-
- }
- headers = {
- 'Authorization': self.token,
-
- }
- print('Api.check_message_state.url:', url)
-
- response = requests.get(url, headers=headers)
- if response.status_code > 300:
- print('Api.check_message_state.result:', response.status_code)
- print('Api.check_message_state.detail:', response.text)
- return {}
- else:
- print('Api.check_message_state.result:', response.status_code)
-
- return response.text
- def push_state(self):
- """
- 每分钟发送心跳请求接口
- """
-
-
- url = f"{self.service_url}/worker/equipmentMaintain/updateEquStateTime"
- data = {
- 'projectId': self.project_id,
- }
- headers = {
- 'Authorization': self.token,
-
- }
-
- response = requests.post(url, json=data, headers=headers)
- if response.status_code > 300:
- print('Api.push_state.result:', response.status_code)
- print('Api.push_state.detail:', response.text)
- return {}
- else:
-
- return response.json()
- def push_face_log(self, user_id, find_at, face_link=''):
- """
- 上传识别记录
- methods.ts_to_string(item.get('create_at'), '%Y-%m-%d %H:%M:%S')
- """
-
-
- url = f"{self.service_url}/worker/ledger/addLedger"
- data = [{
- 'projectId': self.project_id,
- 'equipmentInfo': self.project_id,
- 'equipmentRecognitionTime': find_at,
- 'userId': user_id,
- 'faceInfo': face_link,
- }]
- headers = {
- 'Authorization': self.token,
-
- }
-
- print('Api.push_face_log.url:', url)
-
- response = requests.post(url, json=data, headers=headers)
- if response.status_code > 300:
-
-
- methods.debug_log('apis.u3_for_cscec', f"m-678: url -> {url}")
- methods.debug_log('apis.u3_for_cscec', f"m-678: data -> {data}")
- methods.debug_log('apis.u3_for_cscec', f"m-678: result -> {response.status_code}")
- methods.debug_log('apis.u3_for_cscec', f"m-678: detail -> {response.text}")
- return False
- else:
- print('Api.push_face_log.result:', response.status_code)
- print('Api.push_face_log.detail:', response.text)
-
-
-
- return True
- if __name__ == '__main__':
-
-
-
- api = Api(project_id='63729db2-ea9c-4096-b5d9-3ad0369903c8',
- project_name='山东省大数据产业基地建设项目施工总承包')
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
|