我们怎样才能大量发送1000 GCM消息,比方说,万注册用户的数据库? [英] How can we send GCM messages in lots of 1000 to a database of, say, 10,000 registered users?
本文介绍了我们怎样才能大量发送1000 GCM消息,比方说,万注册用户的数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用下面的code发送使用PHP和MySQL GCM消息。请帮我出,以便它可以在大量的1000 GCM发送消息的,比如一注册用户的数据库。
1000穿越之前的用户,该脚本能正常工作;但经过1000个用户,没有人接收推式。
错误我收到:对群发邮件号(1082)超过允许的最大(1000)
// GCM发送通知
功能px_sendGCM($消息,$型,$ REGID){
全球WPDB $;
$ px_table_name = $ wpdb-> prefix.'gcm_users';
$选项= get_option('gcm_setting');
$ apiKey = $选项['API密钥'];
$ URL ='https://android.googleapis.com/gcm/send';
$结果;
$ ID;如果($ REGID == 010){
$ ID = px_getIds();
}其他{
的$ id = $ REGID;
}如果($ ID == 010安培;&放大器;的$ id> = 1000){
$ NEWID = array_chunk($ ID,1000);
的foreach($ NEWID为$ inner_id){
$栏=阵列(
registration_ids'=> $ inner_id,
'数据'=>阵列($型=> $消息)
); $头=阵列(
'授权'=> 键='。 $ apiKey,
Content-Type的'=> 应用/ JSON
); $结果= wp_remote_post($网址,阵列(
'方法'= GT; POST,
'头'=> $头,
httpversion'=> '1.0',
sslverify'=>假,
身体=> json_en code($字段))
);
}
}其他{
$栏=阵列(
registration_ids'=> $ ID,
'数据'=>阵列($型=> $消息)
); $头=阵列(
'授权'=> 键='。 $ apiKey,
Content-Type的'=> 应用/ JSON
); $结果= wp_remote_post($网址,阵列(
'方法'= GT; POST,
'头'=> $头,
httpversion'=> '1.0',
sslverify'=>假,
身体=> json_en code($字段))
);}$味精= $结果['身体'];
$答案= json_de code($味精);
$卡诺= px_canonical($答案);
$ SUC = $答案 - > {'成功'};
$失败= $答案 - > {'失败'};
$选项= get_option('gcm_setting');
如果($选项['调试']!= FALSE){
$ INF =&LT; DIV ID =信息类='更新'&GT;&LT; P&GT;&LT; B&gt;中.__('留言sent.','px_gcm').\"</b><i> ($message)</i></p><p>$msg</p></div>\";
}其他{
$ INF =&LT; DIV ID =信息类='更新'&GT;&LT; P&GT;&LT; B&gt;中.__('留言sent.','px_gcm').\"</b><i> ($message)</i></p><p>\".__('success:','px_gcm').\" $ SUC&放大器; NBSP;&安培; NBSP;.__('失败:','px_gcm')。$失败&LT; / P&GT;&LT; / DIV&gt;中;
}
请参阅满code 。
解决方案
// GCM发送通知
功能px_sendGCM($消息,$型,$ REGID){
全球WPDB $;
$ px_table_name = $ wpdb-&GT; prefix.'gcm_users';
$选项= get_option('gcm_setting');
$ apiKey = $选项['API密钥'];
$ URL ='https://android.googleapis.com/gcm/send';
$结果;
$ ID;如果(sizeof的($ REGID)== 010){
$ ID = px_getIds(); //您可以发布此功能,这是什么情况呢?
}其他{
的$ id = $ REGID;
}如果(sizeof的($ ID)GT; 1000){//在这里的条件不能同时等于10和大于= 1000
$ NEWID = array_chunk($ ID,1000);
的foreach($ NEWID为$ inner_id){
$栏=阵列(
registration_ids'=&GT; $ inner_id,
'数据'=&GT;阵列($型=&GT; $消息)
); $头=阵列(
'授权'=&GT; 键='。 $ apiKey,
Content-Type的'=&GT; 应用/ JSON
); $结果= wp_remote_post($网址,阵列(
'方法'= GT; POST,
'头'=&GT; $头,
httpversion'=&GT; '1.0',
sslverify'=&GT;假,
身体=&GT; json_en code($字段))
);
}
}其他{
$栏=阵列(
registration_ids'=&GT; $ ID,
'数据'=&GT;阵列($型=&GT; $消息)
);$头=阵列(
'授权'=&GT; 键='。 $ apiKey,
Content-Type的'=&GT; 应用/ JSON
);$结果= wp_remote_post($网址,阵列(
'方法'= GT; POST,
'头'=&GT; $头,
httpversion'=&GT; '1.0',
sslverify'=&GT;假,
身体=&GT; json_en code($字段))
); }$味精= $结果['身体'];
$答案= json_de code($味精);
$卡诺= px_canonical($答案);
$ SUC = $答案 - &GT; {'成功'};
$失败= $答案 - &GT; {'失败'};
$选项= get_option('gcm_setting');
如果($选项['调试']!= FALSE){
$ INF =&LT; DIV ID =信息类='更新'&GT;&LT; P&GT;&LT; B&gt;中.__('留言sent.','px_gcm').\"</b><i> ($message)</i></p><p>$msg</p></div>\";
}其他{
$ INF =&LT; DIV ID =信息类='更新'&GT;&LT; P&GT;&LT; B&gt;中.__('留言sent.','px_gcm').\"</b><i> ($message)</i></p><p>\".__('success:','px_gcm').\" $ SUC&放大器; NBSP;&安培; NBSP;.__('失败:','px_gcm')。$失败&LT; / P&GT;&LT; / DIV&gt;中;
}
I am using the following code to send GCM messages using PHP and MySQL. Please help me out so that it can send GCM messages in lots of 1000 to a database of, say, 10,000 registered users.
Before crossing 1000 users, this script works fine; but after 1000 users, no one receives push.
Error I receive: Number of messages on bulk (1082) exceeds maximum allowed (1000)
//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($regid == 010) {
$id = px_getIds();
}else {
$id = $regid;
}
if($id == 010 && $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> ($message)</i></p><p>$msg</p></div>";
}else {
$inf= "<div id='message' class='updated'><p><b>".__('Message sent.','px_gcm')."</b><i> ($message)</i></p><p>".__('success:','px_gcm')." $suc ".__('fail:','px_gcm')." $fail </p></div>";
}
See full code.
解决方案
//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){ // the condition over here cannot be both equal to 10 and >= 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> ($message)</i></p><p>$msg</p></div>";
}else {
$inf= "<div id='message' class='updated'><p><b>".__('Message sent.','px_gcm')."</b><i> ($message)</i></p><p>".__('success:','px_gcm')." $suc ".__('fail:','px_gcm')." $fail </p></div>";
}
这篇关于我们怎样才能大量发送1000 GCM消息,比方说,万注册用户的数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文