|
@@ -21,6 +21,7 @@ use onesignal\client\model\Segment;
|
|
use onesignal\client\model\FilterExpressions;
|
|
use onesignal\client\model\FilterExpressions;
|
|
use GuzzleHttp;
|
|
use GuzzleHttp;
|
|
use app\common\model\User;
|
|
use app\common\model\User;
|
|
|
|
+use think\Db;
|
|
class Message extends Api
|
|
class Message extends Api
|
|
{
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedLogin = ['*'];
|
|
@@ -49,6 +50,7 @@ class Message extends Api
|
|
$user = User::getByUserId($data['user_id']);
|
|
$user = User::getByUserId($data['user_id']);
|
|
if ($user) {
|
|
if ($user) {
|
|
$user->group_id = $data['group_id'];
|
|
$user->group_id = $data['group_id'];
|
|
|
|
+ $user->token = $data['token'];
|
|
$user->save();
|
|
$user->save();
|
|
}else{
|
|
}else{
|
|
User::create($data, true);
|
|
User::create($data, true);
|
|
@@ -57,19 +59,117 @@ class Message extends Api
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- function createNotification($enContent){
|
|
|
|
|
|
+ function createNotification($enContent,$segment){
|
|
$content = new StringMap();
|
|
$content = new StringMap();
|
|
$content->setEn($enContent);
|
|
$content->setEn($enContent);
|
|
$notification = new Notification();
|
|
$notification = new Notification();
|
|
$notification->setAppId('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694');
|
|
$notification->setAppId('6bbd561f-4d8e-4d04-a6c4-dbef1bf99694');
|
|
$notification->setContents($content);
|
|
$notification->setContents($content);
|
|
- $notification->setIncludedSegments(['SegmentA']);
|
|
|
|
|
|
+ $notification->setIncludedSegments([$segment]);
|
|
return $notification;
|
|
return $notification;
|
|
}
|
|
}
|
|
|
|
|
|
- public function send(){
|
|
|
|
- $notification = $this->createNotification(' wk Test notification');
|
|
|
|
|
|
+ public function send($enContent,$segment){
|
|
|
|
+ $notification = $this->createNotification($enContent,$segment);
|
|
$result = $this->apiInstance->createNotification($notification);
|
|
$result = $this->apiInstance->createNotification($notification);
|
|
|
|
+ return $result;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function sendMsg(){
|
|
|
|
+ $wheres['sendtime']=array('lt',time());
|
|
|
|
+ $wheres['status']=1;
|
|
|
|
+ $one_push = Db::name('message')->where($wheres)->order('id')->find();
|
|
|
|
+ if (empty($one_push)) {
|
|
|
|
+ echo '没有查到推送队列';
|
|
|
|
+ exit;
|
|
|
|
+ } else {
|
|
|
|
+ $where['id']=$one_push['id'];
|
|
|
|
+ $data['status']=2;
|
|
|
|
+ $data['uptime']=time();
|
|
|
|
+ Db::name('message')->where($where)->update($data);
|
|
|
|
+ }
|
|
|
|
+ $template_dsc =$one_push['template_dsc'];
|
|
|
|
+ $segment =$one_push['group_name'];
|
|
|
|
+ $result =$this->send($template_dsc,$segment);
|
|
print_r($result);
|
|
print_r($result);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public function getMessage(){
|
|
|
|
+ $post=$this->request->post();
|
|
|
|
+ $user = User::getByUserId($post['user_id']);
|
|
|
|
+ $data=array();
|
|
|
|
+ if($user){
|
|
|
|
+ $wheres['group_id']=$user->group_id;
|
|
|
|
+ $wheres['status']=2;
|
|
|
|
+ $list = Db::name('message')->where($wheres)->order('id')->select();
|
|
|
|
+ if($list){
|
|
|
|
+ foreach ($list as $k=>$v){
|
|
|
|
+ $data[$k]['imgUrl']='';
|
|
|
|
+ $data[$k]['time']=$v['sendtime'];
|
|
|
|
+ $data[$k]['title']=$v['template_name'];
|
|
|
|
+ $data[$k]['des']=$v['template_dsc'];
|
|
|
|
+ $data[$k]['push_type']=$v['type'];
|
|
|
|
+ $data[$k]['push_para']=$v['para'];
|
|
|
|
+ $data[$k]['isReaded']=0;
|
|
|
|
+ $where['message_id']=$v['id'];
|
|
|
|
+ $where['user_id']=$post['user_id'];
|
|
|
|
+ $read = Db::name('message_read')->where($where)->find();
|
|
|
|
+ if($read){
|
|
|
|
+ $data[$k]['isReaded']=1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $data=null;
|
|
|
|
+ }
|
|
|
|
+ $this->success('',$data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function upRead(){
|
|
|
|
+ $post=$this->request->post();
|
|
|
|
+ if($post['type']==1){//单条阅读
|
|
|
|
+ unset($post['type']);
|
|
|
|
+ $wheres['message_id']=$post['message_id'];
|
|
|
|
+ $wheres['user_id']=$post['user_id'];
|
|
|
|
+ $list = Db::name('message_read')->where($wheres)->find();
|
|
|
|
+ if($list){
|
|
|
|
+ $this->success();
|
|
|
|
+ }else{
|
|
|
|
+ $post['addtime']=time();
|
|
|
|
+ $re = Db::name('message_read')->insertGetId($post);
|
|
|
|
+ if($re){
|
|
|
|
+ $this->success();
|
|
|
|
+ }else{
|
|
|
|
+ $this->error();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $user = User::getByUserId($post['user_id']);
|
|
|
|
+ $wheres['group_id']=$user->group_id;
|
|
|
|
+ $wheres['status']=2;
|
|
|
|
+ $list = Db::name('message')->where($wheres)->order('id')->select();
|
|
|
|
+ $res=array();
|
|
|
|
+ if($list){
|
|
|
|
+ foreach ($list as $k => $v){
|
|
|
|
+ $arr['message_id'] = $v['id'];
|
|
|
|
+ $arr['user_id'] = $post['user_id'];
|
|
|
|
+ $arr['addtime']=time();
|
|
|
|
+ $res[] = $arr;
|
|
|
|
+ };
|
|
|
|
+ $num = 100;//每次导入条数
|
|
|
|
+ $limit = ceil(count($res)/$num);
|
|
|
|
+ for($i=1;$i<=$limit;$i++){
|
|
|
|
+ $offset=($i-1)*$num;
|
|
|
|
+ $data=array_slice($res,$offset,$num);
|
|
|
|
+ Db::name('message_read')->insertAll($data);
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ $this->success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|