コード例 #1
0
        private string ToBase64(McHttpDto dto)
        {
            string   text       = dto.Verb + "\n" + dto.ContentType + "\n" + dto.Date.ToString("r") + "\n" + dto.BaseUrl + dto.ParasStr;
            HMACSHA1 myHMACSHA1 = new HMACSHA1(Encoding.UTF8.GetBytes(dto.SecrectKey));

            byte[] byteText = myHMACSHA1.ComputeHash(Encoding.UTF8.GetBytes(text));
            return(System.Convert.ToBase64String(byteText));
        }
コード例 #2
0
        public string HttpPost(McHttpDto dto, string JsonStr)
        {
            DateTimeOffset currDate = DateTimeOffset.Now;

            dto.Date = currDate;

            ConstructParas(dto);
            string signature = ToBase64(dto);

            _httpClient.DefaultRequestHeaders.Date          = currDate;
            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
                "IWOP", dto.AccessId + ":" + signature);

            string json   = JsonStr;
            var    input  = Newtonsoft.Json.JsonConvert.DeserializeObject(json);
            string result = _httpClient.PostAsJsonAsync(dto.ParasStr, input).Result.Content.ReadAsStringAsync().Result;

            return(result);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: yearrow/ApiTestPrograme
        public static DataTable UploadData(McHttpDto dto, string SqlStr, string resource)
        {
            Int64     _OrgId   = Int64.Parse(ConfigurationSettings.AppSettings["_OrgId"]);
            string    jsonData = string.Empty;
            DataTable DT       = SqlDeal.Query(SqlStr).Tables[0];

            // 处理转化
            for (int i = 0; i < DT.Rows.Count; i++)
            {
                if (i + 1 != DT.Rows.Count)
                {
                    jsonData += GetJson(DT.Rows[i]) + ",";
                }
                else
                {
                    jsonData += GetJson(DT.Rows[i]);
                }
            }
            // jsonData = JsonConvert.SerializeObject(DT);
            Console.WriteLine(jsonData);
            jsonData = "{\"" + resource + "\":{\"orgId\":" + _OrgId + ",\"data\": [" + jsonData + "] }}";
            //dto.apiStr = "external/mquantitys-upload?tag=mix&resource=" + resource + "&version=1";
            //dto.ParasStr = "external/mquantitys-upload?tag=mix&resource=" + resource + "&version=1";
            dto.apiStr   = "/api/mquantity/mquantitys-upload?resource=" + resource + "&tag=mix&version=1";
            dto.ParasStr = "/api/mquantity/mquantitys-upload?&resource=" + resource + "&tag=mixversion=1";
            YLHttpHelperMc client = new YLHttpHelperMc(null);
            ResultDto      result = JsonConvert.DeserializeObject <ResultDto>(client.HttpPost(dto, jsonData));

            if (result.success)
            {
                return(DT);
            }
            else
            {
                return(new DataTable());
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: yearrow/ApiTestPrograme
        static void Main()
        {
            string    SqlStr    = string.Empty;
            McHttpDto dto       = new McHttpDto();
            int       DataCount = int.Parse(ConfigurationSettings.AppSettings["DataCount"]);
            string    OrgId     = ConfigurationSettings.AppSettings["OrgId"];

            dto.AccessId    = ConfigurationSettings.AppSettings["AccessId"];
            dto.SecrectKey  = ConfigurationSettings.AppSettings["SecrectKey"];
            dto.Verb        = "POST";
            dto.ContentType = "application/json; charset=utf-8";
            dto.BaseUrl     = ConfigurationSettings.AppSettings["BaseUrl"];
            try
            {
                //=======================================================
                Console.WriteLine("获取手工打料信息并上传...");
                #region

                SqlStr = (" select top " + DataCount * 10 + " [orgId],[id] ,dosageId,[orgName] ,[proLine] ,[station] ,[datTim] ,[material] ,[operator] ,[factAmnt] ,[watFull] from manual  where orgid ='" + OrgId + "' and isnull(flag,0) != 1");
                UpdateFlag(UploadData(dto, SqlStr, "qManual"), "manual");
                // 发送成功
                Console.WriteLine("手工打料数据上传成功!");

                #endregion

                //=======================================================
                Console.WriteLine("获取车信息并上传...");
                #region
                // 一次性上传所有车
                SqlStr = (" select top " + DataCount + "[orgId],[id] ,[orgName],[proLine] ,[station],[scheduleId],[taskNo],[consPos] ,[betLev],[vehicle],[driver],[pieCnt] ,[projectName],[customer],[datTim] ,[operator],[lands],[planMete],[morMete],[prodMete],[reciepeNo],[carAmnt] ,[pour],[qualitor] ,[watFull],[TransMete] from produce  where orgid = '" + OrgId + "' and  isnull(flag,0) != 1");
                DataTable produceDT = UploadData(dto, SqlStr, "qProduce");
                UpdateFlag(produceDT, "produce");

                Console.WriteLine("车统计数据上传成功!");

                for (int i = 0; i < produceDT.Rows.Count; i++)
                {
                    //循环上传盘数据
                    String    SqlStrPiece = (" select [orgId],[id] ,[orgName],[proLine],[station],[scheduleId] ,[taskNo] ,[consPos] ,[betLev],[vehicle],[driver],[pieCnt],[projectName],[customer],[datTim],[operator],[lands],[planMete],[morMete],[prodMete],[reciepeNo],[pour],[qualitor],[watFull],[TransMete],[pieceId],[pieAmnt] from piece  where orgid = '" + OrgId + "' and  isnull(flag,0) != 1 and proLine='" + produceDT.Rows[i]["proLine"].ToString() + "' and scheduleId='" + produceDT.Rows[i]["scheduleId"].ToString() + "'");
                    DataTable PieceDT     = UploadData(dto, SqlStrPiece, "qPiece");
                    UpdateFlag(PieceDT, "piece");
                    Console.WriteLine("盘统计数据上传成功!");

                    //循环上传明细数据
                    String    SqlStrDosage = (" select [orgId] ,[id] ,[orgName],[proLine],[station],[scheduleId],[taskNo] ,[consPos],[betLev] ,[vehicle],[driver],[pieCnt] ,[projectName],[customer],[datTim],[operator] ,[lands],[planMete],[morMete],[prodMete],[reciepeNo],[pour] ,[qualitor] ,[carAmnt] ,[watFull],[pieceId] ,[pieAmnt],[dosageId] ,[fimTim],[planAmn],[factAmnt],[material],[TransMete] from dosage  where orgid = '" + OrgId + "' and  isnull(flag,0) != 1 and proLine='" + produceDT.Rows[i]["proLine"].ToString() + "' and scheduleId='" + produceDT.Rows[i]["scheduleId"].ToString() + "'");
                    DataTable DosageDT     = UploadData(dto, SqlStrDosage, "qDosage");
                    UpdateFlag(DosageDT, "dosage");
                    Console.WriteLine("明细数据上传成功!");
                }
                #endregion

                //=======================================================结束程序
                Console.WriteLine("执行结束...");
                //Console.ReadLine();
            }

            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #5
0
 private McHttpDto ConstructParas(McHttpDto dto)
 {
     dto.ParasStr = dto.apiStr.Replace("@version@", dto.CurrVersion.ToString());
     return(dto);
 }