http_client.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import uuid
  2. import requests
  3. import json
  4. from datetime import datetime
  5. import message_pb2 as message
  6. import hashlib
  7. class HttpRequest(object):
  8. class InDate:
  9. def __init__(self, ParkId, PlateNo, dataTime, chnnId, Remake, licenseColorDict, InPicUrl, InPlateUrl,
  10. InRecordId):
  11. '''
  12. :param ParkId: 场ID
  13. :param PlateNo:车牌号
  14. :param dataTime:入场时间
  15. :param chnnId:通道ID
  16. :param Remake:备注
  17. :param licenseColorDict:车牌颜色
  18. :param InPicUrl:入场图片
  19. :param InPlateUrl:入场车牌特写图片
  20. :param InRecordId:入场流水号(唯一码)
  21. '''
  22. self.ParkId = ParkId
  23. self.PlateNo = PlateNo
  24. self.dateTime = dataTime
  25. self.chnnId = chnnId
  26. self.Remake = Remake
  27. self.licenseColorDict = licenseColorDict
  28. self.InPicUrl = InPicUrl
  29. self.InPlateUrl = InPlateUrl
  30. self.InRecordId = InRecordId
  31. class QueryData:
  32. def __init__(self, SerialNumber, ParkId):
  33. '''
  34. :param SerialNumber: 入场流水号(唯一码)
  35. :param ParkId:场ID
  36. '''
  37. self.SerialNumber = SerialNumber
  38. self.ParkId = ParkId
  39. class OutDate:
  40. def __init__(self, ParkId, PlateNo,InRecordId, dateTime, chnnId, Remake, licenseColorDict, OutPicUrl, OutPlateUrl):
  41. '''
  42. :param ParkId: 场ID
  43. :param PlateNo:车牌号
  44. :param InRecordId:入场流水号(唯一码)
  45. :param dateTime:入场时间
  46. :param chnnId:通道ID
  47. :param Remake:备注
  48. :param licenseColorDict:车牌颜色
  49. :param OutPicUrl: 出场图片
  50. :param OutPlateUrl:出场车牌特写图片
  51. '''
  52. self.ParkId = ParkId
  53. self.PlateNo = PlateNo
  54. self.InRecordId = InRecordId
  55. self.dateTime = dateTime
  56. self.chnnId = chnnId
  57. self.Remake = Remake
  58. self.licenseColorDict = licenseColorDict
  59. self.OutPicUrl = OutPicUrl
  60. self.OutPlateUrl = OutPlateUrl
  61. def __init__(self, msgId, AppId, time, sign, data):
  62. '''
  63. :param msgId: 消息ID,随机值
  64. :param AppId: AppId
  65. :param time: 时间
  66. :param sign:签名(msgId+AppId+time+私钥)进行md5小写
  67. :param data:数据结构体
  68. '''
  69. self.msgId = msgId
  70. self.AppId = AppId
  71. self.time = time
  72. self.sign = sign
  73. self.data = data.__dict__
  74. def get_request_data(park_table, param):
  75. hl = hashlib.md5()
  76. msgId = str(uuid.uuid1()) + '@' + park_table.car_number
  77. AppId = 'blbc5zkpyymaicd3'
  78. time = str(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  79. sign = msgId + AppId + time+'anzs74aph8ac8dy6tj48t05js6zpkgx5'
  80. hl.update(sign.encode(encoding='utf-8'))
  81. sign = hl.hexdigest()
  82. if param == 'in':
  83. data = HttpRequest.InDate("2302221444266172014", park_table.car_number,
  84. str(datetime.now().strftime('%Y-%m-%d')),
  85. '2302221446265822050',
  86. park_table.car_number_info.plate_type,
  87. '1',
  88. park_table.car_number_info.plate_full_image,
  89. park_table.car_number_info.plate_clip_image, park_table.primary_key)
  90. elif param == 'query':
  91. data = HttpRequest.QueryData(park_table.primary_key, "2302221444266172014")
  92. elif param == 'out':
  93. data = HttpRequest.OutDate("2302221444266172014", park_table.car_number,
  94. park_table.primary_key,
  95. str(datetime.now().strftime('%Y-%m-%d')),
  96. '2302221729013462154',
  97. park_table.car_number_info.plate_type,
  98. '1',
  99. park_table.car_number_info.plate_full_image,
  100. park_table.car_number_info.plate_clip_image)
  101. request = HttpRequest(msgId, AppId, time,sign, data)
  102. return request.__dict__
  103. # http_park_request = {"msgId": "12345678901234567890123456789012@鄂A12345$park", # 32位唯一码 @ 车牌号 $ park
  104. # "AppId": "z5OZfJ83faYnpaL65FIRfEwLrST2y26f", # 固定值,收费系统制定
  105. # "time": "2023-02-10 17:33:30", # 入场时间,年-月-日 时:分:秒
  106. # "sign": "cdb34f24cf941e495e9467171341f3f3", # 签名 (msgid + appid + time + 秘钥)转MD5 小写
  107. # "data": {"SerialNumber": "20220210155926DA54SD4A5SD4DDD", # 32位唯一码, 存车 取车 查询 保持一致
  108. # "ParkId": "1000000000000000001", # 固定值,收费系统制定
  109. # "PlateNo": "闽D10001", # 车牌号,
  110. # "dateTime": "2023-02-07", # 入场时间,年-月-日 时:分:秒
  111. # "chnnId": "C1-1", # C1单元1号入口
  112. # "Remake": "", # 暂时不写,备注
  113. # "licenseColorDict": "", # 暂时不写, 车牌颜色
  114. # "InPicUrl": "", # 暂时不写,入场图片
  115. # "InPlateUrl": "" # 暂时不写,车牌图片特写
  116. # }
  117. # }
  118. # http_query_request = {
  119. # "msgId": "12321431232324353233123",
  120. # "AppId": "z5OZfJ83faYnpaL65FIRfEwLrST2y26f",
  121. # "parkId": "281219316345475072",
  122. # "time": "2023-02-10 09:05:00",
  123. # "sign": "cdb34f24cf941e495e9467171341f3f3",
  124. # "data": {"SerialNumber": "20220210155926DA54SD4A5SD4DDD",
  125. # "ParkId": "1000000000000000001"
  126. # }
  127. # }
  128. #
  129. # http_park_response = {
  130. # "Message": "入场成功",
  131. # "Tag": 1
  132. # }
  133. if __name__ == "__main__":
  134. in_url = 'http://110.80.15.100:9030/Api/CarInEntry'
  135. query_url = 'http://110.80.15.100:9030/Api/GetBill'
  136. out_url = 'http://110.80.15.100:9030/Api/CarOutEntry'
  137. park_table = message.park_table()
  138. park_table.car_number = '鄂A00003'
  139. park_table.unit_id = 31
  140. park_table.import_id = 1
  141. park_table.primary_key = '20230210155926DA54SD4A5SD4DDD'
  142. park_table.car_number_info.plate_color = '蓝色'
  143. park_table.car_number_info.plate_type = '蓝牌小汽车'
  144. park_table.car_number_info.plate_full_image = ''
  145. park_table.car_number_info.plate_clip_image = ''
  146. request = get_request_data(park_table,'in')
  147. print('发送入场请求:')
  148. print(request)
  149. try:
  150. resp = requests.post(in_url, json=request).json()
  151. print('接收入场反馈:')
  152. print(resp)
  153. print('\n')
  154. except Exception as e:
  155. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  156. request = get_request_data(park_table,'query')
  157. print('发送查询账单请求:')
  158. print(request)
  159. try:
  160. resp = requests.post(query_url, json=request).json()
  161. print('接收查询账单反馈:')
  162. print(resp)
  163. print('\n')
  164. except Exception as e:
  165. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  166. request = get_request_data(park_table,'out')
  167. print('发送出场请求:')
  168. print(request)
  169. try:
  170. resp = requests.post(out_url, json=request).json()
  171. print('接收出场反馈:')
  172. print(resp)
  173. except Exception as e:
  174. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  175. # dict = {'kw': 'hello'}
  176. # try:
  177. # resp = requests.post('https://fanyi.baidu.com/sug', data=dict)
  178. # print(resp)
  179. # except Exception as e:
  180. # print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  181. # print(resp)
  182. # p_request.InRequest(msgId="12345678901234567890123456789012@鄂A12345$park",
  183. # AppId="z5OZfJ83faYnpaL65FIRfEwLrST2y26f", sign="cdb34f24cf941e495e9467171341f3f3",
  184. # SerialNumber="20220210155926DA54SD4A5SD4DDD", ParkId="1000000000000000001",
  185. # PlateNo="闽D10001", chnnId="C1-1")
  186. #
  187. # res = p_client.send_request(p_request)
  188. # if res is False:
  189. # print('请求失败!')
  190. '''
  191. word = input("输入您要翻译的单词:")
  192. url = "https://fanyi.baidu.com/sug" # 百度翻译接口
  193. dict = {"kw": word}
  194. # 发送的数据必须放到字典中,通过data发送
  195. resp = requests.post(url, data=dict)
  196. print(resp)
  197. print(resp.json()) # 将服务器返回的内容直接处理成json数据格式
  198. print(resp.text)
  199. print('---------------------------------------------')
  200. json_str = resp.json()
  201. print(json_str)
  202. python_str1 = json.dumps(json_str)
  203. print(python_str1)
  204. python_str2 = json.loads(python_str1)
  205. print(python_str2)
  206. '''
  207. '''
  208. url = 'http:#127.0.0.1:8099/Api/CarInEntry'
  209. postdata = http_park_request
  210. resp = requests.post(url, data=postdata)
  211. print(resp)
  212. print(resp.json()) #将服务器返回的内容直接处理成json数据格式
  213. print(resp.text)
  214. print('---------------------------------------------')
  215. json_dict = resp.json()
  216. print(json_dict)
  217. python_str1 = json.dumps(json_str)
  218. print(python_str1)
  219. python_str2 = json.loads(python_str1)
  220. print(python_str2)
  221. print('---------------------------------------------')
  222. if 'Message' in json_str.keys():
  223. response_message = json_str['Message']
  224. print(response_message)
  225. else:
  226. response_message = ''
  227. if 'Tag' in json_str.keys():
  228. response_tag = json_str['Tag']
  229. print(response_tag)
  230. else:
  231. response_tag = 0
  232. '''