0
我想在SQL數據庫中存儲Firebase reg令牌,該令牌顯示在日誌中,但不會發送到數據庫。在SQL服務器中存儲FCM註冊令牌
這裏是我的 「FirebaseInstanceIdService」 類:
public class FirebaseInstanceIDService extends FirebaseInstanceIdService {
@Override
public void onTokenRefresh() {
String token = FirebaseInstanceId.getInstance().getToken();
Log.d("REG_TOKEN",token);
sendToken(token);
}
private void sendToken(String token) {
OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder()
.add("Token",token)
.build();
Request request = new Request.Builder()
.url("http://192.168.1.6/fcm/addtoken.php")
.post(body)
.build();
try {
client.newCall(request).execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}
這是PHP腳本:
<?php
if (isset($_POST["Token"])) {
$token=$_POST["Token"];
$conn = mysqli_connect("localhost","root","","fcm");
$q="INSERT INTO users (Token) Values ('$token') ON DUPLICATE KEY UPDATE Token = '$token';";
mysqli_query($conn,$q) or die(mysqli_error($conn));
mysqli_close($conn);
}
得到任何幫助。
您是否首先在瀏覽器上檢查過您的PHP腳本? –