From 587c36e27131f2d028fcabc13b296a8de7470034 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期三, 08 一月 2020 08:59:19 +0800
Subject: [PATCH] 2019.1.8
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs | 238 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 227 insertions(+), 11 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs
old mode 100755
new mode 100644
index 2d85f92..1052a4c
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlWifiLogic.cs
@@ -1,5 +1,6 @@
锘縰sing System;
using System.Collections.Generic;
+using System.Security.Cryptography;
using System.Text;
namespace Shared.Phone.UserCenter
@@ -31,14 +32,36 @@
}
/// <summary>
- /// 褰撳墠wifi鐨凷SID,涔熷彨Wifi鐨勫悕瀛�
+ /// 褰撳墠鏄惁鏄綉鍏崇儹鐐�
+ /// </summary>
+ public bool IsGatewayHotspot
+ {
+ get
+ {
+ string myId = this.SSID;
+
+ if (myId.StartsWith("hdlZigbeeGW") == true)
+ {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 褰撳墠wifi鐨凷SID,涔熷彨Wifi鐨勫悕瀛�(鍙栦笉鍒版椂,浼氳繑鍥瀗ull)
/// </summary>
public string SSID
{
get
{
#if iOS
- return string.Empty;
+ string ssiD = Shared.WiimuUPnP.SSID;
+ if (string.IsNullOrEmpty(ssiD) == false && ssiD.StartsWith("\"") && ssiD.EndsWith("\""))
+ {
+ ssiD = ssiD.Substring(1, ssiD.Length - 2);
+ }
+ return ssiD;
#endif
#if Android
string ssiD = null;
@@ -49,9 +72,16 @@
ssiD = strId;
});
});
+ int count = 0;
while (ssiD == null)
{
System.Threading.Thread.Sleep(50);
+ count++;
+ if (count == 20)
+ {
+ //1绉掕秴鏃�
+ return null;
+ }
}
if (string.IsNullOrEmpty(ssiD) == false && ssiD.StartsWith("\"") && ssiD.EndsWith("\""))
{
@@ -68,9 +98,178 @@
private Com.Mediatek.Elian.ElianNative hdlWiFi = null;
#endif
-#endregion
+ /// <summary>
+ /// TCP鍗忚
+ /// </summary>
+ private System.Net.Sockets.TcpClient tcpClient = null;
+ /// <summary>
+ /// 閾炬帴娴佸璞�
+ /// </summary>
+ private System.Net.Sockets.NetworkStream networkStream = null;
+ /// <summary>
+ /// Ap妯″紡缃戝叧杩斿洖鐨勭閽�
+ /// </summary>
+ private string randDesKey = null;
-#region 鈻� 涓�鑸柟娉昣__________________________
+ #endregion
+
+ #region 鈻� Ap妯″紡鐨凾CP閾炬帴____________________
+
+ /// <summary>
+ /// 鎵撳紑Ap妯″紡鐨凾CP閾炬帴(鏈夐敊璇椂锛岀洿鎺ヨ繑鍥為敊璇秷鎭�傛病鏈夐敊璇椂锛岃繑鍥瀗ull)
+ /// </summary>
+ /// <returns></returns>
+ public string StartApTcpConnection()
+ {
+ try
+ {
+ //TCP杩炴帴
+ tcpClient = new System.Net.Sockets.TcpClient();
+ tcpClient.Connect("192.168.8.1", 5000);
+ networkStream = tcpClient.GetStream();
+ //鍔犲瘑鏁版嵁
+ string sendDataMsg = "hdl1985.";
+ string DefaultdesKey = "hdl1985.";
+ //44bytes 鍔犲瘑鏁版嵁 DES鍔犲瘑 base64瀵嗘枃
+ var sendData = Encoding.UTF8.GetBytes(DesEncrypt(sendDataMsg, DefaultdesKey));
+ //灏嗘暟鎹啓鍏ョ綉缁滄祦
+ networkStream.Write(sendData, 0, sendData.Length);
+
+ System.Threading.Thread.Sleep(500);
+ //2.鎺ユ敹鐘舵��,闀垮害<1024瀛楄妭
+ byte[] bytes = new Byte[1024];
+ int length = networkStream.Read(bytes, 0, bytes.Length);
+ if (length == 0)
+ {
+ //閫氫俊閾炬帴澶辫触
+ return Language.StringByID(R.MyInternationalizationString.uCommunicationLinkFail);
+ }
+ string data = Encoding.UTF8.GetString(bytes, 0, length);
+ //缃戝叧杩斿洖鐨勭閽�
+ this.randDesKey = DESDecrypt(data, DefaultdesKey);
+
+ return null;
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex);
+ this.CloseApTcpConnection();
+ //閫氫俊閾炬帴澶辫触
+ return Language.StringByID(R.MyInternationalizationString.uCommunicationLinkFail);
+ }
+ }
+
+ /// <summary>
+ /// Ap妯″紡 鍙戦�佸瘑鐮佸埌瀹跺涵鐨勮矾鐢卞櫒
+ /// </summary>
+ /// <param name="ssid"></param>
+ /// <param name="password"></param>
+ /// <returns></returns>
+ public bool SendApHomeWifiPassword(string ssid, string password)
+ {
+ try
+ {
+ //鍔犲瘑鏁版嵁
+ string data2 = "ssid:" + ssid + "," + "pwd:" + password;
+ var sendData2 = Encoding.UTF8.GetBytes(DesEncrypt(data2, randDesKey));
+ //灏嗘暟鎹啓鍏ョ綉缁滄祦
+ networkStream.Write(sendData2, 0, sendData2.Length);
+ return true;
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex);
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// 鍏抽棴Ap妯″紡鐨則cp閾炬帴
+ /// </summary>
+ public void CloseApTcpConnection()
+ {
+ try
+ {
+ //鍏抽棴瀹㈡埛绔�
+ tcpClient?.Close();
+ tcpClient = null;
+ networkStream = null;
+ randDesKey = null;
+ }
+ catch (Exception ex)
+ {
+ HdlLogLogic.Current.WriteLog(ex);
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鍔犲瘑瑙e瘑___________________________
+
+ /// <summary>
+ /// //鍔犲瘑鏁版嵁
+ /// </summary>
+ /// <param name="pToDesEncrypt"></param>
+ /// <param name="sKey">DES绉橀挜</param>
+ /// <returns></returns>
+ private string DesEncrypt(string pToDesEncrypt, string sKey)
+ {
+ // 鍒涘缓des鍔犲瘑娌�
+ using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
+ {
+ // 寰楀埌UTF-8鐨勬暟鎹簮
+ byte[] inputByteArray = Encoding.UTF8.GetBytes(pToDesEncrypt);
+ // 璁剧疆key鍜宨v瀵嗛挜
+ des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
+ des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
+ //鐢变簬java鏄娇鐢ㄩ粯璁ゅ姞瀵嗘ā寮忥紝C#榛樿鏄疌BC锛岄渶瑕佷慨鏀逛负ECB
+ des.Mode = CipherMode.CBC;
+ des.Padding = PaddingMode.PKCS7;
+ // 鍒涘缓鏁版嵁娴佸苟杩涜鍔犲瘑
+ var ms = new System.IO.MemoryStream();
+ using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
+ {
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ cs.Close();
+ }
+ // 鍏抽棴鏁版嵁娴�
+ ms.Close();
+ return Convert.ToBase64String(ms.ToArray());//base64瀵嗘枃
+ }
+ }
+
+ /// <summary>
+ /// 瑙e瘑
+ /// </summary>
+ /// <param name="pToDecrypt"></param>
+ /// <param name="key">瑙e瘑瀵嗗寵</param>
+ /// <returns></returns>
+ private string DESDecrypt(string pToDecrypt, string key = null)
+ {
+ byte[] inputByteArray = Convert.FromBase64String(pToDecrypt);
+ using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
+ {
+
+ des.Key = ASCIIEncoding.ASCII.GetBytes(key);
+ des.IV = ASCIIEncoding.ASCII.GetBytes(key);
+
+ var ms = new System.IO.MemoryStream();
+ using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
+ {
+ cs.Write(inputByteArray, 0, inputByteArray.Length);
+ cs.FlushFinalBlock();
+ cs.Close();
+ }
+ string str = Encoding.UTF8.GetString(ms.ToArray());
+ ms.Close();
+ return str;
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
#if Android
/// <summary>
@@ -80,14 +279,14 @@
/// <param name="wifiPsw">wifi瀵嗙爜</param>
/// <param name="p2">鎴戜篃涓嶇煡閬撹繖涓槸浠�涔堜笢瑗�</param>
/// <returns></returns>
- public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "1")
+ public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "")
{
if (hdlWiFi == null)
{
- Com.Mediatek.Elian.ElianNative.LoadLib();
+ var result2 = Com.Mediatek.Elian.ElianNative.LoadLib();
//鍒濆鍖朩i-Fi閰嶇綉
this.hdlWiFi = new Com.Mediatek.Elian.ElianNative();
- hdlWiFi.InitSmartConnection(null, 1, 1);
+ var value = hdlWiFi.InitSmartConnection(null, 1, 1);
}
//寮�濮媁i-Fi閰嶇綉
var result = hdlWiFi.StartSmartConnection(wifiName, wifiPsw, p2);
@@ -102,7 +301,8 @@
if (hdlWiFi != null)
{
//鍋滄Wi-Fi閰嶇綉
- hdlWiFi.StopSmartConnection();
+ var result = hdlWiFi.StopSmartConnection();
+ hdlWiFi = null;
}
}
#endif
@@ -114,10 +314,10 @@
/// <param name="wifiPsw">wifi瀵嗙爜</param>
/// <param name="p2">鎴戜篃涓嶇煡閬撹繖涓槸浠�涔堜笢瑗�</param>
/// <returns></returns>
- public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "1")
+ public bool StartSmartConnection(string wifiName, string wifiPsw, string p2 = "")
{
//鍒濆鍖朩i-Fi杩炴帴
- Com.Mediatek.Elian.ElianNative.InitSmartConnection(null, 1, 1);
+ Com.Mediatek.Elian.ElianNative.InitSmartConnection("1", 1, 1);
//寮�濮媁i-Fi杩炴帴
var result = Com.Mediatek.Elian.ElianNative.StartSmartConnection(wifiName, wifiPsw, p2);
return true;
@@ -133,6 +333,22 @@
}
#endif
-#endregion
+ /// <summary>
+ /// 鎵撳紑鎵嬫満wifi璁剧疆鐣岄潰
+ /// </summary>
+ public void OpenAppWifiSettion()
+ {
+ if (Application.DeviceType == Shared.Device.Android)
+ {
+ ///鎵撳紑WI-IF鐣岄潰
+ CommonClass.OpenAction("android.settings.WIFI_SETTINGS");
+ }
+ else
+ {
+ CommonClass.OpenAction("App-Prefs:root=WIFI");
+ }
+ }
+
+ #endregion
}
}
--
Gitblit v1.8.0