发送 REST 调用到 Google Cloud PHPMyAdmin Server 不起作用?

我已通过单击此链接成功部署了服务器。我在尝试写入我在phpMyAdmin中创建的数据库时遇到问题。我正在尝试根据Google发布的新内容创建通知服务。phpMyAdminGoogle CloudFirebase Cloud Messaging

通知代理服务.java

public class NotificationInstanceService extends FirebaseInstanceIdService {
    private static final String TAG = "NotificationInstance";

    @Override
    public void onTokenRefresh() {

        //Getting registration token
        String refreshedToken = FirebaseInstanceId.getInstance().getToken();

        //Displaying token on logcat
        Log.d(TAG, "Refreshed token: " + refreshedToken);

        sendRegistrationToServer(refreshedToken);

    }

    private void sendRegistrationToServer(String token) {
        //You can implement this method to store the token on your server
        //Not required for current project
        OkHttpClient client = new OkHttpClient();
        //Create the request body
        RequestBody body = new FormBody.Builder().add("Token", token).build();
        //Know where to send the request to
        Request request = new Request.Builder().url("<db link>.appspot.com/fcm/register.php")
                .post(body)
                .build();
        //Create
        try {
            client.newCall(request).execute();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}

我在 /fcm/register 下部署了一个文件.php它看起来像这样:https://<db link>.appspot.com

注册.php

<?php
    if (isset($_POST["Token"])) {

           $_uv_Token=$_POST["Token"];
           $conn = mysqli_connect("<db link>.appspot.com","root","","fcm") or die("Error connecting");
           $q="INSERT INTO users (Token) VALUES ( '$_uv_Token') "
              ." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';";

      mysqli_query($conn,$q) or die(mysqli_error($conn));
      mysqli_close($conn);
    }
 ?>

我很困惑,因为我似乎没有向我的数据库写入任何东西,称为用户,我知道我已经在phpMyAdmin上创建的服务器中创建。我知道用户名和密码也已经设置在 有没有办法调试我的脚本是否实际进入PHP代码?如何调试 PHP 代码?我还说,请求实际上是在构建中,因为我可以通过该部分代码进行调试。任何帮助将不胜感激。谢谢!MySQLregister.php.

编辑:我在尝试部署服务器时创建的一些可能有用的文件:

app.yaml:

application: <app server url>
service: default
runtime: php55
api_version: 1
version: alpha-001

handlers:

- url: /(.+\.(ico|jpg|png|gif))$
  static_files: \1
  upload: (.+\.(ico|jpg|png|gif))$
  application_readable: true

- url: /(.+\.(htm|html|css|js))$
  static_files: \1
  upload: (.+\.(htm|html|css|js))$
  application_readable: true

- url: /(.+\.php)$
  script: \1
  login: admin

- url: /.*
  script: index.php
  login: admin

- url: /.*
  script: register.php
  login: admin

config.inc.php:

<?php 
$cfg['blowfish_secret'] = '<Secret>'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

/*
 * Servers configuration
 */
$i = 0;

// Change this to use the project and instance that you've created.
$host = '/cloudsql/<app server url>:us-central1:<database name>-app-php';
$type = 'socket';

/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['socket'] = $host;
$cfg['Servers'][$i]['connect_type'] = $type;
$cfg['Servers'][$i]['compress'] = false;
/* Select mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
/*
 * End of servers configuration
 */

/*
 * Directories for saving/loading files from server
 */
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';

$cfg['PmaNoRelation_DisableWarning'] = true;
$cfg['ExecTimeLimit'] = 60;
$cfg['CheckConfigurationPermissions'] = false;
// [END all]

php.ini:

google_app_engine.enable_functions = "php_uname, getmypid"

编辑:在浏览器中时的文本,转到.appspot.com/fcm/register.php

array(11) { [“pmaCookieVer”]=> string(1) “5” [“pma_lang”]=> string(2) “en” [“pma_collation_connection”]=> string(15) “utf8_unicode_ci” [“pma_console_height”]=> string(2) “92” [“SACSID”]=> string(355) “~AJKiYcFgym76QZfbMX35ddCTdKKf-O7q5koLvNZ0coWTMvw9aNlR5fusNyLRzFyw5DB_t2ygVuTEjHwgrgBco4-wr_V3Eer_Mf0CDuGX2e4IpirCNeiGxkRvaLgRPPyZNZWKUx1mF_DChjsksTirkY5WCzlA3G3MO9bBScrLw8kNOFGnvzkev3-B2x31s_TmnDN5aJ0G3-nPueI4FPpKaaMlPsITziccvXMpiehglQOKoo1Bol3EZSF1tjI9QoJuc-6X_sHgJ0IEppg7K-cBapaEx5CmDD2kWOggnVPWnGj1SiKFUnE3DZD46bjovf5me7IdwfVX22bv5D2PJDPQEN4m3D7yP3-Wdg” [“pma_console_config”]=> string(103) “{”alwaysExpand“:false,”startHistory“:false,”currentQuery“:true,”enterExecutes“:false,”darkTheme“:false}” [“pma_console_mode”]=> string(4) “show” [“phpMyAdmin”]=> string(40) “cfd814e10982d138c7ed4a3ef510c454c0e5f9b9” [“pma_iv-1”]=> string(24) “bSPnJOOBe5x0iXPbbU5Nww==” [“pmaUser-1”]=> string(24) “oHSLKZ7q6eOaXJ475Q6tzw==” [“pmaPass-1”]=> string(24) “dwKZ9gQPCoe/Uk4sWS4s2g==” }

新寄存器.php:

<?php
    if (isset($_REQUEST["Token"])) {

           $_uv_Token=$_REQUEST["Token"];
           $conn = mysqli_connect("/cloudsql/<Database ServerURL>","root","","FCM") or die("Error connecting");
           $q="INSERT INTO users (Token) VALUES ( '$_uv_Token') "
              ." ON DUPLICATE KEY UPDATE Token = '$_uv_Token';";
      var_dump(mysqli_query($conn,$q));
      mysqli_query($conn,$q) or die(mysqli_error($conn));
      mysqli_close($conn);
    } else {
        var_dump($_REQUEST);
    }
 ?>

通知代理服务.java

新的开机自检请求:

    Request request = new Request.Builder().url("<Application Server>/fcm/register.php?Token=123")
            .post(body)
            .build();

答案 1

我不知道你的问题到底是什么,不清楚。但既然你问了:这是你的答案:Is there any way I can debug whether or not my script is actually going into the PHP code? How can I debug the PHP code?

将 php 代码更改为:

<?php
    if (isset($_POST["Token"])) {

           $_uv_Token=$_POST["Token"];
           $conn = mysqli_connect("<db link>.appspot.com","root","","fcm") or die("Error connecting");
           $q="INSERT INTO users (`Token`) VALUES ( `{$_uv_Token}`) "
              ." ON DUPLICATE KEY UPDATE `Token` = `{$_uv_Token}`;";

      mysqli_query($conn,$q) or die(mysqli_error($conn));
      mysqli_close($conn);
    } else {
        echo "Token is not set!";
    }
?>

然后在检查呼叫的响应:NotificationInstanceService.javaOkHttpClient

...
    try {
        Response response = client.newCall(request).execute();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (!response.isSuccessful()){
        Log.w(TAG, "Unexpected response"+response.toString());
    } else {
        Log.w(TAG, "response: "+response.body().string());
    }
...

答案 2

推荐