123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading;
- using Library;
- using LitJson;
- using MySystem;
- public class SpNoticeHelper
- {
- public readonly static SpNoticeHelper Instance = new SpNoticeHelper();
- private SpNoticeHelper()
- { }
- public void Start()
- {
- Thread th = new Thread(DoWorks);
- th.IsBackground = true;
- th.Start();
- }
- public void DoWorks()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("SpSingleNotice");
- if (!string.IsNullOrEmpty(content))
- {
- try
- {
- DoQueue(content);
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "统一URL地址接收消息异常");
- }
- }
- else
- {
- Thread.Sleep(5000);
- }
- }
- }
- public void DoQueue(string content)
- {
- string[] contents = content.Split(new string[] { "#cut#" }, StringSplitOptions.None);
- string Headers = contents[0];
- string Body = contents[1];
- int BrandId = int.Parse(contents[2]);
- if (BrandId == 7)
- {
- JsonData JsonObj = JsonMapper.ToObject(Body);
- if (Body.Contains("\"businessType\""))
- {
- string businessType = JsonObj["businessType"].ToString();
- Body = JsonObj["dataJson"].ToJson();
- if (businessType == "1")
- {
- Bind(Headers, Body, BrandId);
- }
- else if (businessType == "2")
- {
- Active(Headers, Body, BrandId);
- }
- else if (businessType == "4")
- {
- Settle(Headers, Body, BrandId);
- }
- else if (businessType == "5")
- {
- Cash(Headers, Body, BrandId);
- }
- else if (businessType == "6")
- {
- Flux(Headers, Body, BrandId);
- }
- }
- else
- {
- Trade(Headers, Body, BrandId);
- }
- }
- }
- #region 接收绑定记录
- public string Bind(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 接收激活记录
- public string Active(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 接收商户记录
- public string Merchant(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- RedisDbconn.Instance.AddList("kxs_merchant_list_" + BrandId, Body);
- return BackInfo(BrandId);
- }
- #endregion
- #region 接收交易记录
- public string Trade(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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<string, object> obj = new Dictionary<string, object>();
- return BackInfo(BrandId);
- }
- #endregion
- #region 接收分润记录
- public string Profit(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- SaveLog(BrandId, "分润", content);
- RedisDbconn.Instance.AddList("kxs_profit_list_" + BrandId, Body);
- return BackInfo(BrandId);
- }
- #endregion
- #region 接收流量卡分佣交易记录
- public string Flux(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 接收商终关系变更通知
- public string ChangeBind(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 终端费率模板变更记录
- public string TempChange(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 首刷达标数据
- public string First(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 换绑数据
- public string ChangeBindData(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 商户SVIP会员开通和续费数据
- public string SVip(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 解绑数据
- public string UnBind(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 修改结算卡数据
- public string ModifyBankCard(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 提现通知
- public string Cash(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #endregion
- #region 结算通知业务
- public string Settle(string Headers, string Body, int BrandId = 1)
- {
- if (string.IsNullOrEmpty(Body))
- {
- return "fail";
- }
- string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
- 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);
- }
- #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 == 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
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "金控" + KindName + "推送消息");
- }
- }
- #endregion
- #region 返回报文
- private string BackInfo(int BrandId)
- {
- return "SUCCESS";
- }
- #endregion
- #region 解析get请求键值对
- private Dictionary<string, string> GetParams(string data)
- {
- Dictionary<string, string> result = new Dictionary<string, string>();
- string[] datalist = data.Split('&');
- foreach (string sub in datalist)
- {
- string[] subdatalist = sub.Split('=');
- result.Add(subdatalist[0], subdatalist[1]);
- }
- return result;
- }
- #endregion
- }
|