|
@@ -55,7 +55,10 @@ class NoticeAction extends Action {
|
|
|
$conf->set('group.id', 'myConsumerGroup');
|
|
|
|
|
|
// Initial list of Kafka brokers(添加 kafka集群服务器地址)
|
|
|
- $conf->set('metadata.broker.list', '127.0.0.1');
|
|
|
+ if( !C('KAFKA_BROKER_LIST') ){
|
|
|
+ echo 'please set broker list !!! ';
|
|
|
+ }
|
|
|
+ $conf->set('metadata.broker.list', C('KAFKA_BROKER_LIST'));
|
|
|
|
|
|
$topicConf = new RdKafka\TopicConf();
|
|
|
|
|
@@ -79,9 +82,17 @@ class NoticeAction extends Action {
|
|
|
$msg_data = json_decode($message->payload,true);
|
|
|
if($msg_data){
|
|
|
// 使用极光推送消息
|
|
|
+ if(C('JPUSH_APP_KEY') || C('JPUSH_MASTER_SECRET')){
|
|
|
+ echo 'jpush app key or secret not exists',PHP_EOL;
|
|
|
+ break;
|
|
|
+ }
|
|
|
$jpush_client = new \JPush\Client( C('JPUSH_APP_KEY'), C('JPUSH_MASTER_SECRET') );
|
|
|
// 电子围栏告警,上锁车辆异动告警,低电量告警,被盗告警,广播消息推送
|
|
|
- $this->jpushMsg( $jpush_client, $msg_data );
|
|
|
+ $result = $this->jpushMsg( $jpush_client, $msg_data );
|
|
|
+ if($result){
|
|
|
+ echo $result['message'],PHP_EOL;
|
|
|
+ debug_log('jpush',$result['message']);
|
|
|
+ }
|
|
|
}
|
|
|
break;
|
|
|
case RD_KAFKA_RESP_ERR__PARTITION_EOF:
|
|
@@ -98,7 +109,7 @@ class NoticeAction extends Action {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function jpushMsg( $client, $msg_data ){
|
|
|
+ private function jpushMsg( $client, $msg_data ){
|
|
|
/*
|
|
|
$msg_data = '{
|
|
|
"type":2,
|
|
@@ -123,10 +134,8 @@ class NoticeAction extends Action {
|
|
|
C('FENCE_ALARM'), // 8-电子围栏告警
|
|
|
);
|
|
|
if(!is_array($msg_data)){
|
|
|
- echo 'invalid message data format!'.$msg_data . PHP_EOL;
|
|
|
- return;
|
|
|
+ return array( 'success' => false , 'message' => 'invalid message data format!'.$msg_data);
|
|
|
}
|
|
|
-
|
|
|
// 通过传过来的车牌查出 JgClientRegistrationId
|
|
|
if( empty($client) ){
|
|
|
$client = new \JPush\Client( C('JPUSH_APP_KEY'), C('JPUSH_MASTER_SECRET') );
|
|
@@ -137,24 +146,24 @@ class NoticeAction extends Action {
|
|
|
$last_alarm_time = S('last_fence_alarm_'.$msg_data['device_number']);
|
|
|
$interval_time = C('FENCE_ALARM_INTERVAL')*60;
|
|
|
if( time() - $last_alarm_time < $interval_time ){
|
|
|
- echo $msg_data['device_number'] . ' 围栏告警时间间隔:'.C('FENCE_ALARM_INTERVAL').'分钟,最后一次告警时间:'.$last_alarm_time . PHP_EOL;
|
|
|
- return;
|
|
|
+ return array( 'success' => false , 'message' => $msg_data['device_number'] . ' 围栏告警时间间隔:'.C('FENCE_ALARM_INTERVAL').'分钟,最后一次告警时间:'.$last_alarm_time );
|
|
|
}
|
|
|
}
|
|
|
// 取车辆数据
|
|
|
$where = array('DeviceNumber|GpsDeviceNumber' => $msg_data['device_number']);
|
|
|
$fields= 'CityId,LicensePlate,FullName,JgClientRegistrationId';
|
|
|
-
|
|
|
if( !S( 'jpush_vinfo_'.$msg_data['device_number'] ) ){ //如果不存在,则缓存
|
|
|
$vehicle_info = M('jms_vehicle')->field($fields)->where($where)->find();
|
|
|
S( 'jpush_vinfo_'.$msg_data['device_number'], $vehicle_info, 60 ); //缓存1分钟
|
|
|
}
|
|
|
$vehicle_info = S( 'jpush_vinfo_'.$msg_data['device_number'] ); //从缓存取
|
|
|
+ if(!$vehicle_info['JgClientRegistrationId']){
|
|
|
+ return array('success'=> false,'message'=>'jpush registration id not exists!');
|
|
|
+ }
|
|
|
}elseif( $msg_data['type'] == C('BROADCASTING') ){
|
|
|
//广播
|
|
|
}else{
|
|
|
- echo '未知的告警类型:'.$msg_data['type'].PHP_EOL;
|
|
|
- return;
|
|
|
+ return array( 'success' => false , 'message' => '未知的告警类型:'.$msg_data['type'] );
|
|
|
}
|
|
|
// 推送平台
|
|
|
$platform = array('ios', 'android');
|
|
@@ -203,13 +212,15 @@ class NoticeAction extends Action {
|
|
|
'code' => $response['http_code'],
|
|
|
'resp_msg' => 'ok',
|
|
|
);
|
|
|
- $this->saveLog($msg_data);
|
|
|
- print_r($response);
|
|
|
+ if(!$this->saveLog($msg_data)){
|
|
|
+ return array( 'success' => false , 'message' => 'add log failed 1' );
|
|
|
+ }
|
|
|
if( $response['http_code'] == 200 ){ //如果成功了
|
|
|
if( C('FENCE_ALARM_INTERVAL') && $msg_data['type'] == C('FENCE_ALARM') ){
|
|
|
//设置最后围栏告警时间缓存
|
|
|
S('last_fence_alarm_'.$msg_data['device_number'], time(), C('FENCE_ALARM_INTERVAL')*60);
|
|
|
}
|
|
|
+ return array( 'success' => true , 'message' => 'ok' );
|
|
|
}
|
|
|
} catch (\JPush\Exceptions\APIConnectionException $e) {
|
|
|
// try something here
|
|
@@ -217,7 +228,9 @@ class NoticeAction extends Action {
|
|
|
'code' => $e->getHttpCode(),
|
|
|
'resp_msg' => substr($e->__toString(), strpos($e->__toString(),'[')),
|
|
|
);
|
|
|
- $this->saveLog($msg_data);
|
|
|
+ if(!$this->saveLog($msg_data)){
|
|
|
+ return array( 'success' => false , 'message' => 'add log failed 2' );
|
|
|
+ }
|
|
|
print $e;
|
|
|
} catch (\JPush\Exceptions\APIRequestException $e) {
|
|
|
// try something here
|
|
@@ -225,13 +238,15 @@ class NoticeAction extends Action {
|
|
|
'code' => $e->getHttpCode(),
|
|
|
'resp_msg' => substr($e->__toString(), strpos($e->__toString(),'[')),
|
|
|
);
|
|
|
- $this->saveLog($msg_data);
|
|
|
+ if(!$this->saveLog($msg_data)){
|
|
|
+ return array( 'success' => false , 'message' => 'add log failed 3' );
|
|
|
+ }
|
|
|
print $e;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function saveLog( $msg_data ){
|
|
|
+ private function saveLog( $msg_data ){
|
|
|
$fdls_app_message = M('jms_baojing_message');
|
|
|
|
|
|
$log_data = array(
|