lokielse / aliyun-open-api-push
The Push SDK for Aliyun OpenAPI
v1.0.1
2016-07-11 16:33 UTC
Requires
- php: >=5.3.0
- lokielse/aliyun-open-api-core: ^1.0.0
Requires (Dev)
- phpunit/phpunit: 4.*
This package is not auto-updated.
Last update: 2024-10-26 19:48:23 UTC
README
The Push SDK for Aliyun OpenAPI
Install
Via Composer
$ composer require lokielse/aliyun-open-api-push
Usage
/** * 访问信息 */ $config = [ 'AccessKeyId'=>'<your access_key_id>', 'AccessKeySecret'=>'<your access_key_secret>', ]; /** * 配置网关 */ $endpoint = new Endpoint('cn-hangzhou', EndpointConfig::getRegionIds(), EndpointConfig::getProductDomains()); EndpointProvider::setEndpoints([ $endpoint ]); /** * 授权资料 */ $profile = DefaultProfile::getProfile('cn-hangzhou', $config['AccessKeyId'], $config['AccessKeySecret']); /** * 请求对象 */ $request = new \Aliyun\Push\Request\PushRequest(); /** * 推送目标 */ $request->setAppKey($appKey); $request->setTarget("all"); //推送目标: device:推送给设备; account:推送给指定帐号,tag:推送给自定义标签; all: 推送给全部 $request->setTargetValue("all"); //根据Target来设定,如Target=device, 则对应的值为 设备id1,设备id2. 多个值使用逗号分隔.(帐号与设备有一次最多100个的限制) $request->setDeviceType(3); // 设备类型deviceType 取值范围为:0~3. iOS设备: 0; Android设备: 1; 全部: 3, 这是默认值. /** * 推送配置 */ $request->setType(1); // 0:表示消息(默认为0), 1:表示通知 $request->setTitle("Hello OpenAPI!"); // 消息的标题 $request->setBody("PushRequest body"); // 消息的内容 $request->setSummary("PushRequest summary"); // 通知的摘要 /** * 推送配置: iOS */ $request->setiOSBadge("5"); // iOS应用图标右上角角标 $request->setiOSMusic("default"); // iOS通知声音 $request->setiOSExtParameters("{\"k1\":\"ios\",\"k2\":\"v2\"}"); //自定义的kv结构,开发者扩展用 针对iOS设备 $request->setApnsEnv("DEV"); $request->setRemind("false"); // 当APP不在线时候,是否通过通知提醒 /** * 推送配置: Android */ $request->setAndroidOpenType("3"); // 点击通知后动作,1:打开应用 2: 打开应用Activity 3:打开 url $request->setAndroidOpenUrl("http://www.baidu.com"); // Android收到推送后打开对应的url,仅仅当androidOpenType=3有效 $request->setAndroidExtParameters("{\"k1\":\"android\",\"k2\":\"v2\"}"); // 设定android类型设备通知的扩展属性 /** * 推送控制 */ //$pushTime = new DateTime(); //$pushTime->add(new DateInterval('PT30S')); // 30秒之后的时间点, 也可以设置成你指定固定时间 //$request->setPushTime($pushTime->format('Y-m-d\TH:i:s\Z')); // 延后推送。可选,如果不设置表示立即推送 $request->setStoreOffline("false"); // 离线消息是否保存,若保存, 在推送时候,用户即使不在线,下一次上线则会收到 //$expireTime = new DateTime(); //$expireTime->add(new DateInterval('P1D')); // 12小时后消息失效, 不会再发送 //$request->setExpireTime($expireTime->format('Y-m-d\TH:i:s\Z')); //$request->setBatchNumber("100010"); // 批次编号,用于活动效果统计. 设置成业务可以记录的字符串 $client = new DefaultAcsClient($profile); $response = $client->getAcsResponse($request); var_dump($response);
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CONDUCT for details.
Security
If you discover any security related issues, please email lokielse@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.