From bd18a149bfd83807d7cbcf80a2384ef502184a96 Mon Sep 17 00:00:00 2001
From: kyy <3283105747@qq.com>
Date: 星期一, 15 十二月 2025 17:35:55 +0800
Subject: [PATCH] 接口改为富达模式
---
WebApi/Gs.Toolbox/InterfaceUtil.cs | 113 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 89 insertions(+), 24 deletions(-)
diff --git a/WebApi/Gs.Toolbox/InterfaceUtil.cs b/WebApi/Gs.Toolbox/InterfaceUtil.cs
index c40aa81..5d00201 100644
--- a/WebApi/Gs.Toolbox/InterfaceUtil.cs
+++ b/WebApi/Gs.Toolbox/InterfaceUtil.cs
@@ -18,16 +18,19 @@
/// <param name="hNo"></param>
/// <param name="urlType">濡傛灉涓�2锛屽垯鏄洿鏂板伐鍗曠姸鎬�</param>
/// <returns>濡傛灉鎴愬姛杩斿洖鏃ュ織guid,鍚﹀垯杩斿洖涓�</returns>
- public static (int, string) HttpPostErp(string param, string edtUserGuid = "", string abtGuid = "", string hNo = "", int urlType = 0)
+ public static (int, string) HttpPostErp(string param,
+ string edtUserGuid = "", string abtGuid = "", string hNo = "",
+ int urlType = 0, string keyUrl = "")
{
int _rtn = 0;
+ string docNo = string.Empty;
//鏃ュ織璇︾粏锛屽彂閫佺殑鏃跺�欙紝璁板綍鏃ュ織锛屽瓨鍌ㄨ繃绋嬭皟鐢ㄧ殑鏃跺�欙紝鍐嶇疮鍔犱笂mes涓氬姟鐨勬搷浣滅粨鏋�
System.Text.StringBuilder sbLog = new System.Text.StringBuilder();
sbLog.Append(DateTime.Now.ToString() + "寮�濮嬪彂閫�");
string strLogGuid = Guid.NewGuid().ToString();
- string url = AppSettingsHelper.getValueByKey("TestErpUrl");
+ string url = AppSettingsHelper.getValueByKey("TestErpUrl") + keyUrl;
if (urlType == 2)
- url = AppSettingsHelper.getValueByKey("TestErpUrl2");
+ url = AppSettingsHelper.getValueByKey("TestErpUrl2") + keyUrl;
HttpWebRequest request = null;
StreamWriter requestStream = null;
WebResponse response = null;
@@ -41,7 +44,9 @@
request.Timeout = 150000;
request.AllowAutoRedirect = false;
request.ServicePoint.Expect100Continue = false;
- HttpRequestCachePolicy noCachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
+ HttpRequestCachePolicy noCachePolicy =
+ new HttpRequestCachePolicy(HttpRequestCacheLevel
+ .NoCacheNoStore);
request.CachePolicy = noCachePolicy;
requestStream = new StreamWriter(request.GetRequestStream());
requestStream.Write(param);
@@ -57,7 +62,8 @@
}
catch (Exception ex)
{
- LogHelper.Debug(url, "HttpPostErp response:" + param + "锛宔x:" + ex.Message);
+ LogHelper.Debug(url,
+ "HttpPostErp response:" + param + "锛宔x:" + ex.Message);
responseStr = ex.Message;
_rtn = -1;
}
@@ -67,51 +73,110 @@
requestStream = null;
response = null;
}
+
+ /*if (_rtn != -1)
+ {
+ Result _result = JsonConvert.DeserializeObject<Result>(responseStr);
+ if ("200".Equals(_result.code))
+ _rtn = 1;
+ }*/
+
if (_rtn != -1)
{
- Result _result = JsonConvert.DeserializeObject<Result>(responseStr);
- if ("200".Equals(_result.state))
- _rtn = 1;
+ Result _result = JsonConvert.DeserializeObject<Result>(responseStr);
+ // 鏂板垽鏂鍒欙細status=0 涓� message=Success 鎵嶇畻鎴愬姛
+ if (_result?.status == "0" && _result?.message == "Success")
+ _rtn = 1;
+ docNo = _result.data.doc_no;
}
+
sbLog.Append("," + DateTime.Now.ToString() + "缁撴潫鍙戦��");
if (_rtn > 0)
+ {
sbLog.Append(",鍙戦�佹垚鍔�");
+
+ //鍙戦�佹垚鍔熷弽鍐檈rp鍗曞彿
+
+ SqlParameter[] parameters =
+ {
+ new("@hNo", hNo),
+ new("@erpNo",docNo),
+ new("@Api", keyUrl) ,
+ new("@in1", ""),
+ new("@in2", ""),
+ };
+ DbHelperSQL.RunProcedure("[prc_Rev_ErpNo]", parameters);
+ }
else
sbLog.Append(",鍙戦�佸け璐�,mes閫�鍑烘搷浣�");
try
{
SqlParameter[] parameters =
- {
- new("@edtUserGuid", edtUserGuid),
- new("@abtGuid", abtGuid),
- new("@abtTable", ""),
- new("@detail", sbLog.ToString()),
- new("@hNo", hNo),
- new("@RtnLogGuid", strLogGuid),
- new("@SendJson", param),
- new("@RtnJson", responseStr),
- new("@isSuccess", (_rtn>0?1:0)),
- new("@isErp", 1),
- };
+ {
+ new("@edtUserGuid", edtUserGuid),
+ new("@abtGuid", abtGuid),
+ new("@abtTable", ""),
+ new("@detail", sbLog.ToString()),
+ new("@hNo", hNo),
+ new("@RtnLogGuid", strLogGuid),
+ new("@SendJson", param),
+ new("@RtnJson", responseStr),
+ new("@isSuccess", (_rtn > 0 ? 1 : 0)),
+ new("@isErp", 1),
+ };
DbHelperSQL.RunProcedure("[prc_log_create]", parameters);
}
catch (Exception ex)
{
LogHelper.Debug(url, "HttpPostErp 鍐欏叆鏃ュ織琛�" + ex.Message);
}
+
return (_rtn, (_rtn > 0 ? strLogGuid : responseStr));
}
+
+
}
+
+/// <summary>
+/// 鎺ュ彛杩斿洖缁撴灉鏍瑰璞�
+/// </summary>
public class Result
{
/// <summary>
- /// 200鎴愬姛锛屽惁鍒欏け璐�
+ /// 鐘舵�佺爜锛�0琛ㄧず鎴愬姛锛�-1琛ㄧず澶辫触
/// </summary>
- public string? state { get; set; }
- public string? msg { get; set; }
-
public string? status { get; set; }
+ /// <summary>
+ /// 鐘舵�佹弿杩帮細Success琛ㄧず鎴愬姛锛屽け璐ユ椂涓哄叿浣撳紓甯镐俊鎭�
+ /// </summary>
public string? message { get; set; }
+
+ /// <summary>
+ /// 鏁版嵁浣擄細鎴愬姛鏃惰繑鍥炲埌璐у崟淇℃伅锛屽け璐ユ椂涓哄叿浣撳紓甯镐俊鎭�
+ /// </summary>
+ public ResultData? data { get; set; }
+}
+
+/// <summary>
+/// 鎺ュ彛杩斿洖鐨凞ata瀵硅薄锛堝己绫诲瀷锛�
+/// 瀵瑰簲JSON锛歿"doc_type_no":"370","doc_no":"20251209001","msg":"鍒涘缓鍒拌揣鍗曟垚鍔�."}
+/// </summary>
+public class ResultData
+{
+ /// <summary>
+ /// 鍗曟嵁绫诲瀷缂栧彿
+ /// </summary>
+ public string? doc_type_no { get; set; }
+
+ /// <summary>
+ /// 鍗曟嵁缂栧彿
+ /// </summary>
+ public string? doc_no { get; set; }
+
+ /// <summary>
+ /// 鎿嶄綔缁撴灉鎻忚堪
+ /// </summary>
+ public string? msg { get; set; }
}
\ No newline at end of file
--
Gitblit v1.9.3