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; namespace MySystem.Areas.Api.Controllers.v1 { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class JkController : BaseController { public JkController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 金控-获取押金列表 [Authorize] public JsonResult GetDepositList(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); List> dataList = GetDepositListDo(value); return Json(new AppResultJson() { Status = "1", Info = "", Data = dataList }); } public List> GetDepositListDo(string value) { JsonData data = JsonMapper.ToObject(value); List> dataList = new List>(); Dictionary row = new Dictionary(); row.Add("Id", "0"); row.Add("Name", "押0"); dataList.Add(row); row = new Dictionary(); row.Add("Id", "99"); row.Add("Name", "押99"); dataList.Add(row); row = new Dictionary(); row.Add("Id", "199"); row.Add("Name", "押199"); dataList.Add(row); return dataList; } #endregion #region 金控-设置押金 [Authorize] public JsonResult SetDeposit(string value) { value = DesDecrypt(value); JsonData data = JsonMapper.ToObject(value); int UserId = int.Parse(function.CheckInt(data["UserId"].ToString())); string SnIds = data["SnIds"].ToString(); //机具Id列表 string check = RedisDbconn.Instance.Get("SetDepositWait:" + UserId); if (!string.IsNullOrEmpty(check)) { return Json(new AppResultJson() { Status = "-1", Info = "操作频繁,请稍后再试" }); } RedisDbconn.Instance.Set("SetDepositWait:" + UserId, SnIds); RedisDbconn.Instance.SetExpire("SetDepositWait:" + UserId, 120); string DepositId = data["DepositId"].ToString(); //押金Id Dictionary Obj = new Dictionary(); string[] SnIdList = SnIds.Split(','); foreach (string SnId in SnIdList) { int SnIdNum = int.Parse(SnId); PosMachinesTwo pos = maindb.PosMachinesTwo.FirstOrDefault(m => m.Id == SnIdNum && m.UserId == UserId && m.BindingState == 0 && (string.IsNullOrEmpty(m.SeoKeyword) || m.SeoKeyword == "0")); if (pos == null) { return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "已设置押金,请勿重复设置" }); } function.WriteLog(DateTime.Now.ToString() + ":请求参数," + pos.PosSn + ":" + DepositId, "金控-设置押金-返回报文"); string content = function.GetWebRequest("http://sp.kexiaoshuang.com/api/test/SetDeposit?sn=" + pos.PosSn + "&num=" + DepositId); //PublicImportDataService.Instance.SetDeposit(pos.PosSn, decimal.Parse(DepositId)); function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文"); if (content == "fail") { return Json(new AppResultJson() { Status = "-1", Info = "机具" + pos.PosSn + "设置失败" }); } JsonData jsonObj = JsonMapper.ToObject(content); if (jsonObj["code"].ToString() != "000000") { return Json(new AppResultJson() { Status = "-1", Info = jsonObj["message"].ToString() }); } content = jsonObj["data"].ToString(); content = PublicImportDataService.Instance.Decrypt(content); function.WriteLog(DateTime.Now.ToString() + "\n" + content, "金控-设置押金-返回报文"); JsonData contentObj = JsonMapper.ToObject(content); if (contentObj["respCode"].ToString() != "00") { return Json(new AppResultJson() { Status = "-1", Info = contentObj["respMsg"].ToString() }); } var BeforeDeposit = 0; if (string.IsNullOrEmpty(pos.PrizeParams)) { if (RelationClass.GetKqProductBrandInfo(pos.BrandId) == "立刷云电签") { BeforeDeposit = 249; } else { BeforeDeposit = 299; } } else { BeforeDeposit = int.Parse(pos.PrizeParams); } decimal amount = decimal.Parse(DepositId); pos.PrizeParams = amount.ToString("f0"); maindb.SaveChanges(); //设置押金添加记录 PublicFunction.MerchantDepositSet(pos.BrandId, UserId, SnIdNum, pos.PosSn, BeforeDeposit, decimal.Parse(pos.PrizeParams), content); } return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj }); } #endregion #region 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 检查签名是否合法,合法返回1,不合法返回提示信息 /// /// 请求的参数(json字符串) /// 要签名的字段 /// private string CheckSign(string value, string[] signField) { JsonData json = JsonMapper.ToObject(value); Dictionary dic = new Dictionary(); for (int i = 0; i < signField.Length; i++) { dic.Add(signField[i], json[signField[i]].ToString()); } string sign = json["sign"].ToString(); //客户端签名字符串 return new Sign().sign(dic, sign); } #endregion } }