メルカリさんがGo言語で開発されたプッシュ配信のミドルウェアgaurunでAndroidのPush通知を送るとエラーになります。
curlで実行したコマンドはこちらです。
ssh
1curl -v -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"notifications" : [{"token" : ["APA*******************"],"platform" : 2,"message" : "hello", }]}' http://localhost:1056/push
エラーログに書かれていた内容です。
{"level":"error","time":"2017/06/** **:**:** JST","message":"hello","id":24,"platform":"android","token":"APA*******************","type":"failed-push","ptime":0.05,"error":"invalid status code 401: 401 Invalid (legacy) Server-key delivered or Sender is not authorized to perform request."}
PHPで書くと送れているのでapikeyやレジストレーションIDには問題無いと思っています。
php
1<?php 2$apiKey = "AIza********"; 3$regId = "APA*******************"; 4$url = 'https://android.googleapis.com/gcm/send'; 5$header = array( 6 'Content-Type: application/json', 7 "Authorization: key={$apiKey}", 8); 9$postList = array( 10 'registration_ids' => array($regId), 11); 12$data["text"] = "hello"; 13$postList['data'] = $data; 14$post = json_encode($postList); 15 16$ch = curl_init($url); 17curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 18curl_setopt($ch, CURLOPT_FAILONERROR, 1); 19curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 20curl_setopt($ch, CURLOPT_POST, TRUE); 21curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 22curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 23curl_setopt($ch, CURLOPT_TIMEOUT, 5); 24 25$ret = curl_exec($ch); 26 27print_r($ret); 28exit;
gaurunの設定ファイルのgo/src/github.com/mercari/gaurun/conf/gaurun.tomlはこのようにしています。
[android] apikey = "AIza********" enabled = true timeout = 5 # sec keepalive_timeout = 30 keepalive_conns = 4 retry_max = 1 use_fcm = false
use_fcmをtrueにしても届きませんでした。
iOSは正常に届いているのですが・・・・。
どなたかご存知の方がいらっしゃいましたら教えて頂けませんでしょうか。
何卒宜しくお願い申し上げます。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/26 03:44