Skip to content

Commit

Permalink
iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
sn01615 committed May 11, 2020
1 parent 1b75530 commit 865c71b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 14 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ composer require sn01615/umeng-php
```

customizedcast,通过alias进行推送, 对单个或者多个alias进行推送

2020年4月14日:测试有效

2020年5月11日:iOS Customizedcast支持
```php
# Android
$cc = (new UmengPush('***', '***'))
->setProductionMode(false)
// ->setGetUrlAndBody(true) // 直接返回url和body
// ->setGetUrlAndBody(true) // 直接返回url和body
->sendAndroidCustomizedcast([
'ticker' => '1', // 必填 通知栏提示文字
'title' => '2', // 必填 通知标题
Expand All @@ -25,6 +29,25 @@ $cc = (new UmengPush('***', '***'))
],
$alias = '12345', // 开发者填写自己的alias, 要求不超过500个alias, 多个alias以英文逗号间隔
$aliasType = 'XXX');

# iOS
$cc = (new UmengPush('***', '***'))
->setProductionMode(false)
// ->setGetUrlAndBody(true) // 直接返回url和body
->sendIOSCustomizedcast([
// 'alert' => '', // 可为JSON类型和字符串类型
'alert' => [
'title' => '1',
'subtitle' => '2',
'body' => '3',
],
], [
'aaa' => 1111, // 可选,用户自定义内容, "d","p"为友盟保留字段,
// key不可以是"d","p"
], $alias = '12345', // 开发者填写自己的alias, 要求不超过500个alias, 多个alias以英文逗号间隔
$aliasType = 'XXX');

var_dump($cc);
```

##### README
Expand Down
41 changes: 28 additions & 13 deletions src/UmengPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,30 +449,45 @@ function sendIOSGroupcast()
}
}

function sendIOSCustomizedcast()
function sendIOSCustomizedcast(array $values, array $extra, $alias, $aliasType)
{
$values = array_merge([
'alert' => '', // 必填
// // 当content-available=1时(静默推送),可选; 否则必填。
// 可为JSON类型和字符串类型
// {
// "title":"title",
// "subtitle":"subtitle",
// "body":"body"
// },
'badge' => 0,
'sound' => 'chime',
'production_mode' => $this->getProductionMode(),// Set 'production_mode' to 'true' if your app is under production mode
'content-available' => 1,
], $values);
$extra = array_merge([], $extra);
try {
$customizedcast = new IOSCustomizedcast();
$customizedcast->setAppMasterSecret($this->appMasterSecret);
$customizedcast->setPredefinedKeyValue("appkey", $this->appKey);
$customizedcast->setPredefinedKeyValue("timestamp", $this->timestamp);

// Set your alias here, and use comma to split them if there are multiple alias.
// And if you have many alias, you can also upload a file containing these alias, then
// use file_id to send customized notification.
$customizedcast->setPredefinedKeyValue("alias", "xx");
$customizedcast->setPredefinedKeyValue("alias", $alias);
// Set your alias_type here
$customizedcast->setPredefinedKeyValue("alias_type", "xx");
$customizedcast->setPredefinedKeyValue("alert", "IOS 涓�у寲娴嬭瘯");
$customizedcast->setPredefinedKeyValue("badge", 0);
$customizedcast->setPredefinedKeyValue("sound", "chime");
// Set 'production_mode' to 'true' if your app is under production mode
$customizedcast->setPredefinedKeyValue("production_mode", "false");
print("Sending customizedcast notification, please wait...\r\n");
$customizedcast->send();
print("Sent SUCCESS\r\n");
$customizedcast->setPredefinedKeyValue("alias_type", $aliasType);
foreach ($values as $key => $value) {
$customizedcast->setPredefinedKeyValue($key, $value);
}
foreach ($extra as $key => $value) {
$customizedcast->setCustomizedField($key, $value);
}
// print("Sending customizedcast notification, please wait...\r\n");
return $customizedcast->send($this->getGetUrlAndBody());
// print("Sent SUCCESS\r\n");
} catch (Exception $e) {
print("Caught exception: " . $e->getMessage());
return "Caught exception: " . $e->getMessage();
}
}
}
Expand Down

0 comments on commit 865c71b

Please sign in to comment.