frmPersonalCenter.cs 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. using LYFZ.Software.MainBusiness.MicroApplet;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Text;
  7. namespace LYFZ.Software.MainBusiness.SelfService
  8. {
  9. public class frmPersonalCenter:LYFZ.Software.SelfService.frmPersonalCenter
  10. {
  11. frmAdminPage frmPage = null;
  12. string gotoUrl = "http://dear.lyfz.net/#/customer/center/product";
  13. public frmPersonalCenter()
  14. {
  15. this.UcNavigationTool.LabTitle = "自助中心";
  16. if (Environment.OSVersion.Version.Major >= 6)
  17. {
  18. try
  19. {
  20. frmPage = new frmAdminPage();
  21. this.btnRefresh.Click += btnRefresh_Click;
  22. this.frmPage.ContextMenuHandler.RunContextMenu += ContextMenuHandler_RunContextMenu;
  23. this.Shown += FrmPersonalCenter_Shown;
  24. this.frmPage.LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd;
  25. this.frmPage.LoadHandler.OnLoadStart += LoadHandler_OnLoadStart;
  26. }
  27. catch
  28. {
  29. MessageBoxCustom.Show("您的系统不支持自助功能,请使用 Win7 或以上系统。");
  30. this.Enabled = false;
  31. }
  32. }
  33. else
  34. {
  35. MessageBoxCustom.Show("您的系统不支持自助序功能,请使用 Win7 或以上系统。");
  36. this.Enabled = false;
  37. }
  38. }
  39. private void FrmPersonalCenter_Shown(object sender, EventArgs e)
  40. {
  41. this.LoadMicroAppletPage(LYFZ.Software.MainBusiness.CommonLogical.SuccessfulLogin.SoftwareInfo.SDomainName);
  42. }
  43. void LoadMicroAppletPage(string dongleDomainName)
  44. {
  45. if (String.IsNullOrEmpty(tokenPermission))
  46. {
  47. LYFZ.ComponentLibrary.FrmLoadHandling.LoadDoWorkMethod(delegate (object obj, BackgroundWorker backgroundWorker)
  48. {
  49. try
  50. {
  51. backgroundWorker.ReportProgress(0, "正在验证授权...");
  52. //_ContentType: "form-data"
  53. if (!String.IsNullOrEmpty(dongleDomainName))
  54. {
  55. string timestamp = SDateTime.Now.ToJavaScriptTimeStamp().ToString();
  56. //=md5(domain+timestamp+lyfz2398865)
  57. string sign = LYFZ.WinAPI.SDKSecurity.MD5Encrypt(String.Format("{0}{1}lyfz2398865", dongleDomainName, timestamp)).ToLower();
  58. string postData = String.Format("domain={0}&sign={1}&timestamp={2}", dongleDomainName, sign, timestamp);
  59. string jsonData =LYFZ.WinAPI.CustomPublicMethod.HttpWebRequestPOST("http://mcrm.lyfz.net/api.php/plugin/CustomerAuthByDomain", postData, Encoding.UTF8);
  60. if (jsonData.IndexOf("{") == 0)
  61. {
  62. dynamic postReturnObj = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData);
  63. if (Convert.ToInt32(postReturnObj["code"]) == 0)
  64. {
  65. tokenPermission = postReturnObj["data"]["token"];
  66. }
  67. else
  68. {
  69. MessageBoxCustom.Show(String.Format("自助中心登录时失败:{0}", postReturnObj["info"]));
  70. }
  71. }
  72. else
  73. {
  74. MessageBoxCustom.Show(String.Format("自助中心登录时出错:{0}", jsonData));
  75. }
  76. }
  77. if (String.IsNullOrEmpty(tokenPermission))
  78. {
  79. MessageBoxCustom.Show(String.Format("您还没有开通“利亚方舟自助服务中心,请联系客服开通”"), backgroundWorker: backgroundWorker);
  80. }
  81. }
  82. catch (Exception ex)
  83. {
  84. MessageBoxCustom.Show(String.Format("获取授权时错误:{0}", ex.Message), backgroundWorker: backgroundWorker);
  85. }
  86. });
  87. }
  88. if (this.plExMainContainer.Controls.Count <= 0)
  89. {
  90. this.frmPage.SetEmbeddedWindows(this.plExMainContainer);
  91. }
  92. if (!String.IsNullOrEmpty(tokenPermission))
  93. {
  94. SetSetLocalStorage();
  95. frmPage.LoadUrl(gotoUrl);
  96. // frmPage.LoadUrl("http://lyfz.app.local/H5UI/index.html");
  97. // frmPage.LoadUrl("http://res.app.local/H5UI/index.html");
  98. // frmPage.LoadUrl("https://html5test.com/");
  99. // frmPage.LoadUrl("http://www.baidu.com/");
  100. //frmPage.LoadUrl("http://benediktmeurer.de/ARES-6/");
  101. //frmPage.LoadUrl("https://react-md.mlaursen.com/components/pickers/date");
  102. }
  103. else
  104. {
  105. frmPage.LoadUrl("http://www.lyfz.net/index/miniapp_desc");
  106. }
  107. }
  108. private void ContextMenuHandler_RunContextMenu(object sender, Chromium.Event.CfxRunContextMenuEventArgs e)
  109. {
  110. e.SetReturnValue(true);
  111. }
  112. void btnRefresh_Click(object sender, EventArgs e)
  113. {
  114. myRefresh(this.cbDelHuanChun.Checked);
  115. }
  116. void myRefresh(bool isDelHuanChun)
  117. {
  118. if (isDelHuanChun)
  119. {
  120. this.frmPage.Browser.ReloadIgnoreCache();
  121. }
  122. else
  123. {
  124. this.frmPage.Browser.Reload();
  125. }
  126. }
  127. private void LoadHandler_OnLoadStart(object sender, Chromium.Event.CfxOnLoadStartEventArgs e)
  128. {
  129. SetSetLocalStorage();
  130. }
  131. private void LoadHandler_OnLoadEnd(object sender, Chromium.Event.CfxOnLoadEndEventArgs e)
  132. {
  133. SetSetLocalStorage();
  134. }
  135. static string tokenPermission = "";//"120f472f357ab3e1a9188e47710b56fb";
  136. void SetSetLocalStorage()
  137. {
  138. this.frmPage.Chromium.ExecuteJavascript(String.Format("localStorage.setItem('login-token','{0}');", tokenPermission));
  139. }
  140. }
  141. }