apalych/yii2-apns-gcm

Yii 2 结合使用 Apns 和 Gcm

安装: 3

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 0

分支: 40

类型:yii2-extension

1.0.5 2021-03-11 10:13 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:23:07 UTC


README

Yii 2 使用 Apns 和 Gcm 结合常见的 send()sendMulti() 方法

安装

安装此扩展的首选方式是通过 composer

运行

php composer.phar require --prefer-dist apalych/yii2-apns-gcm "1.0.4.1"

或添加

"apalych/yii2-apns-gcm": "1.0.4.1"

到你的 composer.json 文件的 require 部分。

在你的 main.php 中,配置如下

'components' => [
	'apns' => [
		'class' => 'bryglen\apnsgcm\Apns',
		'environment' => \bryglen\apnsgcm\Apns::ENVIRONMENT_SANDBOX,
		'pemFile' => dirname(__FILE__).'/apnssert/apns-dev.pem',
		// 'retryTimes' => 3,
		'options' => [
			'sendRetryTimes' => 5
		]
	],
	'gcm' => [
		'class' => 'bryglen\apnsgcm\Gcm',
		'apiKey' => 'your_api_key',
	],
	// using both gcm and apns, make sure you have 'gcm' and 'apns' in your component
	'apnsGcm' => [
		'class' => 'bryglen\apnsgcm\ApnsGcm',
		// custom name for the component, by default we will use 'gcm' and 'apns'
		//'gcm' => 'gcm',
		//'apns' => 'apns',
	]
]

在线测试器

请访问以下链接进行在线测试 http://apns-gcm.bryantan.info

用法

仅使用 APNS 的用法

/* @var $apnsGcm \bryglen\apnsgcm\Apns */
$apns = Yii::$app->apns;
$apns->send($push_tokens, $message,
  [
    'customProperty_1' => 'Hello',
    'customProperty_2' => 'World'
  ],
  [
    'sound' => 'default',
    'badge' => 1
  ]
);

仅使用 GCM 的用法

/* @var $apnsGcm \bryglen\apnsgcm\Gcm */
$gcm = Yii::$app->gcm;
$gcm->send($push_tokens, $message,
  [
    'customerProperty' => 1,
  ],
  [
    'timeToLive' => 3
  ],
);

同时使用 APNS 和 GCM 的用法

使用 Google Cloud Messaging 发送

/* @var $apnsGcm \bryglen\apnsgcm\ApnsGcm */
$apnsGcm = Yii::$app->apnsGcm;
$apnsGcm->send(\bryglen\apnsgcm\ApnsGcm::TYPE_GCM, $push_tokens, $message,
  [
    'customerProperty' => 1
  ],
  [
    'timeToLive' => 3
  ],
)

使用 Apple 推送通知服务发送

/* @var $apnsGcm \bryglen\apnsgcm\ApnsGcm */
$apnsGcm = Yii::$app->apnsGcm;
$apnsGcm->send(\bryglen\apnsgcm\ApnsGcm::TYPE_APNS, $push_tokens, $message,
  [
    'customerProperty' => 1
  ],
  [
    'sound' => 'default',
  	'badge' => 1
  ],
)