using System; using System.Collections.Generic; using System.Linq; using System.Web; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Http; using System.IO; using Library; using LitJson; using System.Threading.Tasks; namespace MySystem.Areas.Api.Controllers { [Area("Api")] [Route("Api/v1/[controller]/[action]")] public class KqController : Admin.Controllers.BaseController { public KqController(IHttpContextAccessor accessor, ILogger logger, IOptions setting) : base(accessor, logger, setting) { } #region 接收绑定记录 [HttpPost] [Route("/posNofity")] [Route("/kxs/bind/{BrandId:int}")] public Dictionary Bind(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "绑定", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_bind_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_bind_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 接收激活记录 [HttpPost] [Route("/rebateNofity")] [Route("/kxs/active/{BrandId:int}")] public Dictionary Active(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "激活", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_active_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_active_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 接收商户记录 [HttpPost] [Route("/kxs/merchant/{BrandId:int}")] public Dictionary Merchant(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } RedisDbconn.Instance.AddList("kxs_merchant_list_" + BrandId, requestMes); return BackInfo(BrandId, requestMes); } #endregion #region 接收交易记录 [HttpPost] [Route("/transOrderNofity")] [Route("/kxs/trade/{BrandId:int}")] public Dictionary Trade(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "交易", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_trade_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_trade_list_" + BrandId + "/", fileName+".txt", content); Dictionary obj = new Dictionary(); return BackInfo(BrandId, requestMes); } #endregion #region 接收分润记录 [HttpPost] [Route("/kxs/profit/{BrandId:int}")] public Dictionary Profit(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "分润", content); RedisDbconn.Instance.AddList("kxs_profit_list_" + BrandId, requestMes); return BackInfo(BrandId, requestMes); } #endregion #region 接收流量卡分佣交易记录 [HttpPost] [Route("/kxs/flux/{BrandId:int}")] public Dictionary Flux(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "流量卡交易", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_flux_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_flux_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 接收商终关系变更通知 [HttpPost] [Route("/kxs/changebind/{BrandId:int}")] public Dictionary ChangeBind(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "商终关系变更", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_changebind_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_changebind_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 接收商户信息通知 [HttpPost] [Route("/kxs/merchantinfo/{BrandId:int}")] public Dictionary MerchantInfo(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "商户信息通知", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_merchantinfo_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_merchantinfo_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 终端费率模板变更记录 [HttpPost] [Route("/kxs/tempchange/{BrandId:int}")] public Dictionary TempChange(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "终端费率模板变更", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_tempchange_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_tempchange_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 首刷达标数据 [HttpPost] [Route("/kxs/first/{BrandId:int}")] public Dictionary First(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "首刷达标", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_first_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_first_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 换绑数据 [HttpPost] [Route("/kxs/changebinddata/{BrandId:int}")] public Dictionary ChangeBindData(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "换绑", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_changebinddata_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_changebinddata_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 商户SVIP会员开通和续费数据 [HttpPost] [Route("/kxs/svip/{BrandId:int}")] public Dictionary SVip(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "商户SVIP会员开通和续费", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_svip_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_svip_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 解绑数据 [HttpPost] [Route("/kxs/unbind/{BrandId:int}")] public Dictionary UnBind(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "解绑", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_unbind_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_unbind_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 修改结算卡数据 [HttpPost] [Route("/kxs/modifybankcard/{BrandId:int}")] public Dictionary ModifyBankCard(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "修改结算卡", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_modifybankcard_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_modifybankcard_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 提现通知 [HttpPost] [Route("/kxs/cash/{BrandId:int}")] public Dictionary Cash(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "提现", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_cash_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_cash_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 结算通知业务 [HttpPost] [Route("/kxs/settle/{BrandId:int}")] public Dictionary Settle(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "结算业务", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_settle_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_settle_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion #region 手续费和秒到费 [HttpPost] [Route("/kxs/rate/{BrandId:int}")] public Dictionary Rate(int BrandId = 1) { StreamReader sr = new StreamReader(Request.Body); string requestMes = sr.ReadToEnd(); if (string.IsNullOrEmpty(requestMes)) { return new Dictionary(); } string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; SaveLog(BrandId, "手续费和秒到费", content); string fileName = function.MD5_16(Guid.NewGuid().ToString()); RedisDbconn.Instance.AddList("kxs_rate_list_" + BrandId, content + "#cut#" + fileName); // function.WritePage("/redis/kxs_rate_list_" + BrandId + "/", fileName+".txt", content); return BackInfo(BrandId, requestMes); } #endregion // #region WIFI解绑 // [HttpPost] // [Route("/kxs/unbind/wifi")] // public Dictionary UnBindWifi() // { // StreamReader sr = new StreamReader(Request.Body); // string requestMes = sr.ReadToEnd(); // if (string.IsNullOrEmpty(requestMes)) // { // return new Dictionary(); // } // string content = Newtonsoft.Json.JsonConvert.SerializeObject(Request.Headers) + "#cut#" + requestMes; // SaveLog(23, "解绑", content); // string fileName = function.MD5_16(Guid.NewGuid().ToString()); // RedisDbconn.Instance.AddList("kxs_unbindwifi_list", content + "#cut#" + fileName); // Dictionary obj = new Dictionary(); // obj.Add("resCode", 200); // obj.Add("resMsg", "success"); // return obj; // } // #endregion #region 接收参数日志 private void SaveLog(int BrandId, string KindName, string content) { if (BrandId == 2) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "开店宝" + KindName + "推送消息"); } else if (BrandId == 4) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "乐刷" + KindName + "推送消息"); } else if (BrandId == 6) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "立刷" + KindName + "推送消息"); } else if (BrandId == 22) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "立刷微电签" + KindName + "推送消息"); } else if (BrandId == 7) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "盛付通" + KindName + "推送消息"); } else if (BrandId == 8) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "海科电签" + KindName + "推送消息"); } else if (BrandId == 9) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "海科大POS" + KindName + "推送消息"); } else if (BrandId == 10 || BrandId == 11) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "联动" + KindName + "推送消息"); } else if (BrandId == 12) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "盒易付电签" + KindName + "推送消息"); } else if (BrandId == 15) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "联客宝" + KindName + "推送消息"); } else if (BrandId == 23) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "WIFI" + KindName + "推送消息"); } else if (BrandId == 34) { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "联动掌中宝" + KindName + "推送消息"); } else { LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "金控" + KindName + "推送消息"); } } #endregion #region 返回报文 private Dictionary BackInfo(int BrandId, string RequestMes = "") { Dictionary obj = new Dictionary(); if (BrandId == 2) { obj.Add("code", "200"); } else if (BrandId == 4) { obj.Add("code", "0"); obj.Add("message", "成功"); } else if (BrandId == 6 || BrandId == 22) { obj.Add("ret_code", "00"); obj.Add("ret_msg", "SUCCESS"); } else if (BrandId == 10 || BrandId == 11) { obj.Add("retCode", "SUCCESS"); obj.Add("retMessage", "OK"); } else if (BrandId == 12) { if(RequestMes.Contains("\"ordId\"")) { JsonData jsonObj = JsonMapper.ToObject(RequestMes); obj.Add("recvOrdId", "RECV_ORD_ID_" + jsonObj["ordId"].ToString()); } obj.Add("resultCode", "0"); } else if (BrandId == 15 || BrandId == 17) { obj.Add("code", "200"); obj.Add("status", "success"); } else if (BrandId == 30) { obj.Add("code", "200"); obj.Add("msg", "success"); } else { obj = PublicImportDataService.Instance.CallBack(); } return obj; } #endregion #region 解析get请求键值对 private Dictionary GetParams(string data) { Dictionary result = new Dictionary(); string[] datalist = data.Split('&'); foreach (string sub in datalist) { string[] subdatalist = sub.Split('='); result.Add(subdatalist[0], subdatalist[1]); } return result; } #endregion } }