lambda_logs_refund.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #======================= test =========================#
  2. import requests
  3. import json
  4. game_id=456
  5. user_id=123
  6. url = "http://onlyellow.cstor.cn:18888/launch_refund"
  7. server_logs = "[Server] 2020/06/16 09:52:56 Refund ID: 22f6f61f-d573-4eff-963a-708983317057"
  8. sp_log = server_logs.split(' ', -1)
  9. refund_id = sp_log[5]
  10. # print(refund_id)
  11. data = json.dumps({"user_id":user_id, "game_id":game_id, "refund_id":refund_id})
  12. response = requests.post(url=url, data=data)
  13. print(response)
  14. data_a = {"user_id":user_id, "game_id":game_id, "refund_id":refund_id}
  15. print(type(data_a))
  16. #======================= comp =========================#
  17. import json
  18. import urllib.request
  19. import urllib.parse
  20. import base64
  21. import gzip
  22. # import requests
  23. def lambda_handler(event, context):
  24. #双引号(字符串类型),下面的json.dumps也有双引号,
  25. #int类型,下面的json.dumps没有双引号
  26. game_id=456
  27. user_id=123
  28. url = "http://onlyellow.cstor.cn:18888/launch_refund"
  29. de_content = base64.b64decode(event['awslogs']['data'])
  30. ret = json.loads(gzip.decompress(de_content).decode('utf8'))
  31. log_msg = ret['logEvents'][0]['message']
  32. tup_log = log_msg.split(' ', -1)
  33. if len(tup_log[5]) == 36:
  34. refund_id = tup_log[5]
  35. data = json.dumps({"user_id":user_id, "game_id":game_id, "refund_id":refund_id})
  36. # 注意格式
  37. last_data=bytes(data,encoding='utf-8')
  38. headers = {"Content-Type":'application/json'}
  39. req = urllib.request.Request(url=url, headers=headers, data=last_data)
  40. response = urllib.request.urlopen(req)
  41. print(response.read().decode('utf-8'))
  42. else:
  43. pass