科罗娜SDK(LUA)如何发送请求给PHP脚本注册一个设备得到通知?脚本、通知、设备、SDK

2023-09-07 01:39:21 作者:赤岸 -

我的工作,需要得到推送通知的应用程序

I am working on an app that requires to get push notifications

我不能让PushWoosh工作(设备登录成功的,但没有用户),所以我选择与配置自己的服务器来发送通知GCM工作。人们

I couldn't get PushWoosh to work (device logged succesful, but there were no subscribers) so the people I'm working with opted for configuring their own server to send notifications to GCM.

PHP的注册code是如下:

The PHP Register code is as follows:

require_once('loader.php');

// return json response
$json = array();

$nameUser  = $_POST["name"];
$nameEmail = $_POST["email"];

// GCM Registration ID got from device
$gcmRegID  = $_POST["regId"];

/**
 * Registering a user device in database
 * Store reg id in users table
 */
if (isset($nameUser)
     && isset($nameEmail)
     && isset($gcmRegID)) {

    // Store user details in db
    $res = storeUser($nameUser, $nameEmail, $gcmRegID);

    $registatoin_ids = array($gcmRegID);
    $message = array("product" => "shirt");

    $result = send_push_notification($registatoin_ids, $message);

    echo $result;
} else {
    // user details not found
}

根据我们从,如果我在本地code写的,我需要做的这得到了PHP的code中的例子:

According to the example that we got the php code from, if I was writing in native code, I would need to do this:

void register(final Context context, String name, String email, final String regId) {
Log.i(Config.TAG, "registering device (regId = " + regId + ")");

String serverUrl = Config.YOUR_SERVER_URL;

Map<String, String> params = new HashMap<String, String>();
params.put("regId", regId);
params.put("name", name);
params.put("email", email);

long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);

// Once GCM returns a registration id, we need to register on our server
// As the server might be down, we will retry it a couple
// times.
for (int i = 1; i <= MAX_ATTEMPTS; i++) {

    Log.d(Config.TAG, "Attempt #" + i + " to register");

    try {
        //Send Broadcast to Show message on screen
        displayMessageOnScreen(context, context.getString(
                R.string.server_registering, i, MAX_ATTEMPTS));

        // Post registration values to web server
        post(serverUrl, params);
         ..........
         ....

我猜电晕相当于后(的serverUrl,则params); network.request(serverURL使用,POST,监听器,则params )我已经尝试用不同的方式送了好几次,但我总是从服务器获取同样的错误。

And I guess Corona's equivalent to post(serverUrl, params); would be network.request(serverURL,"POST",listener,params) Which I've tried to send several times in different ways, but I always get the same error from the server.

[Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice:  Undefined index: name in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 7
[Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice:  Undefined index: email in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 8
[Sun Jun 08 19:36:30 2014] [error] [client 181.55.xxx.xxx] PHP Notice:  Undefined index: regId in /var/www/html/vhosts/vps44.econfe.com/htdocs/app/push/register.php on line 11

我在科罗纳的最后一次尝试是这样的:

My last attempt in Corona was this:

local commands_json  = {
            ["email"] = "test@test",
            ["name"] = system.getInfo("deviceID"),
            ["regId"] = DeviceID
        }

    local post_body = json.encode( commands_json )

    local headers = {}
    headers["Content-Type"] = "application/json"
    headers["Accept-Language"] = "en-US"
    local params = {}
    params.headers = headers
    params.body = post_body
    params.progress = "download"

    network.request ( SERVER_URL, "POST", networkListener, params )

这是我第一次使用互联网服务,我从来没有发送或收到任何东西之前(或者只是一次,很多年前)所以我可以俯瞰很简单的东西,所以任何帮助或建议高度AP preciated。

This is the first time I'm using internet services, I've never sent or recieved anything before (or maybe just once, many years ago) So I could be overlooking something really simple, so any help or suggestion is highly appreciated.

我甚至不知道我是否应该使用此JSON的事情,我已经试过删除它(我不知道如何处理在这种情况下做头),但同样的事情发生,我使用它,因为它在那里的Pushwoosh例如电晕(这又没有工作对我来说)

I don't even know if I should be using this json thing, I've tried removing it (I don't know what to do with the header in that case) but the same thing happens, I'm using it because it was there in the Pushwoosh example for Corona (which, again, didn't work for me)

推荐答案

好了,要发送的信息以不同的形式我偶然发现了解决方案之后。1:我不需要使用JSON编码。2:在短短的符号分隔一根弦所需的变量'和;

Well, after trying to send the information in many different formats I stumbled upon the solution. 1: I needn't use the json encoding. 2: the variables needed to be in just one string separated by the symbol '&'

local headers = {}
        headers["Content-Type"] ="application/x-www-form-urlencoded"
        headers["Accept-Language"] = "en-US"
        local body="name="..system.getInfo("deviceID").."&email=test@test&regId="..DeviceID
        local params = {}
        params.headers = headers
        params.body = body

        network.request ( SERVER_URL, "POST", networkListener, params )