不正确的 player_id 格式不是有效的 UUID

问题描述

我正在尝试添加一个players_id数组以发送到特定手机的推送通知,但我一直收到错误“include_player_ids中的player_id格式不正确(不是有效的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 \n o pedido: $produto está pronto!\n mesa: $mesa \n 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,CURLOPT_POSTFIELDS,$fields);
    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);

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

    return $response;
}

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

变量 $fields 打印

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

还有$response

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

代码中的玩家ID是完整的,但我删除了它。”

解决方法

if ($cons) { 中,您将各种内容推入数组,将其简化为

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

并在函数中进行此更改

'include_player_ids' => $dado2,