Răsfoiți Sursa

rename lambda_logs_refund to lambda_logs_refund.py.

xdc 5 ani în urmă
părinte
comite
5df515595b
1 a modificat fișierele cu 21 adăugiri și 13 ștergeri
  1. 21 13
      lambda_logs_refund.py

+ 21 - 13
lambda_logs_refund → lambda_logs_refund.py

@@ -4,9 +4,9 @@
 import requests
 import json
 
-user_id=715
-game_id=141
-url = "http://onlyellow.cstor.cn:18888/launch_refund"  
+user_id=123
+game_id=456
+url = "http://onlyellow.cstor.cn:18888/launch_refund"
 
 server_logs = "[Server] 2020/06/16 09:52:56 Refund ID: 22f6f61f-d573-4eff-963a-708983317057"
 sp_log = server_logs.split(' ', -1)
@@ -33,19 +33,27 @@ import gzip
 
 def lambda_handler(event, context):
     
-    user_id=**
-    game_id=**
+    #双引号(字符串类型),下面的json.dumps也有双引号,
+    #int类型,下面的json.dumps没有双引号
+    user_id=123
+    game_id=456
     url = "http://onlyellow.cstor.cn:18888/launch_refund"
     
     de_content = base64.b64decode(event['awslogs']['data'])
     ret = json.loads(gzip.decompress(de_content).decode('utf8'))
     log_msg = ret['logEvents'][0]['message']
     tup_log = log_msg.split(' ', -1)
-    refund_id = tup_log[5]
-    # post
-    data = json.dumps({"user_id":user_id, "game_id":game_id, "refund_id":refund_id})
-    last_data=bytes(data,encoding='utf-8')
-    headers = {"Content-Type":'application/json'}
-    req = urllib.request.Request(url=url, headers=headers, data=last_data)
-    response = urllib.request.urlopen(req)
-    print(response.read().decode('utf-8'))
+    if len(tup_log[5]) == 36:
+        refund_id = tup_log[5]
+        data = json.dumps({"user_id":user_id, "game_id":game_id, "refund_id":refund_id})
+        # 注意格式
+        last_data=bytes(data,encoding='utf-8')
+        headers = {"Content-Type":'application/json'}
+        req = urllib.request.Request(url=url, headers=headers, data=last_data)
+        response = urllib.request.urlopen(req)
+        print(response.read().decode('utf-8'))
+    else:
+        pass
+
+
+