2020-12-05 1.增加苹果推送处理。2.暂时通过推送实现,增加挤下线功能。
6个文件已修改
507 ■■■■■ 已修改文件
.vs/HDL_APP_Project/xs/UserPrefs.xml 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL-ON_Android/Other/JPush/JPushReceiver.cs 147 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL-ON_iOS/AppDelegate.cs 202 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/Common/HDLCommon.cs 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/DAL/Server/HttpUtil.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDL_ON/DAL/Server/NewApiRes.cs 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.vs/HDL_APP_Project/xs/UserPrefs.xml
@@ -1,14 +1,16 @@
<Properties StartupConfiguration="{09712674-2A38-407B-B1E2-560B2C352F9A}|Default">
<Properties StartupConfiguration="{D998E133-F0DD-4760-BE3C-461632F54DA4}|Default">
  <MonoDevelop.Ide.ItemProperties.HDL-ON__iOS PreferredExecutionTarget="MonoDevelop.IPhone.IPhoneDeviceTarget.00008030-00014C392121802E" />
  <MonoDevelop.Ide.Workbench ActiveDocument="HDL-ON_iOS/AppDelegate.cs">
  <MonoDevelop.Ide.Workbench ActiveDocument="HDL-ON_iOS/ViewController.cs">
    <Files>
      <File FileName="HDL_ON/DAL/Server/HttpServerRequest.cs" Line="985" Column="1" />
      <File FileName="HDL-ON_Android/Application.cs" Line="137" Column="38" />
      <File FileName="HDL-ON_Android/JPush.cs" Line="1" Column="1" />
      <File FileName="HDL-ON_Android/Other/JPush/JPushReceiver.cs" Line="28" Column="34" />
      <File FileName="HDL-ON_Android/Other/JPush/JPushService.cs" Line="11" Column="2" />
      <File FileName="HDL-ON_Android/Properties/AndroidManifest.xml" />
      <File FileName="HDL-ON_iOS/AppDelegate.cs" Line="109" Column="34" />
      <File FileName="HDL_ON/DAL/Server/HttpServerRequest.cs" Line="920" Column="77" />
      <File FileName="HDL_ON/UI/UI1-Login/LoginPage.cs" Line="1" Column="1" />
      <File FileName="HDL_ON/UI/UI2/4-PersonalCenter/PersonalDataPageBLL.cs" Line="81" Column="10" />
      <File FileName="HDL_ON/UI/MainPage.cs" Line="79" Column="32" />
      <File FileName="HDL_ON/Common/HDLCommon.cs" Line="309" Column="21" />
      <File FileName="HDL-ON_iOS/AppDelegate.cs" Line="216" Column="27" />
      <File FileName="HDL_ON/DAL/Server/NewAPI.cs" Line="179" Column="55" />
      <File FileName="HDL_ON/DAL/Server/NewApiRes.cs" Line="1023" Column="6" />
      <File FileName="HDL-ON_iOS/ViewController.cs" Line="38" Column="21" />
    </Files>
    <Pads>
      <Pad Id="ProjectPad">
@@ -17,23 +19,17 @@
            <Node name="HDL_ON" expanded="True">
              <Node name="Common" expanded="True" />
              <Node name="DAL" expanded="True">
                <Node name="DriverLayer" expanded="True" />
                <Node name="Server" expanded="True" />
              </Node>
              <Node name="Entity" expanded="True" />
              <Node name="UI" expanded="True" />
            </Node>
            <Node name="HDL-ON_Android" expanded="True">
              <Node name="Other" expanded="True">
                <Node name="JPush" expanded="True" />
              </Node>
              <Node name="Properties" expanded="True" />
              <Node name="Resources" expanded="True">
                <Node name="values" expanded="True" />
              <Node name="UI" expanded="True">
                <Node name="UI1-Login" expanded="True" />
                <Node name="UI2" expanded="True">
                  <Node name="4-PersonalCenter" expanded="True" />
                </Node>
              </Node>
            </Node>
            <Node name="HDL-ON_iOS" expanded="True">
              <Node name="AppDelegate.cs" selected="True" />
              <Node name="ViewController.cs" selected="True" />
            </Node>
          </Node>
        </State>
HDL-ON_Android/Other/JPush/JPushReceiver.cs
@@ -1,17 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;

using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using CN.Jpush.Android.Api;
using CN.Jpush.Android.Service;
using HDL_ON;
using HDL_ON.DAL.Server;
using Shared;
namespace HDL_ON_Android
@@ -40,11 +32,7 @@
        {
            base.OnNotifyMessageOpened(context, notificationMessage);
            //App.Paras = p1.NotificationExtras;
            //Utlis.ShowTip("收到推送:" + p1.NotificationExtras);
            Utlis.WriteLine("极光OnNotifyMessageOpened: " + notificationMessage.NotificationContent);
            Utlis.WriteLine("极光OnNotifyMessageOpened: " + notificationMessage.NotificationExtras);
            OpenNotification(context, notificationMessage);
        }
        /// <summary>
@@ -55,8 +43,18 @@
        public override void OnNotifyMessageArrived(Context context, NotificationMessage notificationMessage)
        {
            base.OnNotifyMessageArrived(context, notificationMessage);
            Utlis.WriteLine("极光OnNotifyMessageArrived: " + notificationMessage.NotificationContent);
            Utlis.WriteLine("极光OnNotifyMessageArrived: " + notificationMessage.NotificationExtras);
            var pushMes = new JPushMessageInfo()
            {
                Title = notificationMessage.NotificationTitle,
                Content = notificationMessage.NotificationContent,
                Extras = notificationMessage.NotificationExtras
            };
            System.Console.WriteLine("PushMes title : " + pushMes.Title);
            System.Console.WriteLine("PushMes message : " + pushMes.Content);
            System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
            HDLCommon.Current.AdjustPushMessage(pushMes);
        }
        /// <summary>
@@ -72,76 +70,81 @@
        }
        ///// <summary>
        ///// 收到自定义消息回调
        ///// 处理极光信息推送
        ///// </summary>
        ///// <param name="p0"></param>
        ///// <param name="p1"></param>
        //public override void OnMessage(Context p0, CustomMessage p1)
        ///// <param name="title">标题</param>
        ///// <param name="message">信息</param>
        ///// <param name="extras">负载数据</param>
        //public void AdjustJiguangMsgPush(JPushMessageInfo JPushMessageInfo)
        //{
        //    base.OnMessage(p0, p1);
        //    try
        //    {
        //    Utlis.WriteLine("极光OnMessage: " + p1.Message.ToString());
        //        if (JPushMessageInfo.Extras.Contains("Offline") == true)
        //        {
        //            Shared.Application.RunOnMainThread(() =>
        //            {
        //                //账号在别处登陆,被踢下线 跳转到登录页面
        //                new Alert(Language.StringByID(StringId.Tip), Language.StringByID(StringId.LoggedOnOtherDevices), Language.StringByID(StringId.Close)).Show();
        //                //2020-12-04 待增加退出登录操作
        //            });
        //            return;
        //        }
        //        else
        //        {
        //            Shared.Application.RunOnMainThread(() =>
        //            {
        //                new Alert(JPushMessageInfo.Title, JPushMessageInfo.Content, Language.StringByID(StringId.Close)).Show();
        //            });
        //            return;
        //        }
        //    }
        //    catch
        //    {
        //    }
        //}
        /// <summary>
        /// 处理极光信息推送
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="message">信息</param>
        /// <param name="extras">负载数据</param>
        public void AdjustJiguangMsgPush(NotificationMessage notificationMessage)
        {
            string title = notificationMessage.NotificationTitle;
            System.Console.WriteLine(TAG, " title : " + title);
            string message = notificationMessage.NotificationContent;
            System.Console.WriteLine(TAG, "message : " + message);
            string extras = notificationMessage.NotificationExtras;
            System.Console.WriteLine(TAG, "extras : " + extras);
            if (extras.Contains("Offline") == true)
            {
                Shared.Application.RunOnMainThread(() =>
                {
                    //此帐号已在别处登录,您被迫下线
                    //ShowAlert("此帐号已在别处登录,您被迫下线");
                    //账号在别处登陆,被踢下线 跳转到登录页面
                    HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
                });
                return;
            }
        }
        /// <summary>
        /// 打开消息显示界面
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="bundle">Bundle.</param>
        private void OpenNotification(Context context, Bundle bundle)
        /// <param name="context"></param>
        /// <param name="notificationMessage"></param>
        private void OpenNotification(Context context, NotificationMessage notificationMessage)
        {
            Intent i = new Intent(context, typeof(BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
            i.PutExtras(bundle);
            i.SetFlags(ActivityFlags.NewTask);
            context.StartActivity(i);
            String extras = bundle.GetString(JPushInterface.ExtraExtra);
            //String myValue = "";
            try
            {
                var pushMes = new JPushMessageInfo()
                {
                    Title = notificationMessage.NotificationTitle,
                    Content = notificationMessage.NotificationContent,
                    Extras = notificationMessage.NotificationExtras
                };
                System.Console.WriteLine("PushMes title : " + pushMes.Title);
                System.Console.WriteLine("PushMes message : " + pushMes.Content);
                System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
                if (Shared.Application.Activity == null)
                {
                    var tempIntent = new Intent(context, typeof(Shared.BaseActivity));//Intent intent=new Intent( 起始组件对象 , 目标 Service.class);
                    tempIntent.SetFlags(ActivityFlags.BroughtToFront);
                    context.StartActivity(tempIntent);
                    HDLCommon.Current.AdjustPushMessage(pushMes);
                }
                else
                {
                    (Shared.Application.Activity as BaseActivity).MoveToFront();
                    HDLCommon.Current.AdjustPushMessage(pushMes);
                }
            }
            catch (Exception e)
            catch
            {
                System.Console.WriteLine("JPush", "Unexpected: extras is not a valid json", e);
                return;
            }
            }
        }
    }
    
HDL-ON_iOS/AppDelegate.cs
@@ -8,6 +8,7 @@
using Microsoft.AppCenter.Analytics;
using Microsoft.AppCenter.Crashes;
using HDL_ON.UI;
using HDL_ON.DAL.Server;
namespace SharedMethod
{
@@ -34,6 +35,7 @@
        //}
    }
}
namespace HDL_ON_iOS
@@ -128,89 +130,13 @@
            if (application.ApplicationState == UIApplicationState.Active || application.ApplicationState == UIApplicationState.Background)
            {
                NSString key_hiddenJson = new NSString("HiddenJson");
                if (userInfo.ContainsKey(key_hiddenJson))
                {
                    var hiddenJson = userInfo["HiddenJson"].ToString();
                    if (string.IsNullOrEmpty(hiddenJson))
                    {
                        return;
                    }
                    if (hiddenJson.Contains("cmtID"))
                    {
                        /////目前根据这个判断是否是可视对讲数据
                        //VideoMethod(hiddenJson);
                    }
                    else
                    {
                        NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
                        if (hiddenJsonDic == null)
                        {
                            return;
                        }
                        NSString key_Offline = new NSString("Offline");
                        if (hiddenJsonDic.ContainsKey(key_Offline))
                        {
                            string signOut = hiddenJsonDic["Offline"].ToString();
                            if (signOut == "0")
                            {
                                //不下线
                            }
                            else
                            {
                                //强制下线
                                //CommonPage.Instance.SingOut();
                                HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
                            }
                        }
                    }
                }
                HandleNotificationMessageUserInfo(userInfo, false);
            }
            else
            {
                NSString key_hiddenJson = new NSString("HiddenJson");
                if (userInfo.ContainsKey(key_hiddenJson))
                {
                    var hiddenJson = userInfo["HiddenJson"].ToString();
                    if (string.IsNullOrEmpty(hiddenJson))
                    {
                        return;
                    }
                    if (hiddenJson.Contains("cmtID"))
                    {
                        /////目前根据这个判断是否是可视对讲数据
                        //VideoMethod(hiddenJson);
                    }
                    else
                    {
                        NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
                        if (hiddenJsonDic == null)
                        {
                            return;
                        }
                        NSString key_Offline = new NSString("Offline");
                        if (hiddenJsonDic.ContainsKey(key_Offline))
                        {
                            string signOut = hiddenJsonDic["Offline"].ToString();
                            if (signOut == "0")
                            {
                                //不下线
                            }
                            else
                            {
                                //标记下线
                                haveToSignOut = true;
                            }
                        }
                    }
                }
                //Inactive
                HandleNotificationMessageUserInfo(userInfo, false);
            }
            completionHandler(UIBackgroundFetchResult.NewData);
@@ -269,12 +195,14 @@
            Console.WriteLine("OnActivated");
            base.OnActivated(application);
            if (haveToSignOut == true)
            {
                //强制下线
                //CommonPage.Instance.SingOut();
                HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
            }
            //if (haveToSignOut == true)
            //{
                ////强制下线
                //UserInfo.Current.LastTime = DateTime.MinValue;
                //UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//重置用户头像
                //UserInfo.Current.SaveUserInfo();
                //HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
            //}
        }
@@ -342,64 +270,79 @@
        }
        /// <summary>
        /// 退出登录标记
        /// 处理通知消息
        /// </summary>
        bool haveToSignOut;
        void HandleNotificationMessageUserInfo(NSDictionary userInfo, bool bFinishedLaunching)
        {
            try
            {
                if (userInfo.ContainsKey(new NSString("aps")))
                {
                    var aps = userInfo["aps"] as NSDictionary;
                    var alert = aps["alert"] as NSDictionary;
                    var body = alert["body"] as NSString;
                    var title = alert["title"] as NSString;
                    var expandData = "";
                    if (userInfo.ContainsKey(new NSString("expandData")))
                    {
                        expandData = userInfo["expandData"] as NSString;
                    }
                    var pushMes = new JPushMessageInfo()
                    {
                        Title = title,
                        Content = body,
                        Extras = expandData,
                    };
                    System.Console.WriteLine("PushMes title : " + pushMes.Title);
                    System.Console.WriteLine("PushMes message : " + pushMes.Content);
                    System.Console.WriteLine("PushMes extras : " + pushMes.Extras);
                    if (bFinishedLaunching)
                    {
                        if (pushMes.Extras != null && pushMes.Extras.Contains("Offline"))
                        {
                            //haveToSignOut = true;
                            //强制下线
                            UserInfo.Current.LastTime = DateTime.MinValue;
                            UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//重置用户头像
                            UserInfo.Current.SaveUserInfo();
                            HDLCommon.Current.ShowAlert(Language.StringByID(StringId.LoggedOnOtherDevices));
                        }
                    }
                    else
                    {
                        HDLCommon.Current.AdjustPushMessage(pushMes);
                    }
                }
            }
            catch
            {
            }
        }
        ///// <summary>
        ///// 退出登录标记
        ///// </summary>
        //bool haveToSignOut;
        /// <summary>
        /// 处理通知
        /// 启动APP 处理通知
        /// </summary>
        /// <param name="launchOptions"></param>
        void DealWithPushMes(NSDictionary launchOptions)
        {
            haveToSignOut = false;
            //haveToSignOut = false;
            if (launchOptions != null)
            {
                // check for a remote notification
                if (launchOptions.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
                {
                    NSDictionary userInfo = launchOptions[UIApplication.LaunchOptionsRemoteNotificationKey] as NSDictionary;
                    if (userInfo != null)
                    {
                        NSString key_hiddenJson = new NSString("HiddenJson");
                        if (userInfo.ContainsKey(key_hiddenJson))
                        {
                            var hiddenJson = userInfo["HiddenJson"].ToString();
                            if (!string.IsNullOrEmpty(hiddenJson))
                            {
                                if (hiddenJson.Contains("cmtID"))
                                {
                                    ///目前根据这个判断是否是可视对讲数据
                                    // VideoMethod(hiddenJson);
                                }
                                else
                                {
                                    NSDictionary hiddenJsonDic = userInfo["HiddenJson"] as NSDictionary;
                                    if (hiddenJsonDic != null)
                                    {
                                        NSString key_Offline = new NSString("Offline");
                                        if (hiddenJsonDic.ContainsKey(key_Offline))
                                        {
                                            string signOut = hiddenJsonDic["Offline"].ToString();
                                            if (signOut == "0")
                                            {
                                                //不下线
                                            }
                                            else
                                            {
                                                //标记下线
                                                haveToSignOut = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        HandleNotificationMessageUserInfo(userInfo, true);
                    }
                }
@@ -409,5 +352,6 @@
    }
}
HDL_ON/Common/HDLCommon.cs
@@ -4,6 +4,7 @@
using HDL_ON.UI.CSS;
using HDL_ON.DAL.Server;
using HDL_ON.UI;
using HDL_ON.Entity;
namespace HDL_ON
{
@@ -237,7 +238,99 @@
            }
        }
        #region 推送处理
        /// <summary>
        /// 推送消息处理
        /// </summary>
        /// <param name="jpushMessageInfo"></param>
        public void AdjustPushMessage(JPushMessageInfo jpushMessageInfo)
        {
            try
            {
                if (jpushMessageInfo.Extras != null && jpushMessageInfo.Extras.Contains("Offline"))
                {
                    Shared.Application.RunOnMainThread(() =>
                    {
                        //账号在别处登陆,被踢下线 跳转到登录页面
                        new Alert(Language.StringByID(StringId.Tip), Language.StringByID(StringId.LoggedOnOtherDevices), Language.StringByID(StringId.Close)).Show();
                        //2020-12-04 待增加退出登录操作
                        Logout();
                    });
                    return;
                }
                else
                {
                    Shared.Application.RunOnMainThread(() =>
                    {
                        new Alert(jpushMessageInfo.Title, jpushMessageInfo.Content, Language.StringByID(StringId.Close)).Show();
                    });
                    return;
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// 退出登录操作
        /// </summary>
        public void Logout()
        {
            try
            {
                Shared.Application.RunOnMainThread(() =>
                {
                    #region 保存本地数据至文件夹
                    string oldRegionRootPath = FileUtils.CreateRegionBackup(DB_ResidenceData.residenceData.CurReginID.ToString());
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            var backuplist = FileUtils.ReadFiles();
                            FileUtils.DeleteRegionFiles(oldRegionRootPath);
                            //移动文件
                            foreach (var fileName in backuplist)
                            {
                                System.IO.FileInfo fileInfo = new System.IO.FileInfo(FileUtils.RootPath + fileName);
                                if (fileInfo.Exists)
                                {
                                    fileInfo.MoveTo(oldRegionRootPath + fileName);
                                    MainPage.Log("move file : " + fileName);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"xxx:{ex.Message}");
                        }
                        finally
                        {
                            FileUtils.DeleteAllFile();
                        }
                    }).Start();
                    #endregion
                    ////2.注销推送
                    new HttpServerRequest().SignOutPush();
                    //3.跳转登录页面
                    UserInfo.Current.LastTime = DateTime.MinValue;
                    UserInfo.Current.headImagePagePath = "LoginIcon/2.png";//重置用户头像
                    UserInfo.Current.SaveUserInfo();
                    MainPage.GoLoginPage(UserInfo.Current);
                    DB_ResidenceData.residenceData.EixtAccount();
                });
            }
            catch (Exception ex)
            {
                MainPage.Log($"xxx:{ex.Message}");
            }
        }
        #endregion
    }
}
HDL_ON/DAL/Server/HttpUtil.cs
@@ -470,7 +470,8 @@
        static string GetTimestamp()
        {
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            return ((long)(DateTime.Now - startTime).TotalSeconds).ToString(); // 相差秒数
            return ((long)(DateTime.Now - startTime).TotalMilliseconds).ToString(); // 相差秒数
            //return ((long)(DateTime.Now - startTime).TotalSeconds).ToString(); // 相差秒数
        }
        /// <summary>
HDL_ON/DAL/Server/NewApiRes.cs
@@ -1361,7 +1361,7 @@
    /// <summary>
    /// 上传图片
    /// </summary>
    ///  [System.Serializable]
    [System.Serializable]
    public class UploadImageObj
    {
        /// <summary>
@@ -1385,7 +1385,7 @@
    /// <summary>
    /// 查询图片路径
    /// </summary>
    ///  [System.Serializable]
    [System.Serializable]
    public class GetImageUrlObj
    {
        /// <summary>
@@ -1399,6 +1399,26 @@
    #endregion
    /// <summary>
    /// 极光推送消息
    /// </summary>
    [System.Serializable]
    public class JPushMessageInfo
    {
        /// <summary>
        /// 推送标题
        /// </summary>
        public string Title;
        /// <summary>
        /// 推送内容
        /// </summary>
        public string Content;
        /// <summary>
        /// 推送附加数据
        /// </summary>
        public string Extras;
    }
    //#region 旧接口
    ///// <summary>