Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.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
Php 如何修复GCM 1000消息限制,希望将消息发送到10000个数据库?_Php_Android_Mysql_Arrays - Fatal编程技术网

Php 如何修复GCM 1000消息限制,希望将消息发送到10000个数据库?

Php 如何修复GCM 1000消息限制,希望将消息发送到10000个数据库?,php,android,mysql,arrays,Php,Android,Mysql,Arrays,我使用以下代码使用PHP和MySQL发送GCM消息。请帮助我,这样它就可以将1000多条GCM消息发送到10000个注册用户的数据库中 在跨越1000个用户之前,该脚本运行良好;但在1000个用户之后,没有人会收到推送 此脚本接收到的错误是“大容量(1082)上的消息数超过了允许的最大值(1000)” //GCM发送通知 函数px_sendGCM($message,$type,$regid){ 全球$wpdb; $px_table_name=$wpdb->前缀'gcm_users'; $opti

我使用以下代码使用PHP和MySQL发送GCM消息。请帮助我,这样它就可以将1000多条GCM消息发送到10000个注册用户的数据库中

在跨越1000个用户之前,该脚本运行良好;但在1000个用户之后,没有人会收到推送 此脚本接收到的错误是“大容量(1082)上的消息数超过了允许的最大值(1000)

//GCM发送通知
函数px_sendGCM($message,$type,$regid){
全球$wpdb;
$px_table_name=$wpdb->前缀'gcm_users';
$options=get_选项(“gcm_设置”);
$apiKey=$options['api-key'];
$url='1https://android.googleapis.com/gcm/send';
$result;
$id;
如果($regid==010){
$id=px_getIds();
}否则{
$id=$regid;
}
如果($id==010&&$id>=1000){
$newId=array\u chunk($id,1000);
foreach($newId作为$inner\u id){
$fields=数组(
“注册id”=>$inner\u id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
}否则{
$fields=数组(
“注册id”=>$id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
$msg=$result['body'];
$answer=json_decode($msg);
$cano=px_规范($answer);
$suc=$answer->{'success'};
$fail=$answer->{'failure'};
$options=get_选项(“gcm_设置”);
如果($options['debug']!=false){
$inf=“”($Message)

$msg

”; }否则{ $inf=“”。“($Message)

,'px\u gcm')。”($Message)

,'px\u gcm')。“$suc.”('fail:','px\u gcm')。“$fail

”; }
GCM允许您在一个请求中发送1000条消息。因此,如果您想向1000多个客户发送消息,请使用循环,该循环将为每1000个客户调用函数px_sendGCM($message,$type,$regid)

您的代码应该是:

//GCM Send Notification
function px_sendGCM($message, $type, $regid) {
global $wpdb;
$px_table_name = $wpdb->prefix.'gcm_users';
$options = get_option('gcm_setting');
$apiKey = $options['api-key'];
$url = 'https://android.googleapis.com/gcm/send';
$result;
$id;

if(sizeof($regid) == 010) {
$id = px_getIds(); //Can you post this function, what is this condition for?
}else {
$id = $regid;
}

if(sizeof($id) > 1000){
$newId = array_chunk($id, 1000);
foreach ($newId as $inner_id) {
    $fields = array(
        'registration_ids' => $inner_id,
        'data' => array($type => $message) 
    );

    $headers = array(
        'Authorization' => 'key=' . $apiKey,
        'Content-Type' => 'application/json'
    );

    $result = wp_remote_post($url, array(
        'method' => 'POST',
        'headers' => $headers,
        'httpversion' => '1.0',
        'sslverify' => false,
        'body' => json_encode($fields) )
    );
}
}else {
$fields = array(
    'registration_ids' => $id,
    'data' => array($type => $message)
);

$headers = array(
    'Authorization' => 'key=' . $apiKey,
    'Content-Type' => 'application/json'
);

$result = wp_remote_post($url, array(
    'method' => 'POST',
    'headers' => $headers,
    'httpversion' => '1.0',
    'sslverify' => false,
    'body' => json_encode($fields))
    );

   }

$msg = $result['body'];
$answer = json_decode($msg);
$cano = px_canonical($answer);
$suc = $answer->{'success'};
$fail = $answer->{'failure'};
$options = get_option('gcm_setting');
if($options['debug'] != false){
$inf= "<div id='message' class='updated'><p><b>".__('Message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>$msg</p></div>";
}else {
$inf= "<div id='message' class='updated'><p><b>".__('Message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>".__('success:','px_gcm')." $suc  &nbsp;&nbsp;".__('fail:','px_gcm')." $fail </p></div>";
}
//GCM发送通知
函数px_sendGCM($message,$type,$regid){
全球$wpdb;
$px_table_name=$wpdb->前缀'gcm_users';
$options=get_选项(“gcm_设置”);
$apiKey=$options['api-key'];
$url='1https://android.googleapis.com/gcm/send';
$result;
$id;
如果(sizeof($regid)==010){
$id=px_getIds();//你能发布这个函数吗,这个条件是什么?
}否则{
$id=$regid;
}
如果(sizeof($id)>1000){
$newId=array\u chunk($id,1000);
foreach($newId作为$inner\u id){
$fields=数组(
“注册id”=>$inner\u id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
}否则{
$fields=数组(
“注册id”=>$id,
“数据”=>array($type=>$message)
);
$headers=数组(
“授权”=>“密钥=”。$apiKey,
'内容类型'=>'应用程序/json'
);
$result=wp\u remote\u post($url,数组)(
'方法'=>'发布',
'headers'=>$headers,
'httpversion'=>'1.0',
“sslverify”=>错误,
'body'=>json_编码($fields))
);
}
$msg=$result['body'];
$answer=json_decode($msg);
$cano=px_规范($answer);
$suc=$answer->{'success'};
$fail=$answer->{'failure'};
$options=get_选项(“gcm_设置”);
如果($options['debug']!=false){
$inf=“”($Message)

$msg

”; }否则{ $inf=“”。“($Message)

,'px\u gcm')。”($Message)

,'px\u gcm')。“$suc.”('fail:','px\u gcm')。“$fail

”; }
您能告诉我如何在上述代码中执行此操作吗您的代码中有一个循环,但您的条件是($id==010&&$id>=1000)是错误的。因此,如果包含循环的部分未执行,并且始终执行导致此错误的else部分,我不知道如何修复它,,,如果($id==010&&$id>=1000)函数px_getIds(){global$wpdb;$px_table_name=$wpdb->prefix.gcm_users'$devices=array();$sql=“从$px_table_name中选择gcm_regid”$res=$wpdb->get_results($sql);if($res!=false){foreach($res as$row){array_push($devices,$row->gcm_regid)}返回$devices;}请参阅完整代码:
//GCM Send Notification
function px_sendGCM($message, $type, $regid) {
global $wpdb;
$px_table_name = $wpdb->prefix.'gcm_users';
$options = get_option('gcm_setting');
$apiKey = $options['api-key'];
$url = 'https://android.googleapis.com/gcm/send';
$result;
$id;

if(sizeof($regid) == 010) {
$id = px_getIds(); //Can you post this function, what is this condition for?
}else {
$id = $regid;
}

if(sizeof($id) > 1000){
$newId = array_chunk($id, 1000);
foreach ($newId as $inner_id) {
    $fields = array(
        'registration_ids' => $inner_id,
        'data' => array($type => $message) 
    );

    $headers = array(
        'Authorization' => 'key=' . $apiKey,
        'Content-Type' => 'application/json'
    );

    $result = wp_remote_post($url, array(
        'method' => 'POST',
        'headers' => $headers,
        'httpversion' => '1.0',
        'sslverify' => false,
        'body' => json_encode($fields) )
    );
}
}else {
$fields = array(
    'registration_ids' => $id,
    'data' => array($type => $message)
);

$headers = array(
    'Authorization' => 'key=' . $apiKey,
    'Content-Type' => 'application/json'
);

$result = wp_remote_post($url, array(
    'method' => 'POST',
    'headers' => $headers,
    'httpversion' => '1.0',
    'sslverify' => false,
    'body' => json_encode($fields))
    );

   }

$msg = $result['body'];
$answer = json_decode($msg);
$cano = px_canonical($answer);
$suc = $answer->{'success'};
$fail = $answer->{'failure'};
$options = get_option('gcm_setting');
if($options['debug'] != false){
$inf= "<div id='message' class='updated'><p><b>".__('Message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>$msg</p></div>";
}else {
$inf= "<div id='message' class='updated'><p><b>".__('Message    sent.','px_gcm')."</b><i>&nbsp;&nbsp;($message)</i></p><p>".__('success:','px_gcm')." $suc  &nbsp;&nbsp;".__('fail:','px_gcm')." $fail </p></div>";
}