0

estoy intentando enviar una notificacion via onesignal cuando accedo al archivo json, pero me proboca errores alguien puede ayudarme?

por ejemplo ese php lo que hace es enviar la orden de una app al servidor pero al momento de implementar la notificacion onesignal para q llegue notificacion cuando uno hace un pedido no devuelve el resultado esperado, q en este caso provoca q no se limpie el carrito de compras una vez se haya echo la peticion, pero cuando quito el codigo normal se borra, no se mucho de php, de echo casi nada :(((

:(((

    <?php 
require 'db.php';
$data = json_decode(file_get_contents('php://input'), true);
if($data['uid'] == '')
{
 $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");    
}
else
{
    
$uid =  $data['uid'];
$ddate = $data['ddate'];
$a = explode('/',$ddate);
$ddate = $a[2].'-'.$a[1].'-'.$a[0];
$timesloat = $data['timesloat'];
$oid ='#'.uniqid();
$pname = $data['pname'];
$status = 'pending';
$p_method = $data['p_method'];
$address_id = $data['address_id'];
$tax = $data['tax'];
$timestamp = date("Y-m-d");
$tid = $data['tid'];
$total = $data['total'];
$e= array();
$p = array();
$w=array();
$pp = array();
$q = array();
for($i=0;$i<count($pname);$i++)
{
$e[] = $pname[$i]['title'];
$p[] = $pname[$i]['pid'];
$w[] = $pname[$i]['weight'];
$pp[] = $pname[$i]['cost'];
$q[] = $pname[$i]['qty'];
}
$pname = implode('$;',$e);
$pid = implode('$;',$p);
$ptype = implode('$;',$w);
$pprice = implode('$;',$pp);
$qty = implode('$;',$q);

$con->query("insert into orders(`oid`,`uid`,`pname`,`pid`,`ptype`,`pprice`,`ddate`,`timesloat`,`order_date`,`status`,`qty`,`total`,`p_method`,`address_id`,`tax`,`tid`)values('".$oid."',".$uid.",'".$pname."','".$pid."','".$ptype."','".$pprice."','".$ddate."','".$timesloat."','".$timestamp."','".$status."','".$qty."',".$total.",'".$p_method."',".$address_id.",".$tax.",'".$tid."')");
$returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Order Place Successfully!!!");




}

echo json_encode($returnArr);


//enviar notificacion onesignal a negocio

function sendMessage() {
    $content      = array(
        "en" => 'Nueva Orden Pendiente'
    );

    //$hashes_array = array();
    //array_push($hashes_array, array(
        //"id" => "like-button",
        //"text" => "Like",
        //"icon" => "http://i.imgur.com/N8SN8ZS.png",
        //"url" => ADMIN_PANEL
    //));
    //array_push($hashes_array, array(
        //"id" => "like-button-2",
        //"text" => "Ver",
        //"icon" => "http://i.imgur.com/N8SN8ZS.png",
        //"url" => ADMIN_PANEL
    //));

    
    $fields = array(
        'app_id' => ID_ONESIGNAL,
        'included_segments' => array(
            'All'
        ),
        'data' => array(
            "foo" => "bar"
        ),
        'contents' => $content,
        //'web_buttons' => $hashes_array
    );
    
    $fields = json_encode($fields);
    print("\nJSON sent:\n");
    print($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 '.PASSWORD_ONESIGNAL.''
    ));
    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;
}

// FIN enviar notificacion onesignal a negocio




//  enviar notificacion onesignal a negocio

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

$data = json_decode($response, true);
print_r($data);
$id = $data['id'];
print_r($id);

print("\n\nJSON received:\n");
print($return);
print("\n");



// FIN enviar notificacion onesignal a negocio

1 respuesta 1

0

gracias logre resolverlo de la siguiente manera :´v

<?php 
require 'db.php';

//include_once 'notifionesignalorder.php';



$data = json_decode(file_get_contents('php://input'), true);
if($data['uid'] == '')
{
 $returnArr = array("ResponseCode"=>"401","Result"=>"false","ResponseMsg"=>"Something Went Wrong!");    
}
else
{
    
$uid =  $data['uid'];
$ddate = $data['ddate'];
$a = explode('/',$ddate);
$ddate = $a[2].'-'.$a[1].'-'.$a[0];
$timesloat = $data['timesloat'];
$oid ='#'.uniqid();
$pname = $data['pname'];
$status = 'pending';
$p_method = $data['p_method'];
$address_id = $data['address_id'];
$tax = $data['tax'];
$timestamp = date("Y-m-d");
$tid = $data['tid'];
$total = $data['total'];
$e= array();
$p = array();
$w=array();
$pp = array();
$q = array();














for($i=0;$i<count($pname);$i++)
{
$e[] = $pname[$i]['title'];
$p[] = $pname[$i]['pid'];
$w[] = $pname[$i]['weight'];
$pp[] = $pname[$i]['cost'];
$q[] = $pname[$i]['qty'];
}
$pname = implode('$;',$e);
$pid = implode('$;',$p);
$ptype = implode('$;',$w);
$pprice = implode('$;',$pp);
$qty = implode('$;',$q);

$con->query("insert into orders(`oid`,`uid`,`pname`,`pid`,`ptype`,`pprice`,`ddate`,`timesloat`,`order_date`,`status`,`qty`,`total`,`p_method`,`address_id`,`tax`,`tid`)values('".$oid."',".$uid.",'".$pname."','".$pid."','".$ptype."','".$pprice."','".$ddate."','".$timesloat."','".$timestamp."','".$status."','".$qty."',".$total.",'".$p_method."',".$address_id.",".$tax.",'".$tid."')");
$returnArr = array("ResponseCode"=>"200","Result"=>"true","ResponseMsg"=>"Order Place Successfully!!!");


echo json_encode($returnArr);

} 


?>

<?php 
    $fields = array(
        'app_id' => ID_ONESIGNAL,
      
        'included_segments' => array('All'),
        'contents' => array("en" =>"Revise nueva orden"),
        'headings' => array("en"=>"Nueva Orden Pendiente"),
        'large_icon' => 'https://cdn4.iconfinder.com/data/icons/iconsimple-logotypes/512/github-512.png',
    );
    
    $fields = json_encode($fields);
    //print("\nJSON sent:\n");
    //print($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 '.PASSWORD_ONESIGNAL.''
    ));
    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);
   
?>

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.