无法通过php发送GCM

时间:2015-06-01 23:52:47

标签: php android google-cloud-messaging

我是php的新手。如果我每次手动更改起始值和结束值,脚本会成功。但是,尝试通过while循环发送时失败并显示此错误:

  

请求实体太大。错误413

GCMSendMessage:

#!/usr/bin/python
print "Content-type: text/html\n"
import cgi
import cgitb
inStream=open('accounts.txt','r')
a=inStream.readlines()
print a

def FStoD():
    d = {}
    formData = cgi.FieldStorage()
    for k in formData.keys():
        d[k] = formData[k].value
    return d
print FStoD()

def list_user():
    L=[]
    for x in a:
        L+=x[0]
    return L

inStream.close()
outStream=open('accounts.csv','w')
def createaccount():
    d=FStoD
    list_users=list_user()
    user = d['user']
    print user
    passw = d['password']
    print passw
    if user in list_users:
        print 'Sorry, this username is already taken'
    else:
        outStream.write(user + ',' + passw + '\n')    
        print  'You have successfully created your account' 
createaccount()

GCMPushMessage.php:

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

include("GCMPushMessage.php");
$new_array= array();

$i = 0; // counter 

$mysqli = mysqli_connect("localhost", "root", "xxx", "xxx");
while ($i < n) //n is the (total registration id's)/1000
{
 $new_array[]   = null;
 $start         = ($i * 1000); 
 $end           = $start + 1000; //GCM Limit of 1000 users per notification
 $queryregid    = "SELECT gcm_regid FROM `gcm_users` WHERE id >$start AND id <=$end";
 $result_select = $mysqli->query($queryregid);
 if ($result_select->num_rows > 0) {
     // output data of each row
     while ($row = $result_select->fetch_assoc()) {
         $new_array[] = $row["gcm_regid"]; // Inside while loop
     }
 }  else {
    echo "0 results";
}

$apiKey = "xxx";
$param1 = "XXX";
$param2 = "AAA";
$param3 = '0';

$gcpm = new GCMPushMessage($apiKey);
$gcpm->setDevices($new_array);

 $response = $gcpm->send($message, array(
     'param1' => $param1,
     'param2' => $param2,
     'param3' => $param3
 ));

 $i = $i + 1; // counter increment
}
print "Response=$response"; 

?>

0 个答案:

没有答案