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;
        }
    }
}
相关推荐
Rverdoser39 分钟前
代理服务器运行速度慢是什么原因
开发语言·前端·php
森叶2 小时前
从 JIT 即时编译一直讲到CGI|FastGGI|WSGI|ASGI四种协议的实现细节
python·php·web
myusa24 小时前
使用阿里云CLI跨地域迁移ECS实例
数据库·阿里云·php
互联网搬砖老肖2 天前
运维打铁:服务器分类及PHP入门
运维·服务器·php
Mr.小怪2 天前
K8s网络从0到1
网络·kubernetes·php
剑哥在胡说2 天前
高并发PHP部署演进:从虚拟机到K8S的DevOps实践优化
kubernetes·php·devops
fakaifa2 天前
【开源版】likeshop上门家政系统PHP版全开源+uniapp前端
小程序·uni-app·php·家政小程序源码·家政服务小程序·源码下载·上门家政
从零开始学习人工智能3 天前
探索网络设备安全:Shodan 的原理与合法应用
网络·安全·php
橙色小博3 天前
Python中的re库详细用法与代码解析
linux·python·正则表达式·php·re
Suckerbin3 天前
PHP会话技术
开发语言·php