add - Mes接口逻辑实现

master
wenjy 9 months ago
parent d925cfb4c4
commit a79dbf268a

@ -0,0 +1,130 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using ZJ_BYD.Model.HttpApiParam;
namespace ZJ_BYD.Common
{
public class HttpUtilApi
{
private static string checkSnCodeUrl = "http://47.93.53.88:8280/scada-collected/checkSnCode";
private static string submitWorkStationDataUrl = "http://47.93.53.88:8280/scada-collected/submitWorkStationData";
/// <summary>
/// 条码验证及查询接口
/// </summary>
/// <param name="checkSnCode"></param>
/// <returns></returns>
public static ResponseParam checkSnCode(CheckSnCode checkSnCode)
{
ResponseParam result = null;
try
{
var jsonStr = JsonConvert.SerializeObject(checkSnCode);
var reqStr = Post(checkSnCodeUrl, jsonStr);
result = JsonConvert.DeserializeObject<ResponseParam>(reqStr);
}
catch (Exception ex)
{
result = new ResponseParam()
{
code = 500,
msg = ex.Message
};
}
return result;
}
/// <summary>
/// 一体机工位提交数据
/// </summary>
/// <param name="workData"></param>
/// <returns></returns>
public static ResponseParam submitWorkStationData(WorkData workData)
{
ResponseParam result = null;
try
{
var jsonStr = JsonConvert.SerializeObject(submitWorkStationDataUrl);
var respStr = Post(submitWorkStationDataUrl, jsonStr);
result = JsonConvert.DeserializeObject<ResponseParam>(respStr);
}
catch (Exception ex)
{
result = new ResponseParam()
{
code = 500,
msg = ex.Message
};
}
return result;
}
private static string Post(string Url, string jsonParas)
{
string postContent = "";
string strURL = Url;
//创建一个HTTP请求
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strURL);
//Post请求方式
request.Method = "POST";
//内容类型
request.ContentType = "application/json";
request.UserAgent = "app";
//设置参数并进行URL编码
string paraUrlCoded = jsonParas;//System.Web.HttpUtility.UrlEncode(jsonParas);
byte[] payload;
//将Json字符串转化为字节
payload = System.Text.Encoding.UTF8.GetBytes(paraUrlCoded);
//设置请求的ContentLength
request.ContentLength = payload.Length;
//发送请求,获得请求流
Stream writer = null;
try
{
writer = request.GetRequestStream();//获取用于写入请求数据的Stream对象
}
catch (Exception)
{
// writer = null;
//Console.Write("连接服务器失败!");
postContent = "连接服务器失败!";
//writer.Close();//关闭请求流
return postContent;//返回Json数据
}
//将请求参数写入流
writer.Write(payload, 0, payload.Length);
writer.Close();//关闭请求流
// String strValue = "";//strValue为http响应所返回的字符流
HttpWebResponse response;
try
{
//获得响应流
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException ex)
{
response = ex.Response as HttpWebResponse;
}
Stream s = response.GetResponseStream();
// Stream postData = Request.InputStream;
StreamReader sRead = new StreamReader(s);
postContent = sRead.ReadToEnd();
sRead.Close();
return postContent;//返回Json数据
}
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZJ_BYD.Model.HttpApiParam
{
public class CheckSnCode
{
public string mainCode { get; set; }
public string _operator { get; set; }
public string productCode { get; set; }
public string snCode { get; set; }
public string snCodeName { get; set; }
public string snType { get; set; }
public string stationCode { get; set; }
}
}

@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZJ_BYD.Model.HttpApiParam
{
public class DParams
{
public string max { get; set; }
public string min { get; set; }
public string n { get; set; }
public string ng { get; set; }
public string step { get; set; }
public string stepName { get; set; }
public string v { get; set; }
public string vtype { get; set; }
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZJ_BYD.Model.HttpApiParam
{
public class ResponseData
{
public string inputNum { get; set; }
public string productCode { get; set; }
public string targetNum { get; set; }
public string rfId { get; set; }
public string useFlag { get; set; }
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZJ_BYD.Model.HttpApiParam
{
public class ResponseParam
{
public int code { get; set; }
public List<ResponseData> data { get; set; }
public string msg { get; set; }
}
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ZJ_BYD.Model.HttpApiParam
{
public class WorkData
{
public List<DParams> dparams { get; set; }
public string _operator { get; set; }
public string productCode { get; set; }
public int qc { get; set; }
public string rfId { get; set; }
public string snList { get; set; }
public string workStationCode { get; set; }
}
}

@ -240,6 +240,7 @@
<Compile Include="BindOrder.Designer.cs">
<DependentUpon>BindOrder.cs</DependentUpon>
</Compile>
<Compile Include="Common\HttpUtilApi.cs" />
<Compile Include="Common\MyWebClient.cs">
<SubType>Component</SubType>
</Compile>
@ -250,6 +251,11 @@
<Compile Include="LoginFrom.Designer.cs">
<DependentUpon>LoginFrom.cs</DependentUpon>
</Compile>
<Compile Include="Model\HttpApiParam\CheckSnCode.cs" />
<Compile Include="Model\HttpApiParam\DParams.cs" />
<Compile Include="Model\HttpApiParam\ResponseData.cs" />
<Compile Include="Model\HttpApiParam\ResponseParam.cs" />
<Compile Include="Model\HttpApiParam\WorkData.cs" />
<Compile Include="Model\T_BranchInfo.cs" />
<Compile Include="Model\T_PrintInfo.cs" />
<Compile Include="CheckCode.cs" />
@ -786,6 +792,7 @@
<ItemGroup>
<WCFMetadata Include="Connected Services\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ProjectExtensions>
<VisualStudio>

Loading…
Cancel
Save