2 Commits ead8d9ce7a ... 39606212a3

Tác giả SHA1 Thông báo Ngày
  fcy 39606212a3 Merge branch 'master' of http://git.nanodreamtech.com/dream/fipres 3 năm trước cách đây
  fcy b1802ef407 44 3 năm trước cách đây

+ 44 - 52
application/web/controller/IndexController.php

@@ -8,13 +8,9 @@ use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Style\Alignment;
 use PhpOffice\PhpSpreadsheet\Style\Border;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
-use \IGeTui,\IGtAppMessage,\IGtNotificationTemplate;
-//产品类
-define('APPKEY','hWPSNCBrnU6nk1SOLjZF67');
-define('APPID','xpoTHGLgyQ6ykBzyv42dt1');
-define('MASTERSECRET','aoY8L0SYeW8ofcV71W7097');
-define('CID','dd25afb14fa2485fcf050b5dbac482b3');
-define('HOST',"http://api.getui.com/apiex.htm");
+use MobTech\MobPush\Config\MobPushConfig;
+use MobTech\MobPush\Client\Push\PushV3Client;
+
 /**
  * @author lyuis
  *    小程序首页相应功能类
@@ -478,6 +474,7 @@ class IndexController extends MainController
     public function dataDetails()
     {
         $page = $this->request->param('page');
+        $index = $this->request->param('index',0);
         $ALARMENDTIME = $this->request->param('ALARMENDTIME');//结束时间
         $ALARMSTARTTIME = $this->request->param('ALARMSTARTTIME');//开始时间
         $PRIMARYADDR = $this->request->param('PRIMARYADDR');//中继器ID
@@ -500,14 +497,14 @@ class IndexController extends MainController
             ->join('deviceinfo d', 're.DEVICEID=d.DEVICEID and re.PRIMARYADDR=d.PRIMARYADDR', 'left')
             ->field('d.*,re.ALARMSTARTTIME,re.ALARMENDTIME,re.REPORTINFO,re.STATIONNAME,rt.STATUS')
             ->order('ALARMSTARTTIME desc')
-            ->page($page, $this->pages)
+            //->page($page, $this->pages)
             ->select();
         //$arr = array(1 => '80℃', 2 => '100℃', 3 => '130℃');
         $arrt = array(1 => 80, 2 => 100, 3 => 130);
         $sta = array('在线', '报警', '不在线', '未配置');
         $xAxis=$yValue=array();
         foreach ($dataDetails as $k => &$v) {
-            if($k==0){
+            if($k==$index){
                 $TEMPERTHRESHOLD=empty($v['TEMPERTHRESHOLD'])?0:$arrt[$v['TEMPERTHRESHOLD']];
                 if(!empty($v['ALARMSTARTTIME'])) {
                     array_push($xAxis, date('H:i:s',strtotime($v['ALARMSTARTTIME'])));
@@ -544,57 +541,52 @@ class IndexController extends MainController
     
     //自动报警
     public function autoBaojing(){
-    	$realtimedata=Db::table('realtimedata')->where(array('STATUS'=>1))->field('LASTTRANSDATE')->order('LASTTRANSDATE desc')->find();
-    	if(!empty($realtimedata['LASTTRANSDATE'])&&strtotime($realtimedata['LASTTRANSDATE'])>time()-10){
-    		$res=$this->sendPush();
-    		var_dump($res);
+    	$where=array(array('ALARMENDTIME','=',''));//array('ALARMSTARTTIME','gt',date('Y-m-d').' 00:00:00')
+    	$realtimedata=Db::table('reportdata')->where($where)->select();
+    	foreach($realtimedata as $val){
+    		$PID=$val['PRIMARYADDR'];
+    		$res=Db::table('primarydev_user')->alias('l')
+    		->join('mobpush m','m.user_id=l.UID','left')
+    		->where(array('l.PID'=>$PID))
+    		->column('m.reg_id');
+    		foreach($res as $k=>$v)
+    			if(empty($v)) 
+    			 unset($res[$k]);
+    		$admin_reg_id=Db::table('mobpush')->where(array('user_id'=>1))->column('reg_id');
+    		$res=array_merge($admin_reg_id,$res);
+    		if(!empty($res)){
+    			$this->sendPush($res);
+    		}
     	}
     	echo 'ok';
     }
     
+    public function recordRegId(){
+    	$reg_id = $this->request->param('reg_id','');
+    	if(empty($this->userid))
+    		$this->api_return_json(array('msg'=>'登录过期'));
+    	if(empty($reg_id))
+    		$this->api_return_json(array('msg'=>'no'),1);
+    	$res=Db::table('mobpush')->where(array('user_id'=>$this->userid,'reg_id'=>$reg_id))->find();
+    	if(empty($res))
+    		Db::table('mobpush')->insert(array('reg_id'=>$reg_id,'user_id'=>$this->userid));
+    	$this->api_return_json(array('msg'=>'ok'),1);
+    }
+    function pushtest(){
+    	$this->sendPush(['65kykswdtgny41s','65kykt1a27wv3ls']);
+    }
     //消息推送
-    public function sendPush(){
-    	$igt = new IGeTui(HOST,APPKEY,MASTERSECRET);
-    	// STEP2:选择通知模板
-    	//定义透传模板,设置透传内容,和收到消息是否立即启动启用
-    	$template = $this->IGtNotificationTemplateDemo();
-    	// STEP5:定义"AppMessage"类型消息对象,设置消息内容模板、发送的目标App列表、是否支持离线发送、以及离线消息有效期(单位毫秒)
-    	$message = new IGtAppMessage();
-    	$message->set_isOffline(true);
-    	$message->set_offlineExpireTime(10 * 60 * 1000);//离线时间单位为毫秒,例,两个小时离线为3600*1000*2
-    	$message->set_data($template);
-    	
-    	$appIdList=array(APPID);
-    	// $phoneTypeList=array('ANDROID');
-    	// $provinceList=array('浙江');
-    	// $tagList=array('haha');
-    	
-    	$message->set_appIdList($appIdList);
-    	//$message->set_conditions($cdt->getCondition());
-    	// STEP6:执行推送
-    	$rep = $igt->pushMessageToApp($message,"任务组名");
-    	
+    public function sendPush($reg_id){
+    	$mobPushConfig = new MobPushConfig();
+    	$mobPushConfig::$appkey = '31c1fc57d33bf';
+    	$mobPushConfig::$appSecret = '754bac00d98fbcfaaf1dc77277e9ee27';
+    	$pushV3Client=new PushV3Client();
+    	/* Registration ID推送 */
+    	$rep=$pushV3Client->pushByRids('', '报警通知', 'FIPRES 收到报警
+信息一条,请前往查看', $reg_id);
     	return $rep;
     } 
     
-    private function IGtNotificationTemplateDemo(){
-    	$template =  new IGtNotificationTemplate();
-    	$template->set_appId(APPID);                   //应用appid
-    	$template->set_appkey(APPKEY);                 //应用appkey
-    	$template->set_transmissionType(1);            //透传消息类型
-    	$template->set_transmissionContent("测试离线");//透传内容
-    	// STEP3:设置推送标题、推送内容
-    	$template->set_title("温度报警通知");      //通知栏标题
-    	$template->set_text("FIPRES收到报警信息一条,请前往查看 ".date('H:i:s'));     //通知栏内容
-    	$template->set_logo("");                       //通知栏logo
-    	$template->set_logoURL("");                    //通知栏logo链接
-    	//STEP4:设置响铃、震动等推送效果
-    	$template->set_isRing(true);                   //是否响铃
-    	$template->set_isVibrate(true);                //是否震动
-    	$template->set_isClearable(true);              //通知栏是否可清除
-    
-    	return $template;
-    }
 }
 
 

+ 1 - 1
application/web/controller/UserController.php

@@ -209,7 +209,7 @@ class UserController extends MainController
             }
         }
         $token = JWT::getToken($id, $this->major);
-        $this->api_return_json(array('msg' => '登录成功', 'sid' => $token), 1);
+        $this->api_return_json(array('msg' => '登录成功', 'sid' => $token,'user_id'=>$id,'username'=>$username), 1);
     }
 
     public function register()

+ 2 - 1
composer.json

@@ -20,7 +20,8 @@
         "topthink/framework": "5.1.*",
         "firebase/php-jwt": "^5.2",
         "phpoffice/phpspreadsheet": "^1.14",
-        "getuilaboratory/getui-pushapi-php-client": "dev-master"
+        "getuilaboratory/getui-pushapi-php-client": "dev-master",
+        "mob/mobpush": "^2.0"
     },
     "autoload": {
         "psr-4": {

+ 48 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "484e502598b4a8872b6268f44b441a18",
+    "content-hash": "bd1809792a8a30f54fe917abec3b5e06",
     "packages": [
         {
             "name": "firebase/php-jwt",
@@ -352,6 +352,53 @@
             ],
             "time": "2020-08-28T17:11:00+00:00"
         },
+        {
+            "name": "mob/mobpush",
+            "version": "v2.0.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/MobClub/mobpush-websdkv3-php.git",
+                "reference": "2b9b450839addbfd9c8367b920d2b5abc3b1aa8b"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/MobClub/mobpush-websdkv3-php/zipball/2b9b450839addbfd9c8367b920d2b5abc3b1aa8b",
+                "reference": "2b9b450839addbfd9c8367b920d2b5abc3b1aa8b",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^9.2"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "MobTech\\MobPush\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "mob",
+                    "email": "mob@yoozoo.com"
+                }
+            ],
+            "description": "MobPush WebSDK",
+            "keywords": [
+                "mob",
+                "mobpush",
+                "mobtech"
+            ],
+            "time": "2020-09-23T10:57:46+00:00"
+        },
         {
             "name": "myclabs/php-enum",
             "version": "1.7.7",