autoxloo/apns 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

autoxloo/apns

Composer 安装命令:

composer require autoxloo/apns

包简介

Apple Notification Server

README 文档

README

Sends push notification via Apple Notification Server

Note: This package is not supported properly

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist autoxloo/apns "*"

or

composer require --prefer-dist autoxloo/apns "*"

or add

"autoxloo/apns": "*"

to the require section of your composer.json file.

Configuration

You have to install curl with http2 support:

cd ~
sudo apt-get install build-essential nghttp2 libnghttp2-dev libssl-dev
wget https://curl.haxx.se/download/curl-7.58.0.tar.gz
tar -xvf curl-7.58.0.tar.gz
cd curl-7.58.0
./configure --with-nghttp2 --prefix=/usr/local --with-ssl=/usr/local/ssl
make
sudo make install
sudo ldconfig
sudo reboot

Info from https://askubuntu.com/questions/884899/how-do-i-install-curl-with-http2-support

If not helped, try https://serversforhackers.com/c/curl-with-http2-support

Usage

To send push notification you should have apple .pem certificate.

Constructor params and default values:

use autoxloo\apns\AppleNotificationServer;

$appleCertPath = __DIR__ . '/wxv_cert.pem';

$apns = new AppleNotificationServer(
    $appleCertPath,
    $apiUrl = 'https://api.push.apple.com/3/device',
    $apiUrlDev = 'https://api.sandbox.push.apple.com/3/device',
    $apnsPort = 443,
    $pushTimeOut = 10,
    $topic = null,
    $expiration = null,
    $pushType = null
);

Sending push notification:

use autoxloo\apns\AppleNotificationServer;

$appleCertPath = __DIR__ . '/wxv_cert.pem';
$token = 'some device token';
$payload = [
    'some key1' => 'some value1',
    'some key2' => 'some value2',
];

$apns = new AppleNotificationServer($appleCertPath);
$response = $apns->send($token, $payload);

or if you want to send to many tokens:

use autoxloo\apns\AppleNotificationServer;

$appleCertPath = __DIR__ . '/wxv_cert.pem';
$tokens = [
    'some device token',
    'some other device token',
];
$payload = [
    'some key1' => 'some value1',
    'some key2' => 'some value2',
];

$apns = new AppleNotificationServer($appleCertPath);
$response = $apns->sendToMany($tokens, $payload);

If you want to send push notification with some apns-push-type, you need certificate compilable with this push type and to set AppleNotificationServer::$pushType in constructor or with set method:

use autoxloo\apns\AppleNotificationServer;

$appleCertPath = __DIR__ . '/wxv_cert.pem';
$token = 'some device token';
$payload = [
    'some key1' => 'some value1',
    'some key2' => 'some value2',
];

$apns = new AppleNotificationServer($appleCertPath);
$apns->setPushType(AppleNotificationServer::PUSH_TYPE_BACKGROUND);  // sets `apns-push-type` header.
// other available set methods:
$apns->setTopic('some topic');  // sets `apns-topic` header.
$apns->setExpiration(time() + 30);  // sets `apns-expiration` header.
$apns->setExpiration(0);  // sets `apns-expiration` header. If the value is 0, APNs attempts to deliver
                          // the notification only once and doesn’t store it.
$response = $apns->send($token, $payload);

AppleNotificationServer sends push notification first on $apiUrl (https://api.push.apple.com/3/device) if not success (not status code 200), then sends on $apiUrlDev (https://api.sandbox.push.apple.com/3/device). If you don't want to send push notification on $apiUrlDev set it value to false. Also, if you want to send push notification only on dev url, you can do so like this (set $apiUrl with dev url value):

use autoxloo\apns\AppleNotificationServer;

$apns = new AppleNotificationServer($appleCertPath, 'https://api.sandbox.apple.com/3/device', false);

See Generating a Remote Notification and Sending Notification Requests to APNs for more details.

统计信息

  • 总下载量: 120
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2018-09-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固