Ejemplo n.º 1
0
        /// <summary>
        /// 获取Token
        /// </summary>
        public TokenResult getToken()
        {
            TokenResult result = null;

            string apiPath              = "/iocm/app/sec/v1.1.0/login";
            string body                 = "appId=" + this.iot_appId + "&secret=" + this.iot_appKey;
            string method               = "POST";
            string contenttype          = "application/x-www-form-urlencoded";
            WebHeaderCollection headers = new WebHeaderCollection();

            try
            {
                ApiResult apiResult = new ApiResult();
                apiResult = PostIotApi(apiPath, body, headers, method, contenttype, this.iot_p12Certfile, this.iot_CertfilePwd);
                //获取到api返回的结果集
                if (apiResult != null)
                {
                    TokenResult token = JsonConvert.DeserializeObject <TokenResult>(apiResult.result);
                    result = token;
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 下发命令处理
        /// </summary>
        private void SendCommandProcessing()
        {
            //初始化信息
            cmdProcess = new CmdProcessing(appIP, appPort, appId, appKey, p12Certfile, p12CertfilePwd);

            try
            {
                TokenResult token = new TokenResult();
                //调用获取Token方法
                token = cmdProcess.getToken();
                if (token != null)
                {
                    string tokenCode = token.accessToken; //获取token码

                    //下发命令操作
                    //IOT平台应用中的设备ID(此处需要获取设备ID)
                    string deviceId = "";
                    //参数实体类赋值(需要下发的编解码插件中定义的字段值)
                    List <CommandPara> listParas = new List <CommandPara>();
                    //发送命令
                    string cmdResult = cmdProcess.sendCommand(tokenCode, deviceId, callBackUrl, expireTime, serviceId, commandId, listParas);
                    if (cmdResult == null)
                    {
                        //下发命令失败
                    }
                    else
                    {
                        if (cmdResult == ((int)ReturnState.SendCmdSuccess).ToString())
                        {
                            //下发命令成功
                            //可在此执行数据处理等操作
                        }
                        else
                        {
                            //下发命令失败
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }