http_client.py 9.9 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. #
  83. # if param == 'in':
  84. # data = HttpRequest.InDate("2302221444266172014", park_table.car_number,
  85. # str(datetime.now().strftime('%Y-%m-%d')),
  86. # '2302221446265822050',
  87. # park_table.car_number_info.plate_type,
  88. # '1',
  89. # park_table.car_number_info.plate_full_image,
  90. # park_table.car_number_info.plate_clip_image, park_table.primary_key)
  91. # elif param == 'query':
  92. # data = HttpRequest.QueryData(park_table.primary_key, "2302221444266172014")
  93. # elif param == 'out':
  94. # data = HttpRequest.OutDate("2302221444266172014", park_table.car_number,
  95. # park_table.primary_key,
  96. # str(datetime.now().strftime('%Y-%m-%d')),
  97. # '2302221729013462154',
  98. # park_table.car_number_info.plate_type,
  99. # '1',
  100. # park_table.car_number_info.plate_full_image,
  101. # park_table.car_number_info.plate_clip_image)
  102. #
  103. # request = HttpRequest(msgId, AppId, time,sign, data)
  104. #
  105. # return request.__dict__
  106. #
  107. # http_park_request = {"msgId": "12345678901234567890123456789012@鄂A12345$park", # 32位唯一码 @ 车牌号 $ park
  108. # "AppId": "z5OZfJ83faYnpaL65FIRfEwLrST2y26f", # 固定值,收费系统制定
  109. # "time": "2023-02-10 17:33:30", # 入场时间,年-月-日 时:分:秒
  110. # "sign": "cdb34f24cf941e495e9467171341f3f3", # 签名 (msgid + appid + time + 秘钥)转MD5 小写
  111. # "data": {"SerialNumber": "20220210155926DA54SD4A5SD4DDD", # 32位唯一码, 存车 取车 查询 保持一致
  112. # "ParkId": "1000000000000000001", # 固定值,收费系统制定
  113. # "PlateNo": "闽D10001", # 车牌号,
  114. # "dateTime": "2023-02-07", # 入场时间,年-月-日 时:分:秒
  115. # "chnnId": "C1-1", # C1单元1号入口
  116. # "Remake": "", # 暂时不写,备注
  117. # "licenseColorDict": "", # 暂时不写, 车牌颜色
  118. # "InPicUrl": "", # 暂时不写,入场图片
  119. # "InPlateUrl": "" # 暂时不写,车牌图片特写
  120. # }
  121. # }
  122. # http_query_request = {
  123. # "msgId": "12321431232324353233123",
  124. # "AppId": "z5OZfJ83faYnpaL65FIRfEwLrST2y26f",
  125. # "parkId": "281219316345475072",
  126. # "time": "2023-02-10 09:05:00",
  127. # "sign": "cdb34f24cf941e495e9467171341f3f3",
  128. # "data": {"SerialNumber": "20220210155926DA54SD4A5SD4DDD",
  129. # "ParkId": "1000000000000000001"
  130. # }
  131. # }
  132. #
  133. # http_park_response = {
  134. # "Message": "入场成功",
  135. # "Tag": 1
  136. # }
  137. if __name__ == "__main__":
  138. in_url = 'http://110.80.15.100:9030/Api/CarInEntry'
  139. query_url = 'http://110.80.15.100:9030/Api/GetBill'
  140. out_url = 'http://110.80.15.100:9030/Api/CarOutEntry'
  141. park_table = message.park_table()
  142. park_table.car_number = '鄂A00003'
  143. park_table.unit_id = 31
  144. park_table.import_id = 1
  145. park_table.primary_key = '20230210155926DA54SD4A5SD4DDD'
  146. park_table.car_number_info.plate_color = '蓝色'
  147. park_table.car_number_info.plate_type = '蓝牌小汽车'
  148. park_table.car_number_info.plate_full_image = ''
  149. park_table.car_number_info.plate_clip_image = ''
  150. request = get_request_data(park_table,'in')
  151. print('发送入场请求:')
  152. print(request)
  153. try:
  154. resp = requests.post(in_url, json=request).json()
  155. print('接收入场反馈:')
  156. print(resp)
  157. print('\n')
  158. except Exception as e:
  159. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  160. request = get_request_data(park_table,'query')
  161. print('发送查询账单请求:')
  162. print(request)
  163. try:
  164. resp = requests.post(query_url, json=request).json()
  165. print('接收查询账单反馈:')
  166. print(resp)
  167. print('\n')
  168. except Exception as e:
  169. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  170. request = get_request_data(park_table,'out')
  171. print('发送出场请求:')
  172. print(request)
  173. try:
  174. resp = requests.post(out_url, json=request).json()
  175. print('接收出场反馈:')
  176. print(resp)
  177. except Exception as e:
  178. print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  179. # dict = {'kw': 'hello'}
  180. # try:
  181. # resp = requests.post('https://fanyi.baidu.com/sug', data=dict)
  182. # print(resp)
  183. # except Exception as e:
  184. # print('向收费系统推送请求失败! ERROR:%s' % (str(e.args)))
  185. # print(resp)
  186. # p_request.InRequest(msgId="12345678901234567890123456789012@鄂A12345$park",
  187. # AppId="z5OZfJ83faYnpaL65FIRfEwLrST2y26f", sign="cdb34f24cf941e495e9467171341f3f3",
  188. # SerialNumber="20220210155926DA54SD4A5SD4DDD", ParkId="1000000000000000001",
  189. # PlateNo="闽D10001", chnnId="C1-1")
  190. #
  191. # res = p_client.send_request(p_request)
  192. # if res is False:
  193. # print('请求失败!')
  194. '''
  195. word = input("输入您要翻译的单词:")
  196. url = "https://fanyi.baidu.com/sug" # 百度翻译接口
  197. dict = {"kw": word}
  198. # 发送的数据必须放到字典中,通过data发送
  199. resp = requests.post(url, data=dict)
  200. print(resp)
  201. print(resp.json()) # 将服务器返回的内容直接处理成json数据格式
  202. print(resp.text)
  203. print('---------------------------------------------')
  204. json_str = resp.json()
  205. print(json_str)
  206. python_str1 = json.dumps(json_str)
  207. print(python_str1)
  208. python_str2 = json.loads(python_str1)
  209. print(python_str2)
  210. '''
  211. '''
  212. url = 'http:#127.0.0.1:8099/Api/CarInEntry'
  213. postdata = http_park_request
  214. resp = requests.post(url, data=postdata)
  215. print(resp)
  216. print(resp.json()) #将服务器返回的内容直接处理成json数据格式
  217. print(resp.text)
  218. print('---------------------------------------------')
  219. json_dict = resp.json()
  220. print(json_dict)
  221. python_str1 = json.dumps(json_str)
  222. print(python_str1)
  223. python_str2 = json.loads(python_str1)
  224. print(python_str2)
  225. print('---------------------------------------------')
  226. if 'Message' in json_str.keys():
  227. response_message = json_str['Message']
  228. print(response_message)
  229. else:
  230. response_message = ''
  231. if 'Tag' in json_str.keys():
  232. response_tag = json_str['Tag']
  233. print(response_tag)
  234. else:
  235. response_tag = 0
  236. '''