2017-11-11 64 views
0

这是代码:pushcrew - 用PHP发送通知卷曲

$title = 'Du hast neue Nachricht'; 
    $message = 'Besuch meine Website'; 
    $url = 'https://www.bla.com'; 
    $subscriberId = 'xxx51a002dec08a1690fcbe6e'; 

    $apiToken = 'xxxe0b282d9c886456de0e294ad'; 

    $curlUrl = 'https://pushcrew.com/api/v1/send/individual/'; 

    //set POST variables 
    $fields = array(
     'title' => $title, 
     'message' => $message, 
     'url' => $url, 
     'subscriber_id' => $subscriberId 
    ); 

    $httpHeadersArray = Array(); 
    $httpHeadersArray[] = 'Authorization: key='.$apiToken; 

    //open connection 
    $ch = curl_init(); 

    //set the url, number of POST vars, POST data 
    curl_setopt($ch, CURLOPT_URL, $curlUrl); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields)); 
    curl_setopt($ch, CURLOPT_HTTPSHEADER, $httpHeadersArray); 

    //execute post 
    $result = curl_exec($ch); 

    $resultArray = json_decode($result, true); 

    if($resultArray['status'] == 'success') { 
     echo $resultArray['request_id']; //ID of Notification Request 
    } 
    else if($resultArray['status'] == 'failure') 
    { 
     echo 'fail'; 
    } 
    else 
    { 
     echo 'dono'; 
    } 

    echo '<pre>'; 
    var_dump($result); 
    echo '</pre>'; 

我也得到:

dono 
string(36) "{"message":"You are not authorized"}" 
控制台并没有其他错误

并没有什么。 apitoken是100%正确的。这里有什么麻烦?我是否必须等到推钉机决定允许我的网站或其他东西?

忽略这一点:我必须添加一些文字来问这个问题..

回答

0

有错字这里:

curl_setopt($ch, CURLOPT_HTTPSHEADER, $httpHeadersArray); 

正确的是

CURLOPT_HTTPHEADER

(不S

+0

终于它的作品谢谢! – user2966167