极光推送
来源:互联网 发布:centos mysql启动失败 编辑:程序博客网 时间:2024/05/17 23:00
/**
* 给单个用户发送通知
* @param int $user_id 用户ID
* @param string $content 发送内容
* @param string $title 标题
* @param int $open_type 打开类型
* @param string $open_url 打开url
* @param int $pipei_id 展示的数据主键根据ptype决定
* @param int $ptype 一级通知类型
*/
public function sendToUser($user_id, $content, $title='', $open_type=0, $open_url='',$pipei_id = 0,$ptype = 0,$is_push = true)
{
if (empty($user_id) || empty($content))
{
return false;
}
try {
$identify = \common\models\basedata\MsgIdentify::getByUid((int)$user_id, false);
if (!$identify)
{
return false;
}
$registration_id = $identify[0]['identify'];
$platform = $identify[0]['platform'];
$open_type = $platform == PLATFORM_IOS ?(string)$open_type : $open_type;
$notification = ['extras' => ['open_type' => $open_type,'open_url' => $open_url]];
$client = $this->client->push()->setPlatform($platform == PLATFORM_ANDROID ? 'android' : 'ios');
// $client = $this->client->push()->setPlatform('all');
if ($platform == PLATFORM_ANDROID)
{
$client->androidNotification($content, $notification);
} else if ($platform == PLATFORM_IOS) {
$client->iosNotification($content, $notification);
}
$notification['title'] = $title;
$client->message($content, $notification);
$client->setOptions((int)$user_id, MsgPush::MSG_LIVE_TIME,null,(YII_DEBUG ? false : true));
$client->addRegistrationId($registration_id);
$response = $client->send();
if (isset($response['http_code']) && $response['http_code']==200)
{
$jmsg_id= $response['body']['msg_id'];
if($is_push)
{
\common\models\basedata\MsgSend::add($content,$user_id,0,$jmsg_id,(int)$open_type,$open_url,$pipei_id,$ptype,$title);
}
return true;
}
} catch (\JPush\Exceptions\APIConnectionException $e)
{
\common\helper\Common::dblog($e->getTraceAsString(),10003);
return self::SEND_EXCEPTION;
} catch (\JPush\Exceptions\APIRequestException $e)
{
\common\helper\Common::dblog($e->getTraceAsString(), 10003);
return self::SEND_EXCEPTION;
} catch (\Exception $e) {
\common\helper\Common::dblog($e->getTraceAsString(), 10003);
return self::SEND_EXCEPTION;
}
return false;
}
* 给单个用户发送通知
* @param int $user_id 用户ID
* @param string $content 发送内容
* @param string $title 标题
* @param int $open_type 打开类型
* @param string $open_url 打开url
* @param int $pipei_id 展示的数据主键根据ptype决定
* @param int $ptype 一级通知类型
*/
public function sendToUser($user_id, $content, $title='', $open_type=0, $open_url='',$pipei_id = 0,$ptype = 0,$is_push = true)
{
if (empty($user_id) || empty($content))
{
return false;
}
try {
$identify = \common\models\basedata\MsgIdentify::getByUid((int)$user_id, false);
if (!$identify)
{
return false;
}
$registration_id = $identify[0]['identify'];
$platform = $identify[0]['platform'];
$open_type = $platform == PLATFORM_IOS ?(string)$open_type : $open_type;
$notification = ['extras' => ['open_type' => $open_type,'open_url' => $open_url]];
$client = $this->client->push()->setPlatform($platform == PLATFORM_ANDROID ? 'android' : 'ios');
// $client = $this->client->push()->setPlatform('all');
if ($platform == PLATFORM_ANDROID)
{
$client->androidNotification($content, $notification);
} else if ($platform == PLATFORM_IOS) {
$client->iosNotification($content, $notification);
}
$notification['title'] = $title;
$client->message($content, $notification);
$client->setOptions((int)$user_id, MsgPush::MSG_LIVE_TIME,null,(YII_DEBUG ? false : true));
$client->addRegistrationId($registration_id);
$response = $client->send();
if (isset($response['http_code']) && $response['http_code']==200)
{
$jmsg_id= $response['body']['msg_id'];
if($is_push)
{
\common\models\basedata\MsgSend::add($content,$user_id,0,$jmsg_id,(int)$open_type,$open_url,$pipei_id,$ptype,$title);
}
return true;
}
} catch (\JPush\Exceptions\APIConnectionException $e)
{
\common\helper\Common::dblog($e->getTraceAsString(),10003);
return self::SEND_EXCEPTION;
} catch (\JPush\Exceptions\APIRequestException $e)
{
\common\helper\Common::dblog($e->getTraceAsString(), 10003);
return self::SEND_EXCEPTION;
} catch (\Exception $e) {
\common\helper\Common::dblog($e->getTraceAsString(), 10003);
return self::SEND_EXCEPTION;
}
return false;
}
阅读全文
0 0
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 极光推送
- 推送 、极光
- 极光推送
- 极光推送
- 极光推送
- scrapy的简单应用-抓取链家数据
- opencv中copyTo的用法
- 递归return需注意
- 51 nod 1693 水群(最短路)
- JAVA中对list map根据map某个key值进行排序
- 极光推送
- IO流--字节流
- android从图标进入app不会黑屏和任务栏进入app会黑屏的解决办法
- LogisticRegression
- GC详解及Minor GC和Full GC触发条件总结
- HttpWatch学习笔记二
- 查看端口被占用
- POI 把java项目中的数据信息导入到Excel中,详细操作
- 获取传感器信息