修改encoding, 新增Param API

master
rexlin 5 years ago
parent beaf945a41
commit 25f22a0241
  1. 72
      n5coredll/LogUtil.cs
  2. 71
      n5coredll/N5Core.cs
  3. 5
      n5coredll/RequestResult.cs
  4. 1
      n5coredll/n5coredll.csproj

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace n5coredll
{
public class LogUtil
{
private static String mLogPath;
private static LogUtil mInstance;
public static LogUtil getInstance()
{
if (mInstance == null)
mInstance = new LogUtil();
return mInstance;
}
public void setLogPath(String logPath)
{
if (logPath.EndsWith(@"\"))
mLogPath = logPath;
else
mLogPath = logPath + @"\";
}
private String getCurLogFile()
{
StringBuilder txnIdSb = new StringBuilder();
DateTime dt = DateTime.Now;
return ("n5dll" + "_" + dt.ToString("yyyyMMdd") +".log");
}
public void addRepeatLog(string logInfo)
{
try
{
String path = mLogPath + getCurLogFile();
//path = @"C:\Users\rexli\AppData\Local\Temp\test.log";
if (!File.Exists(path))
{
using (StreamWriter sw = File.CreateText(path))
{
sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
sw.Flush();
sw.Close();
}
}
else
{
using (StreamWriter sw = File.AppendText(path))
{
sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss:ffff") + " [LOGGER] " + logInfo);
sw.Flush();
sw.Close();
}
}
// Console.WriteLine(logInfo);
}
catch (Exception err)
{
Console.WriteLine("Exception = " + err);
}
}
}
}

@ -1413,6 +1413,73 @@ namespace n5coredll
return RequestResult.createRespErrJson("SETTLE_RESP", ERR_STATUS_TIMEOUT);
}
public string sendParam()
{
if (ifBusy)
return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_BUSY);
ifBusy = true;
sendTime = 0;
isSending = false;
mRecvTimes = 0;
isReadyBack = false;
currReqByteArr = null;
currResultJsonStr = null;
RequestResult reqResult = null;
isGetACK = false;
if (openSerialPort())
{
currReqByteArr = this.packReqMsg(RequestResult.toJsonParam());
if (currReqByteArr == null || currReqByteArr.Length == 0)
{
closeSerialPort();
ifBusy = false;
return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_PARAM);
//return "Request failed: params error";
}
Console.WriteLine("currReqByteArr = " + currReqByteArr);
Console.WriteLine("currReqByteArr.Length = " + currReqByteArr.Length);
this.sendReqMsg();
}
else
{
ifBusy = false;
closeSerialPort();
return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_OPENCOM);
}
int sleepTime = timeOut / 1000;
DateTime startTime = DateTime.Now;
Boolean ifEnd = false;
while (!ifEnd)
{
DateTime nowTime = DateTime.Now;
TimeSpan sp = nowTime - startTime;
if (sp.TotalSeconds > sleepTime)
ifEnd = true;
else
{
if (!isSending && !isGetACK)
this.resendReqMsg();
if (isReadyBack)
{
closeSerialPort();
if (currResultJsonStr != null && !"".Equals(currResultJsonStr))
{
ifBusy = false;
return currResultJsonStr;
}
}
}
}
Console.WriteLine("Timeout return : " + DateTime.Now.ToString());
ifBusy = false;
return RequestResult.createRespErrJson("PARAM_RESP", ERR_STATUS_TIMEOUT);
}
public string requestRetrieval(string txnId, int pTimeOut)
{
RetrievalResult retrievalResult = null;
@ -2276,8 +2343,8 @@ namespace n5coredll
{
Console.WriteLine("Check LRC success! LRC is [" + ObjectUtil.desToHex(new byte[] { nlrc }) + "]");
sendAck();
string jsonMsg = System.Text.Encoding.Default.GetString(msg);
//string jsonMsg = System.Text.Encoding.Default.GetString(msg);
string jsonMsg = System.Text.Encoding.UTF8.GetString(msg);
onMsgReceived(jsonMsg);
reset();
return;

@ -30,6 +30,11 @@ namespace n5coredll
return "{\"EVENT_NAME\":\"SETTLE\"}";
}
public static string toJsonParam()
{
return "{\"EVENT_NAME\":\"PARAM\",\"PAYMENT_APP_ID\":\"CC\"}";
}
public static string toJsonForReprint()
{
return "{\"EVENT_NAME\":\"PRINT\",\"IS_REPRINT\":true}";

@ -49,6 +49,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="LogUtil.cs" />
<Compile Include="LoyaltyType.cs" />
<Compile Include="N5Core.cs" />
<Compile Include="N5PropertyOper.cs" />

Loading…
Cancel
Save