php+极光推送(厂商通道) jpush推送

php+极光推送(厂商通道) jpush推送

此方法可放到common.php内调用

php 复制代码
if (!function_exists("push")) {
    /**
     * Notes:
     * User: 任性不起来了
     * Date: 2024/6/28 16:44
     * @param $accept_id 用户ID
     * @param $message 消息内容
     * @param int $orderrecording_id 商机ID
     */
    function push($accept_id, $message,$orderrecording_id=0)
    {
        
        //记录日志---接收参数
        error_log(date('Y-m-d H:i:s').'   $message ==='.json_encode($message,320).PHP_EOL,3,'../runtime/push.log');
        
        $push = addons_action('Jiguang', 'JPush', 'getClient', 'push');
        //获取保存的设备ID
        $id = Db::name('user')->where(['id' => $accept_id])->value('client_id');

        $push->setPlatform('all')
            ->addRegistrationId($id)
            ->setNotificationAlert('alert');

        $push->androidNotification($message, [
//            'title'  => $title,
            'sound'  => 'sound',
            'extras' => [
                'key' => 'value'
            ],
        ]);
        //配置厂商通道
        $push->options([
                'classification'      => 1,//0:代表运营消息,1:代表系统消息。
                'third_party_channel' => [
                    'huawei' => [
                        'importance' => 'NORMAL',
                        'category'   => 'WORK'
                    ],
                    'xiaomi' => [
                        'channel_id' => '121954' ,
                    ],
                    'oppo' => [
                        'channel_id' => 'message' ,
                    ],
                    'vivo' => [
                        'distribution' => 'secondary_push' ,
                        'category' => 'ORDER' ,
                    ],
                    'honor' => [
                        'importance' => 'NORMAL' ,
                    ],
                ]
            ]
        );

        $result = $push->send();


        //        $result = $data->setPlatform('android')
//            //        ->addAllAudience()
//            ->addRegistrationId($id)
//            ->androidNotification($message,[
//                'title'  => $title,
//                //                'sound'  => '测试声音',
//                // 'builder_id' => 2,
//                'extras' => [],
//                ])
//            ->send();



        error_log(date('Y-m-d H:i:s').'   $result ==='.json_encode($result,320).PHP_EOL,3,'../runtime/push.log');

        if ($result['http_code'] = 200) {
            //推送成功,此处写自己的项目逻辑
			
            //更新商机列表推送ID
            if($orderrecording_id){
                //更新录单表
                $update = [
                    'msg_id' => $result['body']['msg_id'] ,
                    'update_time' => time() ,
                ] ;
                Db::name('order_recording')->where('aid',$orderrecording_id)->update($update);
                //增加推送记录
                $insert = [
                    'user_id' => $accept_id ,
                    'orderrecording_id' => $orderrecording_id ,
                    'msg_id' => $update['msg_id'] ,
                    'is_read' => 0 ,
                    'create_time' => time() ,
                ] ;
                Db::name('order_push')->insert($insert);
            }

            return true;
        } else {
            return false;
        }
    }
}
相关推荐
JaguarJack6 小时前
PHP 图像处理实战 GD/Imagick 从入门到精通,构建高性能图像服务
后端·php
偷光8 小时前
浏览器中的隐藏IDE: Elements (元素) 面板
开发语言·前端·ide·php
能工智人小辰18 小时前
Coordinate Attention for Efficient Mobile Network Design 学习笔记
笔记·学习·php
应用市场18 小时前
自建本地DNS过滤系统:实现局域网广告和垃圾网站屏蔽
开发语言·php
星如雨落1 天前
Linux VScode 安装PHP环境
linux·php·visual studio code
宁小法1 天前
PHP 数组 如何将新元素加到数组第一个位置(支持指定key => value)
php·数组·首个元素
运维闲章印时光1 天前
网络断网、环路、IP 冲突?VRRP+MSTP+DHCP 联动方案一次性解决
运维·服务器·开发语言·网络·php
板鸭〈小号〉2 天前
Socket网络编程(1)——Echo Server
开发语言·网络·php
kjl5365662 天前
Redis配置文件(redis.conf)
redis·bootstrap·php
東雪蓮☆2 天前
LNMP 环境部署 WordPress
linux·运维·mysql·nginx·php