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;
    }
 
 
}

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐