/// <summary> /// RestAPI 호출하여 RFID 확인 /// </summary> private void RestAPI_CheckRFID() { System.Threading.Thread.Sleep(2000); HashLib.IHash hash = HashLib.HashFactory.Crypto.CreateSHA256(); HashLib.HashResult digest = hash.ComputeString(strRfid.ToString(), Encoding.ASCII); { XstrHashedRFid = digest.ToString().Replace("-", "").ToLower(); } XApiResponse = APIController.API_PostPurchaseId(XstrHashedRFid); if (XApiResponse != null && XApiResponse.code == 200) { apiResult = true; } else { apiResult = false; } }
/// <summary> /// 영수증 번호 요청 /// sha256(rfid)를 인증하고, 구매 영수증 번호를 응답 받는다. /// </summary> /// <param name="aRfid"></param> /// <returns></returns> public static DTOGetPurchaseIdResponse API_PostPurchaseId(string aRfid) { //===================================================================== // POST http://10.1.203.12:8080/api/caffe/purchases/purchase/receipt/id //===================================================================== RestSharp.RestClient client = new RestSharp.RestClient(URL_DCCAFFE); RestSharp.RestRequest request = new RestSharp.RestRequest(); request.AddHeader("Content-Type", "application/json;charset=UTF-8"); request.Method = RestSharp.Method.POST; request.RequestFormat = RestSharp.DataFormat.Json; request.Resource = URI_GET_PURCHASE_ID; //------------------------------------------------ // make to request json /* * StringBuilder sb = new StringBuilder(); * StringWriter sw = new StringWriter(sb); * using (JsonWriter writer = new JsonTextWriter(sw)) * { * writer.Formatting = Formatting.None; * * writer.WriteStartObject(); * writer.WritePropertyName("rfid"); * writer.WriteValue(aRfid); * writer.WriteEndObject(); * } * * //------------------------------------------------ * request.AddParameter("application/json", sb.ToString(), RestSharp.ParameterType.RequestBody); */ DTOGetPurchaseIdRequest reqJson = new DTOGetPurchaseIdRequest { rfid = aRfid }; request.AddJsonBody(reqJson); //---------------------------------------- var t1 = client.ExecuteTaskAsync(request); t1.Wait(); //---------------- // error handling if (t1.Result.ErrorException != null) { System.Diagnostics.Debug.WriteLine("[RESPONSE] " + t1.Result.Content); return(null); } string json = t1.Result.Content; //-------------- // debug output json = JsonFormatting(json); System.Diagnostics.Debug.WriteLine("[RESPONSE] " + json); //----------------------- // desirialized json data DTOGetPurchaseIdResponse dto = new DTOGetPurchaseIdResponse(); try { dto = JsonConvert.DeserializeObject <DTOGetPurchaseIdResponse>(json); dto.code = (int)t1.Result.StatusCode; } catch (Exception ex) { dto = null; System.Diagnostics.Debug.WriteLine("[ERROR] " + ex.Message); } return(dto); }