极光推送。。

//方法
use JPush\Client;
use Ws\Http\Request;
use Ws\Http\Request\Body;

protected function Jpush_user($phone, $alert, $extras)
{
        $client = new Client(config('jpush')['user']['app_key'], config('jpush')['user']['master_secret'], null);
        $pusher = $client->push()->addAlias($phone)->setPlatform(['ios', 'android'])->iosNotification($alert, [
            'extras' => $extras,
        ])->androidNotification($alert, [
            'extras' => $extras,
        ]);
        if (config('iOS_push_debug') === false) {
            $pusher->setOptions(null, null, null, true);
        }
        try {
            $pusher->send();
        } catch (\Exception $e) {
            trace('乘客端推送失败:' . $e->getMessage());
        }
        $this->TPNS('user', $phone, $alert, $extras);
    }

protected function TPNS($config, $phone, $alert, $extras, $sound = '')
{
        if ($config === 'user') {
            return;
        }
        $config = config('tpns')[$config];
        $point  = 'https://api.tpns.tencent.com/v3/push/app';
        $http   = Request::create();
        $custom = json_encode($extras);
        $param  = [
            'audience_type' => 'account',
            'account_list'  => [$phone],
            'message'       => [
                'title'   => $alert,
                'content' => '',
            ],
            'message_type'  => 'notify',
        ];
        // Android 推送
        $param_a = $param;

        $param_a['message']['android'] = [
            'custom_content' => $custom,
        ];

        $resp = $http->post($point, [
            'Authorization' => 'Basic ' . base64_encode($config['Android']['AccessID'] . ':' . $config['Android']['SecretKey']),
        ], Body::json($param_a));
        if ($resp->body->ret_code !== 0) {
            trace('腾讯云移动推送Android推送失败:' . $resp->body->err_msg);
        }
        // iOS推送
        $param_i = $param;

        $param_i['message']['ios'] = [
            'aps'            => [
                'alert' => [
                    'subtitle' => $alert,
                ],
            ],
            'sound'          => $sound,
            'custom_content' => $custom,
        ];
        if (config('iOS_push_debug')) {
            $param_i['environment'] = 'dev';
        } else {
            $param_i['environment'] = 'product';
        }
        $resp = $http->post($point, [
            'Authorization' => 'Basic ' . base64_encode($config['iOS']['AccessID'] . ':' . $config['iOS']['SecretKey']),
        ], Body::json($param_i));
        if ($resp->body->ret_code !== 0) {
            trace('腾讯云移动推送iOS推送失败:' . $resp->body->err_msg);
        }
    }


//使用

$this->Jpush_user($user->phone, $data['title'], ['type' => 0, 'message_id' => $message_id]);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值