使用PHP后端在通知中心注册

使用PHP后端在通知中心注册,php,cordova,azure,push-notification,azure-notificationhub,Php,Cordova,Azure,Push Notification,Azure Notificationhub,对于用户请求,后端必须是PHP,应用程序客户端位于Ionic 2中。基于: 重要 我在php API中创建了此方法: $uri = $this->endpoint . $this->hubPath . "/registrations".NotificationHub::API_VERSION; /* print($uri); */ $ch = curl_init($uri); $token = $this->generateSasToken(

对于用户请求,后端必须是PHP,应用程序客户端位于Ionic 2中。基于:

重要

我在php API中创建了此方法:

    $uri = $this->endpoint . $this->hubPath . "/registrations".NotificationHub::API_VERSION;
    /* print($uri); */
    $ch = curl_init($uri);
    $token = $this->generateSasToken($uri);
    $headers = [
        'Authorization: '. $token,
        'Content-Type: '."application/atom+xml;type=entry;charset=utf-8",
        'x-ms-version: 2015-01',
        'Content-Length: 0'
    ];
    $body = $this->getXmlAndroid($registrationId, $tag);
    print_r($body);
    curl_setopt_array($ch, array(
        CURLOPT_CUSTOMREQUEST => 'POST',
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_SSL_VERIFYPEER => FALSE,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POSTFIELDS => $body
     ));
    $response = curl_exec($ch);
        // Check for errors
    if($response === FALSE){
        print_r(curl_error($ch));
        throw new Exception(curl_error($ch));
    }

    $info = curl_getinfo($ch);
    print_r($info);
    curl_close($ch);
getXmlAndroid方法是带有GCM ID的简单返回xml格式

private function getXmlAndroid($registrationId){
    return '<?xml version="1.0" encoding="utf-8"?>
            <entry xmlns="http://www.w3.org/2005/Atom">
                <content type="application/xml">
                    <GcmRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
                        <GcmRegistrationId>'.$registrationId.'</GcmRegistrationId> 
                    </GcmRegistrationDescription>
                </content>
            </entry>';

 }
问题总是在通知API返回中请求注册方法

[http_code] => 400

其中400表示“无效的请求正文。由于请求格式不正确,无法创建注册。”。我不明白为什么会发生这种情况。

为什么发送内容长度:0头?它可能会导致问题。

是的,这是一个愚蠢的问题,这个标题是不必要的。
[http_code] => 400