Przeglądaj źródła

推送到每台登录账号的手机

locky 3 lat temu
rodzic
commit
fa8a28d147
1 zmienionych plików z 47 dodań i 45 usunięć
  1. 47 45
      Controller/gatewayController.py

+ 47 - 45
Controller/gatewayController.py

@@ -101,51 +101,53 @@ class GatewayView(View):
                     'nickname': nickname,
                 }
 
-                user_id = gateway_push_qs[0]['user_id']
-                app_bundle_id = gateway_push_qs[0]['app_bundle_id']
-                push_type = gateway_push_qs[0]['push_type']
-                token_val = gateway_push_qs[0]['token_val']
-                lang = gateway_push_qs[0]['lang']
-                tz = gateway_push_qs[0]['tz'] if gateway_push_qs[0]['tz'] else 0
-
-                # 获取推送所需数据
-                msg_title = GatewayPushService.get_msg_title(app_bundle_id, nickname)
-                msg_text = GatewayPushService.get_msg_text(n_time, tz, lang, alarm)
-
-                kwargs['msg_title'] = msg_title
-                kwargs['msg_text'] = msg_text
-                kwargs['app_bundle_id'] = app_bundle_id
-                kwargs['token_val'] = token_val
-
-                try:
-                    # 推送消息
-                    if push_type == 0:  # ios apns
-                        GatewayPushService.ios_apns_push(**kwargs)
-                    elif push_type == 1:  # android gcm
-                        GatewayPushService.android_fcm_push(**kwargs)
-                    elif push_type == 2:  # android 极光推送
-                        GatewayPushService.android_jpush(**kwargs)
-                except Exception as e:
-                    logger.info('网关推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
-                    continue
-
-                # 组织存储数据
-                local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=0, lang='cn')[:10]
-                equipment_info_list.append(EquipmentInfoService.get_equipment_info_obj(
-                    local_date_time,
-                    add_time=n_time,
-                    event_time=n_time,
-                    receive_time=n_time,
-                    device_uid=serial_number,
-                    device_nick_name=nickname,
-                    alarm=alarm,
-                    event_type=event_type,
-                    device_user_id=user_id,
-                ))
-            if equipment_info_list:
-                # 根据日期获得星期几
-                week = LocalDateTimeUtil.date_to_week(local_date_time)
-                EquipmentInfoService.equipment_info_bulk_create(week, equipment_info_list)
+                # 推送到每台登录账号的手机
+                for gateway_push in gateway_push_qs:
+                    user_id = gateway_push['user_id']
+                    app_bundle_id = gateway_push['app_bundle_id']
+                    push_type = gateway_push['push_type']
+                    token_val = gateway_push['token_val']
+                    lang = gateway_push['lang']
+                    tz = gateway_push['tz'] if gateway_push['tz'] else 0
+
+                    # 获取推送所需数据
+                    msg_title = GatewayPushService.get_msg_title(app_bundle_id, nickname)
+                    msg_text = GatewayPushService.get_msg_text(n_time, tz, lang, alarm)
+
+                    kwargs['msg_title'] = msg_title
+                    kwargs['msg_text'] = msg_text
+                    kwargs['app_bundle_id'] = app_bundle_id
+                    kwargs['token_val'] = token_val
+
+                    try:
+                        # 推送消息
+                        if push_type == 0:  # ios apns
+                            GatewayPushService.ios_apns_push(**kwargs)
+                        elif push_type == 1:  # android gcm
+                            GatewayPushService.android_fcm_push(**kwargs)
+                        elif push_type == 2:  # android 极光推送
+                            GatewayPushService.android_jpush(**kwargs)
+                    except Exception as e:
+                        logger.info('网关推送消息异常,errLine:{}, errMsg:{}'.format(e.__traceback__.tb_lineno, repr(e)))
+                        continue
+
+                    # 组织存储数据
+                    local_date_time = CommonService.get_now_time_str(n_time=n_time, tz=0, lang='cn')[:10]
+                    equipment_info_list.append(EquipmentInfoService.get_equipment_info_obj(
+                        local_date_time,
+                        add_time=n_time,
+                        event_time=n_time,
+                        receive_time=n_time,
+                        device_uid=serial_number,
+                        device_nick_name=nickname,
+                        alarm=alarm,
+                        event_type=event_type,
+                        device_user_id=user_id,
+                    ))
+                if equipment_info_list:
+                    # 根据日期获得星期几
+                    week = LocalDateTimeUtil.date_to_week(local_date_time)
+                    EquipmentInfoService.equipment_info_bulk_create(week, equipment_info_list)
             return response.json(0)
         except Exception as e:
             logger.info('---网关推送接口异常--- {}'.format(repr(e)))