[Solved] Create Registration Notification Hub Azure PHP


# build uri
    $uri = $this->endpoint . $this->hubPath . "/registrations" . NotificationHub::API_NEW_VERSION;
    $ch = curl_init();

    $token = $this->generateSasToken($uri);

    $headers = [
        'Authorization: '. $token,
        'Content-Type: application/xml',
        'x-ms-version: 2015-01'
    ];

    $request_body = self::requestBodyRegistration($device_type, $tagsOrTagExpression, $device_code );

    if( is_null( $request_body ) )
    {
        return null;
    }

    curl_setopt_array($ch, array(
        CURLOPT_URL => $uri,
        CURLOPT_POST => TRUE,
        CURLOPT_RETURNTRANSFER => TRUE,
        CURLOPT_SSL_VERIFYPEER => FALSE,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_POSTFIELDS => $request_body
    ));

    // Send the request
    $response = curl_exec($ch);

    // Check for errors
    if($response === FALSE){
        throw new Exception(curl_error($ch));
    }

    $info = curl_getinfo($ch);
    curl_close($ch);

private function requestBodyRegistration($device_type, $tagsOrTagExpression, $device_code )
{
    switch ($device_type) {
        case 'apple':
            return '<?xml version="1.0" encoding="utf-8"?>
                        <entry xmlns="http://www.w3.org/2005/Atom">
                            <content type="application/xml">
                                <AppleRegistrationDescription xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
                                    <Tags>'. $tagsOrTagExpression .'</Tags>
                                    <DeviceToken>'. $device_code .'</DeviceToken>
                                </AppleRegistrationDescription>
                            </content>
                        </entry>';
        case 'gcm':
            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">
                                                <Tags>'. $tagsOrTagExpression .'</Tags>
                                                <GcmRegistrationId>'. $device_code .'</GcmRegistrationId>
                                        </GcmRegistrationDescription>
                                    </content>
                                </entry>';
        default:
            return null;
    }
}

solved Create Registration Notification Hub Azure PHP