using System; using System.Collections.Generic; using System.Linq; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Authorization; using System.Web; using MySystem.MainModels; using LitJson; using Library; using System.IO; using System.Text; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/[controller]/[action]")] public class DepositController : BaseController { public DepositController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 设置押金 public Dictionary Set() { Dictionary result = new Dictionary(); try { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); JsonData json = JsonMapper.ToObject(requestMes); string value = AesDecrypt(json["content"].ToString(), "kvS4TIRh7Yulg4nr"); JsonData data = JsonMapper.ToObject(value); string sn = data["sn"].ToString(); string serviceFee = data["serviceFee"].ToString(); Dictionary req = new Dictionary(); string PosSn = data["sn"].ToString(); req.Add("PosSn", PosSn); req.Add("BrandId", "12"); req.Add("Deposit", data["serviceFee"].ToString()); string UserId = "0"; if(requestMes.Contains("\"userId\"")) { UserId = data["userId"].ToString(); } req.Add("UserId", UserId); string CallBackUrl = ""; if(requestMes.Contains("\"callBackUrl\"")) { CallBackUrl = data["callBackUrl"].ToString(); } req.Add("CallBackUrl", CallBackUrl); RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req)); result.Add("code", 0); result.Add("status", "success"); result.Add("msg", "成功"); // WebCMSEntities db = new WebCMSEntities(); // PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == sn); // if(pos != null) // { // Dictionary req = new Dictionary(); // req.Add("PosSnId", pos.Id); // req.Add("BrandId", 12); // req.Add("Deposit", serviceFee); // RedisDbconn.Instance.AddList("ChangePosFeeQueue", Newtonsoft.Json.JsonConvert.SerializeObject(req)); // result.Add("code", 0); // result.Add("status", "success"); // result.Add("msg", "成功"); // } // else // { // result.Add("code", 1); // result.Add("status", "fail"); // result.Add("msg", "机具号不存在"); // } } catch(Exception ex) { Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "设置押金异常"); result.Add("code", 1); result.Add("status", "fail"); result.Add("msg", "异常"); } return result; } public string AesDecrypt(string str, string key) { if (string.IsNullOrEmpty(str)) return null; byte[] toEncryptArray = Convert.FromBase64String(str); System.Security.Cryptography.RijndaelManaged rm = new System.Security.Cryptography.RijndaelManaged { Key = Encoding.UTF8.GetBytes(key), Mode = System.Security.Cryptography.CipherMode.ECB, Padding = System.Security.Cryptography.PaddingMode.PKCS7, }; System.Security.Cryptography.ICryptoTransform cTransform = rm.CreateDecryptor(); byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length); return Encoding.UTF8.GetString(resultArray); } #endregion } }