如何用curl注册onesignal?

时间:2019-02-17 15:08:28

标签: curl push onesignal

我不知道为什么js在标记注册方面非常麻烦。有了curl我马上就完成了

$fields = array( 
'app_id' => "xxxxxxxxxxxxxxxxxxxxxxxxxx", 
'language' => "nl", 
'identifier' => "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
'device_type' => "5", 
'device_model' => getOs($_SERVER['HTTP_USER_AGENT']), 
'notification_types' => "1",
'tags' => array("email" => $rr['emailadres']) 
); 

$fields = json_encode($fields); 
//print("\nJSON sent:\n"); 
//print($fields); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://onesignal.com/api/v1/players"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json')); 
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["allresponses"] = $response; 
$return = json_encode( $return); 

好吧,现在我想发送带有curl的推送通知,但是当我使用此代码时:

    public function sendPush($text,$title,$email,$url,$imgUrl)
{

    //echo $text.$title.'-'.$email.'-'.$url.'-'.$imgUrl;
    ini_set('display_errors',0);
error_reporting(E_ALL); 
        $content = array(
            "nl" => ''.$text.''
            );

$filters = array(
    array("field" => "tag", "key" => "email","relation" => "=", "value" => $email),
);


        $fields = array(
            'app_id' => "676e190e-4c85-4de6-9f8c-84dec6fca383",
            'included_segments' => array('All'),
            'headings' => array("nl" => "".$title.""),
            'content_available' => array(true),         
            'contents' => $content,
            'url' => $url,      
            'filters' => array(array("field" => "tag","key" => "email", "value" => "".$email.""))

        );

        $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 OTE3YjliZGYtMmVmNi00NjAyLTgxNmItNDNkOTY2ZWM2OTY2'));
        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;

ini_set('display_errors',0);
error_reporting(E_ALL);         
}

然后我按状态在单信号日志中看到:没有收件人?? 该电子邮件标签存在,因此可以发送吗?

我可以直接将其发送给玩家ID吗?

0 个答案:

没有答案