小米推送PHP包整合composer
阿新 • • 發佈:2018-12-11
rookiejin/mipush
github地址:
https://github.com/rookiejin/mipush
小米推送網址:
https://dev.mi.com/console/doc/detail?pId=230
php小米推送類:
https://blog.csdn.net/weixin_38728964/article/details/82464476
https://www.cnblogs.com/iwanghang/p/9056796.html
<?php namespace app\v2_5\controller; use think\Controller; use think\Db;//DB(資料庫)類 use think\Session;//session類 use think\Request;//請求資訊類 use util\Util; //ios use push\xmpush\IOSBuilder; use push\xmpush\Sender; use push\xmpush\Constants; use push\xmpush\Stats; use push\xmpush\Tracer; //android use push\xmpush\Builder; use push\xmpush\HttpBase; // use xmpush\Sender; // use xmpush\Constants; // use xmpush\Stats; // use xmpush\Tracer; use push\xmpush\Feedback; use push\xmpush\DevTools; use push\xmpush\Subscription; use push\xmpush\TargetedMessage; class Push extends Controller { /** * android推送 * @param $data 推送詳情陣列 * @param $content 推送內容 * @param $audience_type 推送物件(1:所有人;2:標籤;3:別名;4:序列號) * @param $aliasList 別名(陣列) * @param $token 使用者所屬企業id */ public static function androidpush($data,$content,$audience_type,$aliasList,$token){ Constants::setSecret(PUSH_Secret_android); Constants::setBundleId(PUSH_BundleId); $company_name = 'XXX'; // 使用開發環境 if(PUSH_Online == 0){ Constants::useSandbox(); } $notifyid = rand(0,4); $sender = new Sender(); // message 演示自定義的點選行為 $message = new Builder(); $message->title($company_name); // 通知欄的title $message->description($content); // 通知欄的descption $message->passThrough(0); // 這是一條通知欄訊息,如果需要透傳,把這個引數設定成1,同時去掉title和descption兩個引數 $message->extra(Builder::notifyForeground, 1); // 應用在前臺是否展示通知,如果不希望應用在前臺時候彈出通知,則設定這個引數為0 $message->notifyId($notifyid); // 通知型別。最多支援0-4 5個取值範圍,同樣的型別的通知會互相覆蓋,不同型別可以在通知欄並存 foreach ($data as $key => $value) { $message->extra($key, $value); } $message->build(); $targetMessage = new TargetedMessage(); $targetMessage->setTarget($aliasList, TargetedMessage::TARGET_TYPE_ALIAS); // 設定傳送目標。可通過regID,alias和topic三種方式傳送 $targetMessage->setMessage($message); $result = $sender->sendToAliases($message, $aliasList)->getRaw(); return $result; } /** * ios推送 * @param $data 推送詳情陣列 * @param $content 推送內容 * @param $audience_type 推送物件(1:所有人;2:標籤;3:別名;4:序列號) * @param $aliasList 別名(陣列) * @param $token 使用者所屬企業id */ public static function iospush($data,$content,$audience_type,$aliasList,$token){ Constants::setSecret(PUSH_Secret_ios); Constants::setBundleId(PUSH_BundleId); $company_name = 'XXX'; // 使用開發環境 if(PUSH_Online == 0){ Constants::useSandbox(); } $message = new IOSBuilder(); $message->title($company_name); // 通知欄的title $message->body($content);// 通知欄的內容 foreach ($data as $key => $value) { $message->extra($key, $value); } $message->build(); $sender = new Sender(); if($audience_type == 1){ //給所有人傳送 $result = $sender->broadcastAll($message)->getRaw(); }elseif($audience_type == 3){ //別名傳送 $result = $sender->sendToAliases($message, $aliasList)->getRaw(); } return $result; } }