脚本宝典收集整理的这篇文章主要介绍了如何使用php curl在Firefox中发送推送消息,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
function send_push_message($subscription_ids){ // Set GCM endpoint $url = 'https://andROId.GOOGLEapis.COM/gcm/send'; $fields = array( 'registration_ids' => $subscription_ids,); $headers = array( 'Authorization: key=API_KEY','Content-tyPE: application/json' ); $ch = curl_init(); // Set the url,number of POST VARs,POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); curl_setopt($ch,CURLOPT_RETURNtransfer,true); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLOPT_POSTFIELDS,json_encode($fields)); // Execute post $result = curl_exec($ch); if ($result === FALSE) { die('Push msg send Failed in curl: ' . curl_error($ch)); } // Close connection curl_close($ch); }
(我以前存储过订阅)
我想我可以使用这个url:https://updates.push.services.mozilla.com/push为Firefox做这样的事情
我需要在Mozilla注册我的网站才能做到这一点,就像谷歌一样吗?
请帮忙!
function send_push_message($subscriptionIDs){ if (empty($subscriptionIDs)) return FALSE; $chs = $sChrome = array(); $mh = curl_multi_inIT(); for@R_512_2428@ ($subscriptionIDs as $subscription){ $i = count($chs); switch ($subscription["browser"]){ case "firefox": $chs[ $i ] = curl_init(); curl_setopt($chs[ $i ],"https://updates.push.services.mozilla.com/push/".$subscription["id"] ); curl_setopt($chs[ $i ],CURLOPT_PUT,TRUE); curl_setopt($chs[ $i ],array( "TTL: 86400" ) ); curl_setopt($chs[ $i ],FALSE); curl_multi_add_handle($mh,$chs[ $i ]); break; case "chrome": $sChrome[] = $subscription["id"]; break; } } if (!empty($sChrome)){ $i = count($chs); $chs[ $i ] = curl_init(); curl_setopt($chs[ $i ],"https://android.googleapis.com/gcm/send" ); curl_setopt($chs[ $i ],TRUE); curl_setopt($chs[ $i ],array( "Authorization: key=MY_KEY","Content-Type: application/json" ) ); curl_setopt($chs[ $i ],FALSE); curl_setopt($chs[ $i ],json_encode( array( "registration_ids" => $sChrome ) ) ); curl_multi_add_handle($mh,$chs[ $i ]); } do { curl_multi_exec($mh,$running); curl_multi_select($mh); } while ($running > 0); for ($i = 0; $i < count($chs); $i++){ curl_multi_remove_handle($mh,$chs[ $i ]); } curl_multi_close($mh); }
($subscriptionIDs是一个包含2个键的数组数组:id和browser)
以上是脚本宝典为你收集整理的如何使用php curl在Firefox中发送推送消息全部内容,希望文章能够帮你解决如何使用php curl在Firefox中发送推送消息所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。