Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

php - Incorrect player_id format in (not a valid UUID)

I'm trying to add an array of players_id to send to push notification to specific mobiles, but I keep getting the error "Incorrect player_id format in include_player_ids (not a valid UUID)"

if ($cons) {
    $dado1 = array();
    $dado2 = array();
    while ($row = sqlsrv_fetch_array($cons, SQLSRV_FETCH_ASSOC)) {

        $dado1 = array(
            $row['funcionarioId']
        );
        array_push($dado2, $dado1);
    }
    //echo json_encode($dado2);
} else {
    $dado2 = array();
    array_push($dado2, $dado1);
    $retornoVazio = array("Retorno" => $dado2);
    EnviaEmailComErro($sql, sqlsrv_errors(), "Consulta_NFCe - ConsultaDados");
    array_push($dado2, array("Success" => "0", "Error" => "1"));
    echo json_encode($retornoVazio);
}

function sendMessage($produto, $mesa, $comanda, $garcom, $dado2)
{
    $content = array(
        "en" => " Gar?om $garcom 
 o pedido: $produto está pronto!
 mesa: $mesa 
 comanda: $comanda",
    );

**That where it should add the IDS**

    $fields = array(
        'app_id' => "***",
        'include_player_ids' => array($dado2),
        'channel_for_external_user_ids' => 'push',
        'data' => array("foo" => "bar"),
        'contents' => $content
    );

    $fields = json_encode($fields);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/notifications");
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8',
        'Authorization: Basic ***'));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    $response = curl_exec($ch);
    curl_close($ch);

    return $response;
}

$response = sendMessage($produto, $mesa, $comanda, $garcom, $dado2);
$return["allresponses"] = $response;
$return = json_encode($return);

the variable $fields print

{"app_id":"***",
"include_player_ids":[
                        [
                            ["2610ec53-"],
                            ["045eac07-"],
                            ["8fb19bd9-"]
                        ]
                    ]"

And $response:

{"errors":["Incorrect player_id format in include_player_ids (not a valid UUID): [["2610ec53-"], ["045eac07-"], ["8fb19bd9-"]]"]}

"The players ID are complete in the code, but I deleted it."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In the if ($cons) { you are pushing all sorts of stuff into arrays, simplify it to

if ($cons) {
    $dado2 = array();
    while ($row = sqlsrv_fetch_array($cons, SQLSRV_FETCH_ASSOC)) {
        $dado2[] = $row['funcionarioId'];
    }
} else {

And in the function make this change

'include_player_ids' => $dado2,

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...