Ejemplo n.º 1
0
        private void BuldingLoginInfo()
        {
            IPHostEntry host     = Dns.GetHostEntry(Dns.GetHostName());
            string      clientId = host.AddressList.FirstOrDefault(
                ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString();
            string t = Convert.ToString(DateTimeOffset.Now.ToUnixTimeMilliseconds());
            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("productKey", ProductKey);
            dict.Add("deviceName", DeviceName);
            dict.Add("clientId", clientId);
            dict.Add("timestamp", t);
            UserName = DeviceName + "&" + ProductKey;
            PassWord = IotSignUtils.sign(dict, DeviceSecret, Signmethod);
            ClientId = clientId + "|securemode=3,signmethod=" + Signmethod + ",timestamp=" + t + "|";
        }
Ejemplo n.º 2
0
        public void Main()
        {
            IPHostEntry host     = Dns.GetHostEntry(Dns.GetHostName());
            string      clientId = host.AddressList.FirstOrDefault(
                ip => ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).ToString();
            string t          = Convert.ToString(DateTimeOffset.Now.ToUnixTimeMilliseconds());
            string signmethod = "hmacmd5";

            Dictionary <string, string> dict = new Dictionary <string, string>();

            dict.Add("productKey", ProductKey);
            dict.Add("deviceName", DeviceName);
            dict.Add("clientId", clientId);
            dict.Add("timestamp", t);

            string mqttUserName = DeviceName + "&" + ProductKey;
            string mqttPassword = IotSignUtils.sign(dict, DeviceSecret, signmethod);
            string mqttClientId = clientId + "|securemode=3,signmethod=" + signmethod + ",timestamp=" + t + "|";

            string targetServer = ProductKey + ".iot-as-mqtt." + RegionId + ".aliyuncs.com";

            ConnectMqtt(targetServer, mqttClientId, mqttUserName, mqttPassword);
        }