基于第三方极光推送

"require": {
    "jpush/jpush": "^3.5"
}

composer 下载 jpush/jpush

引用JPush


// jpush
function jSend($config,$notification, $alias = null, $extra = [], $product = true)
{
    try {
        $client = new JPush($config['AppKey'], $config['Secret']);
        $result = $client->push()
            ->setPlatform(array('ios', 'android'))
            ->addAlias($alias)
            ->setNotificationAlert($notification)
            ->addAndroidNotification($notification, 'title', 1, $extra)
            ->addIosNotification($notification, '1', 1, true, 'jiguang',$extra)
            ->send();
    } catch (\Exception $exception) {
        trace('提交订单失败:' . $exception->getMessage());
    }
}

更全

<?php

use JPush\Client as Client;

class JPush
{
    /**
     * 通过别名发送极光推送消息
     * @param $title // 标题
     * @param $content // 内容
     * @param $alias // 别名
     * @param array $params // 扩展字段
     * @param string $ios_badge // ios 角标数
     * @param array $platform // 推送设备
     * @return array
     */
    public static function pushMessageByAlias ($title, $content, $alias, $params = [], $ios_badge = '0', $platform = ['ios', 'android'])
    {

        if (!is_array ($alias)) return false;
        $jpush_conf = Output::getJPushKey (); // 获取配置信息 app_key 和 master_secret

        $app_key = $jpush_conf[ 'app_key' ];
        $master_secret = $jpush_conf[ 'master_secret' ];
        try {
            // 初始化
            $client = new Client($app_key, $master_secret);

            $result = $client->push ()
                ->setPlatform ($platform)
                ->addAlias ($alias)
                ->iosNotification (
                    $content, [
                    'sound' => '1',
                    'badge' => (int)$ios_badge,
                    'content-available' => true,
                    'category' => 'jiguang',
                    'extras' => $params,
                ])
                ->androidNotification ($content, [
                    'title' => $title,
                    //'build_id' => 2,
                    'extras' => $params,
                ])
                ->options ([
                    'sendno' => 100,
                    'time_to_live' => 86400,
                    'apns_production' => true, // ios推送证书的选择,True 表示推送生产环境,False 表示要推送开发环境
                    //'big_push_duration' => 10,
                ])
                ->send ();
            return $result;
        } catch (\Exception $e) {
            // 日志
          
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值