0

Curl/Python을 사용하여 Chrome 용 Payload로 웹 푸시 알림을 보내는 방법을 설명해 주실 수 있습니까? Python의 암호화 된 페이로드로 Chrome 웹 푸시 알림

내가 노력하고 코드입니다 :

코드 :

fcm_url = "https://fcm.googleapis.com/fcm/send" 
headers = {'Content-Type': 'application/json'}  
headers.update({'Authorization': 'key=' + fcm_key}) 

encoded = {'body': "i\x87\xb7W\xee\xd6QzL\xb6Q\xfe\xf5=t\xc4D[\xfe\xe3+g\xb7\x86\xdd\x81\xb9I\xffX\x99\x9b\x85$x\x80\xc6\x88\xe3\xbcm\x91\xff\x17a\x87C\x81\xf0\xbd\xb3}Y\xc8\xdb:\x14\x02\xf2R\xe7\x12\xcb\x1c\x0f\x13\xca'\xec7B\xc3\x9e\xb2\x17\xa0\xf0\xcd\xed3\xff\x1e\xc9k'A\xfb\x84\xf0\x17\xd4+I\xe0\xe0\x92i%\x00\xf0\xe0\xdb[\xa5\xc9/'\xc3L\xf6a\x183\xc1x7\xa6\x04!\xcctH\xf3\xf3\xcf\xf5\x12r\xd3\xf4\xd4\x8b\x10pc\x84Dd\xee\xe5'\x82\xa8\x81\x9a\xf4\x94\xd3\x12\x166\x91G3t\x08\xf9\xbe\x1b\x90\x02\xc6\x17\x17\xc3\xe9\x08qQK\xd4\xce\xc2\x88\x8f\xcbA\xc9\xfd]\x99\x13\xfd\xa6v2\xd65\x1b\xd5\x82)FUX\x92c\xed\xecF\x91rk\xba\x04\xd2\x90\x93a\n\x96|M}\x10\xc4\xb0\xe4\xdd\x1dd4\xf1\xcb\x06<\xf7\x06\xf9\xfe\xce\x19W\xaa\xc4", 'crypto_key': 'BJUZv_0v3lqIkptS5R4r-DKbVXl4Cpd4YN4ASO4dcNzEGPgtNW7EDF2HBSNGy0fI8kBJj3bnSuCh0bmR46ICKpc', 'salt': 'bjNe7m6zIQeDcsh4TF_wqg'} 

crypto_key = "dh=" + encoded["crypto_key"] 
salt = "salt=" + encoded['salt'] 
headers.update({'crypto-key': crypto_key, 'content-encoding': 'aesgcm', 'encryption': salt})  
fcm_data = {"data": {"message": base64.urlsafe_b64encode(encoded['body'])}, "registration_ids": google_ids_array} 
resp = requests.post(fcm_url, data=json.dumps(fcm_data), headers=headers) 

응답 :

하지만 통지가 위에서 지정한 데이터가 포함되어 있지 않습니다.

케이스는했지만, 유용한 없음 :

1) fcm_data = {"data": {"message": "Hello"}, "to": google_ids_array[0]} # Wrong Notification 
2) fcm_data = {"data": {"message": "Hello"}, "registration_ids": google_ids_array} # Wrong Notification 
3) fcm_data = {"data": {"message": base64.urlsafe_b64encode(encoded['body'])}, "to": google_ids_array[0]} # Wrong Notification 
4) fcm_data = {"data": {"message": base64.urlsafe_b64encode(encoded['body'])}, "registrations_ids": google_ids_array} # Bad Request, to 

5) fcm_data = {"raw_data": "He", "registration_ids": google_ids_array} # success, No Notification 
6) fcm_data = {"raw_data": str({"message": "Hello"}), "registration_ids": google_ids_array} # Failure, MessageTooBig 
7) fcm_data = {"raw_data": base64.urlsafe_b64encode(encoded['body']), "registration_ids": google_ids_array} # Failure, MessageTooBig 

사람이 크롬 브라우저에 페이로드와 올바른 웹 알림을 보내는 방법을 제안하지시겠습니까?

어떤 제안/힌트가 도움이 될 것입니다 ...

감사합니다, 당신이 파이썬 라이브러리를 참조 할 수있는 페이로드를 인코딩

답변

2

작업 코드

fcm_url = "https://fcm.googleapis.com/fcm/send"   
encoded = {'body': "i\x87\xb7W\xee\xd6QzL\xb6Q\xfe\xf5=t\xc4D[\xfe\xe3+g\xb7\x86\xdd\x81\xb9I\xffX\x99\x9b\x85$x\x80\xc6\x88\xe3\xbcm\x91\xff\x17a\x87C\x81\xf0\xbd\xb3}Y\xc8\xdb:\x14\x02\xf2R\xe7\x12\xcb\x1c\x0f\x13\xca'\xec7B\xc3\x9e\xb2\x17\xa0\xf0\xcd\xed3\xff\x1e\xc9k'A\xfb\x84\xf0\x17\xd4+I\xe0\xe0\x92i%\x00\xf0\xe0\xdb[\xa5\xc9/'\xc3L\xf6a\x183\xc1x7\xa6\x04!\xcctH\xf3\xf3\xcf\xf5\x12r\xd3\xf4\xd4\x8b\x10pc\x84Dd\xee\xe5'\x82\xa8\x81\x9a\xf4\x94\xd3\x12\x166\x91G3t\x08\xf9\xbe\x1b\x90\x02\xc6\x17\x17\xc3\xe9\x08qQK\xd4\xce\xc2\x88\x8f\xcbA\xc9\xfd]\x99\x13\xfd\xa6v2\xd65\x1b\xd5\x82)FUX\x92c\xed\xecF\x91rk\xba\x04\xd2\x90\x93a\n\x96|M}\x10\xc4\xb0\xe4\xdd\x1dd4\xf1\xcb\x06<\xf7\x06\xf9\xfe\xce\x19W\xaa\xc4", 'crypto_key': 'BJUZv_0v3lqIkptS5R4r-DKbVXl4Cpd4YN4ASO4dcNzEGPgtNW7EDF2HBSNGy0fI8kBJj3bnSuCh0bmR46ICKpc', 'salt': 'bjNe7m6zIQeDcsh4TF_wqg'} 

crypto_key = "dh=" + encoded["crypto_key"] 
salt = "salt=" + encoded['salt'] 
headers = {'Authorization': 'key=' + fcm_key, 'Content-Type': 'application/json', } 
headers.update({'crypto-key': crypto_key, 'content-encoding': 'aesgcm', 'encryption': salt})  
fcm_data = {"raw_data": base64.b64encode(encoded.get('body')), "registration_ids": google_ids_array} 
resp = requests.post(fcm_url, data=json.dumps(fcm_data), headers=headers) 

: https://github.com/web-push-libs/pywebpush

감사합니다.