gpt4 book ai didi

php - 向 Google Cloud PHPMyAdmin 服务器发送 REST 调用不起作用?

转载 作者:IT老高 更新时间:2023-10-28 23:25:28 26 4
gpt4 key购买 nike

我已经成功部署了 phpMyAdmin服务器在 Google Cloud通过关注 link .我在尝试写入在 phpMyAdmin 中创建的数据库时遇到问题。我正在尝试基于新的 Firebase Cloud Messaging 创建通知服务谷歌发布的。

NotificationInstanceService.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();
}

}
}

我在 https://<db link>.appspot.com 上进行了部署,/fcm/register.php 下的文件,如下所示:

注册.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);
}
?>

我很困惑,因为我似乎没有向我的数据库中写入任何名为 users 的内容,我知道我已经在 MySQL 中创建了这些内容。在 phpMyAdmin 上创建的服务器。我知道用户名和密码也已经设置在register.php.有什么方法可以调试我的脚本是否真的进入 PHP 代码?如何调试 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==" }

新的 register.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);
}
?>

NotificationInstanceService.java

新的 POST 请求:

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

最佳答案

我不知道你的问题到底是什么,不清楚。但是既然你问了:有什么方法可以调试我的脚本是否真的进入了 PHP 代码?如何调试 PHP 代码?这是你的答案:

把你的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.java 中检查 OkHttpClient 调用的响应:

...
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());
}
...

关于php - 向 Google Cloud PHPMyAdmin 服务器发送 REST 调用不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39066673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com