/**
* 推送单个通知
* @param string $userCid 用户唯一标识
* @param string $title 标题
* @param string $body 内容
* @return bool
*/
function pushNotice($userCid='',$title='',$body='')
{
Vendor('Pushapi.GTClient');
// 创建API,APPID等配置参考 环境要求 进行获取
$api = new GTClient("https://restapi.getui.com","AppKey", "AppID","MasterSecret");
// 设置推送参数
$push = new GTPushRequest();
// 设置请求唯一标识号
$push->setRequestId(time());
$message = new GTPushMessage();
$notify = new GTNotification();
$notify->setTitle($title);
$notify->setBody($body);
// 点击通知后续动作,目前支持以下后续动作:
// 1、intent:打开应用内特定页面url:打开网页地址。
// 2、payload:自定义消息内容启动应用。
// 3、payload_custom:自定义消息内容不启动应用。
// 4、startapp:打开应用首页。
// 5、none:纯通知,无后续动作
$notify->setClickType("none");
$message->setNotification($notify);
$push->setPushMessage($message);
$push->setCid($userCid);
// 处理返回结果
$result = $api->pushApi()->pushToSingleByCid($push);
if (!empty($result)) {
return true;
} else {
return false;
}
}
/**
* 全体发送通知(设置的应用内所有的用户)
* @param string $title
* @param string $body
*/
function pushAllNotice($title='',$body=''){
Vendor('Pushapi.GTClient');
$push = new GTPushRequest();
$push->setRequestId(time());
$message = new GTPushMessage();
$notify = new GTNotification();
$notify->setTitle($title);
$notify->setBody($body);
$notify->setClickType("none");
$message->setNotification($notify);
$push->setPushMessage($message);
$api = new GTClient("https://restapi.getui.com","AppKey", "AppID","MasterSecret");
//处理返回结果
$result = $api->pushApi()->pushAll($push);
if (!empty($result)) {
return true;
} else {
return false;
}
}
/**
* 用户绑定别名
* @param string $userCid 用户唯一标识
* @param string $alias 用户别名
*/
public function bindAlias($userCid='',$alias=''){
Vendor('Pushapi.GTClient');
$aliasRequest = new GTAliasRequest();
$cidAlias = new GTCidAlias();
$cidAlias->setCid($userCid);
$cidAlias->setAlias($alias);
$aliasRequest->addDataList($cidAlias);
$api = new GTClient("https://restapi.getui.com","AppKey","AppID","MasterSecret");
//处理返回结果
$result = $api->userApi()->bindAlias($aliasRequest);
print_r($result);
if (!empty($result)) {
return true;
} else {
return false;
}
}
// 绑定别名
bindAlias('15265900000','小明');
// 发送消息
pushAllNotice('系统通知','小明捡到了50元钱');