Ver Fonte

苏州亚科-质检+快递:打印快递加log文件

dujj há 2 anos atrás
pai
commit
2238009edb
1 ficheiros alterados com 42 adições e 0 exclusões
  1. 42 0
      Demo/Demo/Core/LabelV2.cs

+ 42 - 0
Demo/Demo/Core/LabelV2.cs

@@ -3,6 +3,10 @@ using Common.Request.Label;
 using Utils;
 using Common;
 using Newtonsoft.Json.Linq;
+using System.IO;
+using System;
+using System.Text;
+using System.Collections.Generic;
 /// <summary>
 /// 商家寄件(官方快递)
 /// </summary>
@@ -66,11 +70,14 @@ public static class LabelV2
         string msg = "";
         string data = "";
         string errorStr = "";
+        Dictionary<string, string> logReq = null;
         try
         {
             param.method = ApiInfoConstant.ORDER;
             var request = ObjectToDictionaryUtils.ObjectToMap(param);
 
+            logReq = request;
+
             if (request == null)
             {
                 msg = "body参数错误";
@@ -90,6 +97,23 @@ public static class LabelV2
             msg = "操作失败:" + ex.ToString();
         }
 
+        try
+        {
+            StringBuilder sb = new StringBuilder();
+            sb.AppendLine("----" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
+            sb.AppendLine("POST "+ ApiInfoConstant.NEW_TEMPLATE_URL);
+            sb.AppendLine("Request Body");
+            sb.AppendLine(Newtonsoft.Json.JsonConvert.SerializeObject(logReq));
+            sb.AppendLine("Response Body");
+            sb.AppendLine(data);
+            sb.AppendLine("");
+            WriteTxt(sb.ToString());
+        }
+        catch (Exception)
+        {
+
+        }
+
         JObject result = new JObject();
         result.Add("code", code);
         result.Add("msg", msg);
@@ -97,4 +121,22 @@ public static class LabelV2
 
         return result.ToString();
     }
+
+    #region 将字符串写入txt文档
+    private static void WriteTxt(string src)
+    {
+        string rFilePath = System.Environment.CurrentDirectory + "\\log" + DateTime.Today.ToString("yyyyMMdd");
+        FileStream fs = new FileStream(rFilePath, FileMode.Append);
+        byte[] data = Encoding.Default.GetBytes(src);
+        try
+        {
+            fs.Write(data, 0, data.Length);
+            fs.Flush();
+            fs.Close();
+        }
+        catch (Exception)
+        {
+        }
+    }
+    #endregion
 }