From 17355977e81bb1f93862b5201424f60af9d093cf Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期六, 05 十二月 2020 16:21:44 +0800 Subject: [PATCH] 2020-12-05 1.增加苹果推送处理。2.暂时通过推送实现,增加挤下线功能。 --- HDL_ON/DAL/Server/NewApiRes.cs | 24 ++ HDL_ON/Common/HDLCommon.cs | 93 ++++++++++ HDL_ON/DAL/Server/HttpUtil.cs | 3 .vs/HDL_APP_Project/xs/UserPrefs.xml | 38 +-- HDL-ON_iOS/AppDelegate.cs | 202 ++++++++-------------- HDL-ON_Android/Other/JPush/JPushReceiver.cs | 147 ++++++++-------- 6 files changed, 282 insertions(+), 225 deletions(-) diff --git a/.vs/HDL_APP_Project/xs/UserPrefs.xml b/.vs/HDL_APP_Project/xs/UserPrefs.xml index 0ca1a30..089dc0a 100644 --- a/.vs/HDL_APP_Project/xs/UserPrefs.xml +++ b/.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> diff --git a/HDL-ON_Android/Other/JPush/JPushReceiver.cs b/HDL-ON_Android/Other/JPush/JPushReceiver.cs index 61b99f9..f24b091 100644 --- a/HDL-ON_Android/Other/JPush/JPushReceiver.cs +++ b/HDL-ON_Android/Other/JPush/JPushReceiver.cs @@ -1,17 +1,9 @@ -锘縰sing 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; - } - + } } } diff --git a/HDL-ON_iOS/AppDelegate.cs b/HDL-ON_iOS/AppDelegate.cs index 3728f8d..652593e 100644 --- a/HDL-ON_iOS/AppDelegate.cs +++ b/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 @@ } + } diff --git a/HDL_ON/Common/HDLCommon.cs b/HDL_ON/Common/HDLCommon.cs index 111a589..3bacd32 100644 --- a/HDL_ON/Common/HDLCommon.cs +++ b/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 } } diff --git a/HDL_ON/DAL/Server/HttpUtil.cs b/HDL_ON/DAL/Server/HttpUtil.cs index 0e405b0..84a5333 100644 --- a/HDL_ON/DAL/Server/HttpUtil.cs +++ b/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> diff --git a/HDL_ON/DAL/Server/NewApiRes.cs b/HDL_ON/DAL/Server/NewApiRes.cs index 80a2ac7..1f277dd 100644 --- a/HDL_ON/DAL/Server/NewApiRes.cs +++ b/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> -- Gitblit v1.8.0