Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/198.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
401使用php向android设备发送推送消息时出错_Php_Android_Push Notification - Fatal编程技术网

401使用php向android设备发送推送消息时出错

401使用php向android设备发送推送消息时出错,php,android,push-notification,Php,Android,Push Notification,我正在使用fallowing代码使用php发送推送消息这里是我的代码 <?php if($_POST['message']) { $username ="email address"; $password = "password"; $source="Koti-Link-8"; $service="ac2dm"; $post_params = array ( "Email" => $username, "Passwd" => $password, "accountType"=

我正在使用fallowing代码使用php发送推送消息这里是我的代码

<?php
if($_POST['message'])
{

$username ="email address";
$password = "password";
$source="Koti-Link-8";
$service="ac2dm";
$post_params = array ( "Email" => $username, "Passwd" => $password, "accountType"=>"HOSTED_OR_GOOGLE", "source" => $source, "service"=>$service ); 

$first = true;
            $data_msg = "";

            foreach ($post_params as $key => $value) {
            if ($first)
              $first = false;
            else
              $data_msg .= "&";

            $data_msg .= urlencode($key) ."=". urlencode($value);
            }

            $x = curl_init("https://www.google.com/accounts/ClientLogin"); 

            curl_setopt($x, CURLOPT_HEADER, 1);
            curl_setopt($x, CURLOPT_POST, 1);
            curl_setopt($x, CURLOPT_POSTFIELDS, $data_msg);
            curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);
            $response = curl_exec($x);
            curl_close($x); 

            echo $response;
$pos = strpos($response, "Auth=");
$authKey = trim(substr($response, 5+$pos));

$message=$_POST['message'];


$deviceToken="APA91bEuHNZyyPpczB4NJL-kXitE9-vTti6za3o7x9tA7AjzJIUagHBYteXFUSgcoubrUmg8vVmnLn07XuAzJtgsIs74Q-T33-Vmvo-08C_mh2BMCfr1m5I0rrixT0ymywa3bkqFQEo3KhapTq6Okevvs3ZzoOUGTg";
$col_key=date('Y-m-d H:i:s');
$data = array(
'registration_id' => $deviceToken,
'collapse_key' => 'ck_' .$col_key,
'data.message' => $message,
'data.title' =>'Requestec Push Demo');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://android.apis.google.com/c2dm/send");
echo 'Content-Length:'.strlen($data);
    $headers = array('Authorization: GoogleLogin auth=' . $authKey);
                                        if($headers){
                                            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
                                        }
                                        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
                                        curl_setopt($ch, CURLOPT_POST, true);
                                        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

                                        $messagedata = curl_exec($ch);
                                        echo $messagedata."<br>";
                                        $success="Sent Successfully";
                                        curl_close($ch);

}

?>


但是,当使用它时,会显示来自c2dm服务器的401错误消息问题在哪里以及如何解决。请帮助我401它表示未经授权。未获取访客的输入数据。 您必须检查发送服务器的所有标头。可能是出了什么问题