SpNoticeHelper.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Threading;
  5. using Library;
  6. using LitJson;
  7. using MySystem;
  8. public class SpNoticeHelper
  9. {
  10. public readonly static SpNoticeHelper Instance = new SpNoticeHelper();
  11. private SpNoticeHelper()
  12. { }
  13. public void Start()
  14. {
  15. Thread th = new Thread(DoWorks);
  16. th.IsBackground = true;
  17. th.Start();
  18. }
  19. public void DoWorks()
  20. {
  21. while (true)
  22. {
  23. string content = RedisDbconn.Instance.RPop<string>("SpSingleNotice");
  24. if (!string.IsNullOrEmpty(content))
  25. {
  26. try
  27. {
  28. DoQueue(content);
  29. }
  30. catch (Exception ex)
  31. {
  32. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + content + "\n" + ex, "统一URL地址接收消息异常");
  33. }
  34. }
  35. else
  36. {
  37. Thread.Sleep(5000);
  38. }
  39. }
  40. }
  41. public void DoQueue(string content)
  42. {
  43. string[] contents = content.Split(new string[] { "#cut#" }, StringSplitOptions.None);
  44. string Headers = contents[0];
  45. string Body = contents[1];
  46. int BrandId = int.Parse(contents[2]);
  47. if (BrandId == 7)
  48. {
  49. JsonData JsonObj = JsonMapper.ToObject(Body);
  50. if (Body.Contains("\"businessType\""))
  51. {
  52. string businessType = JsonObj["businessType"].ToString();
  53. Body = JsonObj["dataJson"].ToJson();
  54. if (businessType == "1")
  55. {
  56. Bind(Headers, Body, BrandId);
  57. }
  58. else if (businessType == "2")
  59. {
  60. Active(Headers, Body, BrandId);
  61. }
  62. else if (businessType == "4")
  63. {
  64. Settle(Headers, Body, BrandId);
  65. }
  66. else if (businessType == "5")
  67. {
  68. Cash(Headers, Body, BrandId);
  69. }
  70. else if (businessType == "6")
  71. {
  72. Flux(Headers, Body, BrandId);
  73. }
  74. }
  75. else
  76. {
  77. Trade(Headers, Body, BrandId);
  78. }
  79. }
  80. }
  81. #region 接收绑定记录
  82. public string Bind(string Headers, string Body, int BrandId = 1)
  83. {
  84. if (string.IsNullOrEmpty(Body))
  85. {
  86. return "fail";
  87. }
  88. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  89. SaveLog(BrandId, "绑定", content);
  90. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  91. RedisDbconn.Instance.AddList("kxs_bind_list_" + BrandId, content + "#cut#" + fileName);
  92. // function.WritePage("/redis/kxs_bind_list_" + BrandId + "/", fileName + ".txt", content);
  93. return BackInfo(BrandId);
  94. }
  95. #endregion
  96. #region 接收激活记录
  97. public string Active(string Headers, string Body, int BrandId = 1)
  98. {
  99. if (string.IsNullOrEmpty(Body))
  100. {
  101. return "fail";
  102. }
  103. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  104. SaveLog(BrandId, "激活", content);
  105. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  106. RedisDbconn.Instance.AddList("kxs_active_list_" + BrandId, content + "#cut#" + fileName);
  107. // function.WritePage("/redis/kxs_active_list_" + BrandId + "/", fileName + ".txt", content);
  108. return BackInfo(BrandId);
  109. }
  110. #endregion
  111. #region 接收商户记录
  112. public string Merchant(string Headers, string Body, int BrandId = 1)
  113. {
  114. if (string.IsNullOrEmpty(Body))
  115. {
  116. return "fail";
  117. }
  118. RedisDbconn.Instance.AddList("kxs_merchant_list_" + BrandId, Body);
  119. return BackInfo(BrandId);
  120. }
  121. #endregion
  122. #region 接收交易记录
  123. public string Trade(string Headers, string Body, int BrandId = 1)
  124. {
  125. if (string.IsNullOrEmpty(Body))
  126. {
  127. return "fail";
  128. }
  129. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  130. SaveLog(BrandId, "交易", content);
  131. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  132. RedisDbconn.Instance.AddList("kxs_trade_list_" + BrandId, content + "#cut#" + fileName);
  133. // function.WritePage("/redis/kxs_trade_list_" + BrandId + "/", fileName + ".txt", content);
  134. Dictionary<string, object> obj = new Dictionary<string, object>();
  135. return BackInfo(BrandId);
  136. }
  137. #endregion
  138. #region 接收分润记录
  139. public string Profit(string Headers, string Body, int BrandId = 1)
  140. {
  141. if (string.IsNullOrEmpty(Body))
  142. {
  143. return "fail";
  144. }
  145. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  146. SaveLog(BrandId, "分润", content);
  147. RedisDbconn.Instance.AddList("kxs_profit_list_" + BrandId, Body);
  148. return BackInfo(BrandId);
  149. }
  150. #endregion
  151. #region 接收流量卡分佣交易记录
  152. public string Flux(string Headers, string Body, int BrandId = 1)
  153. {
  154. if (string.IsNullOrEmpty(Body))
  155. {
  156. return "fail";
  157. }
  158. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  159. SaveLog(BrandId, "流量卡交易", content);
  160. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  161. RedisDbconn.Instance.AddList("kxs_flux_list_" + BrandId, content + "#cut#" + fileName);
  162. // function.WritePage("/redis/kxs_flux_list_" + BrandId + "/", fileName + ".txt", content);
  163. return BackInfo(BrandId);
  164. }
  165. #endregion
  166. #region 接收商终关系变更通知
  167. public string ChangeBind(string Headers, string Body, int BrandId = 1)
  168. {
  169. if (string.IsNullOrEmpty(Body))
  170. {
  171. return "fail";
  172. }
  173. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  174. SaveLog(BrandId, "商终关系变更", content);
  175. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  176. RedisDbconn.Instance.AddList("kxs_changebind_list_" + BrandId, content + "#cut#" + fileName);
  177. // function.WritePage("/redis/kxs_changebind_list_" + BrandId + "/", fileName + ".txt", content);
  178. return BackInfo(BrandId);
  179. }
  180. #endregion
  181. #region 终端费率模板变更记录
  182. public string TempChange(string Headers, string Body, int BrandId = 1)
  183. {
  184. if (string.IsNullOrEmpty(Body))
  185. {
  186. return "fail";
  187. }
  188. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  189. SaveLog(BrandId, "终端费率模板变更", content);
  190. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  191. RedisDbconn.Instance.AddList("kxs_tempchange_list_" + BrandId, content + "#cut#" + fileName);
  192. // function.WritePage("/redis/kxs_tempchange_list_" + BrandId + "/", fileName + ".txt", content);
  193. return BackInfo(BrandId);
  194. }
  195. #endregion
  196. #region 首刷达标数据
  197. public string First(string Headers, string Body, int BrandId = 1)
  198. {
  199. if (string.IsNullOrEmpty(Body))
  200. {
  201. return "fail";
  202. }
  203. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  204. SaveLog(BrandId, "首刷达标", content);
  205. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  206. RedisDbconn.Instance.AddList("kxs_first_list_" + BrandId, content + "#cut#" + fileName);
  207. // function.WritePage("/redis/kxs_first_list_" + BrandId + "/", fileName + ".txt", content);
  208. return BackInfo(BrandId);
  209. }
  210. #endregion
  211. #region 换绑数据
  212. public string ChangeBindData(string Headers, string Body, int BrandId = 1)
  213. {
  214. if (string.IsNullOrEmpty(Body))
  215. {
  216. return "fail";
  217. }
  218. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  219. SaveLog(BrandId, "换绑", content);
  220. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  221. RedisDbconn.Instance.AddList("kxs_changebinddata_list_" + BrandId, content + "#cut#" + fileName);
  222. // function.WritePage("/redis/kxs_changebinddata_list_" + BrandId + "/", fileName + ".txt", content);
  223. return BackInfo(BrandId);
  224. }
  225. #endregion
  226. #region 商户SVIP会员开通和续费数据
  227. public string SVip(string Headers, string Body, int BrandId = 1)
  228. {
  229. if (string.IsNullOrEmpty(Body))
  230. {
  231. return "fail";
  232. }
  233. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  234. SaveLog(BrandId, "商户SVIP会员开通和续费", content);
  235. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  236. RedisDbconn.Instance.AddList("kxs_svip_list_" + BrandId, content + "#cut#" + fileName);
  237. // function.WritePage("/redis/kxs_svip_list_" + BrandId + "/", fileName + ".txt", content);
  238. return BackInfo(BrandId);
  239. }
  240. #endregion
  241. #region 解绑数据
  242. public string UnBind(string Headers, string Body, int BrandId = 1)
  243. {
  244. if (string.IsNullOrEmpty(Body))
  245. {
  246. return "fail";
  247. }
  248. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  249. SaveLog(BrandId, "解绑", content);
  250. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  251. RedisDbconn.Instance.AddList("kxs_unbind_list_" + BrandId, content + "#cut#" + fileName);
  252. // function.WritePage("/redis/kxs_unbind_list_" + BrandId + "/", fileName + ".txt", content);
  253. return BackInfo(BrandId);
  254. }
  255. #endregion
  256. #region 修改结算卡数据
  257. public string ModifyBankCard(string Headers, string Body, int BrandId = 1)
  258. {
  259. if (string.IsNullOrEmpty(Body))
  260. {
  261. return "fail";
  262. }
  263. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  264. SaveLog(BrandId, "修改结算卡", content);
  265. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  266. RedisDbconn.Instance.AddList("kxs_modifybankcard_list_" + BrandId, content + "#cut#" + fileName);
  267. // function.WritePage("/redis/kxs_modifybankcard_list_" + BrandId + "/", fileName + ".txt", content);
  268. return BackInfo(BrandId);
  269. }
  270. #endregion
  271. #region 提现通知
  272. public string Cash(string Headers, string Body, int BrandId = 1)
  273. {
  274. if (string.IsNullOrEmpty(Body))
  275. {
  276. return "fail";
  277. }
  278. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  279. SaveLog(BrandId, "提现", content);
  280. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  281. RedisDbconn.Instance.AddList("kxs_cash_list_" + BrandId, content + "#cut#" + fileName);
  282. // function.WritePage("/redis/kxs_cash_list_" + BrandId + "/", fileName + ".txt", content);
  283. return BackInfo(BrandId);
  284. }
  285. #endregion
  286. #region 结算通知业务
  287. public string Settle(string Headers, string Body, int BrandId = 1)
  288. {
  289. if (string.IsNullOrEmpty(Body))
  290. {
  291. return "fail";
  292. }
  293. string content = Newtonsoft.Json.JsonConvert.SerializeObject(Headers) + "#cut#" + Body;
  294. SaveLog(BrandId, "结算业务", content);
  295. string fileName = function.MD5_16(Guid.NewGuid().ToString());
  296. RedisDbconn.Instance.AddList("kxs_settle_list_" + BrandId, content + "#cut#" + fileName);
  297. // function.WritePage("/redis/kxs_settle_list_" + BrandId + "/", fileName + ".txt", content);
  298. return BackInfo(BrandId);
  299. }
  300. #endregion
  301. #region 接收参数日志
  302. private void SaveLog(int BrandId, string KindName, string content)
  303. {
  304. if (BrandId == 2)
  305. {
  306. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "开店宝" + KindName + "推送消息");
  307. }
  308. else if (BrandId == 4)
  309. {
  310. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "乐刷" + KindName + "推送消息");
  311. }
  312. else if (BrandId == 6)
  313. {
  314. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "立刷" + KindName + "推送消息");
  315. }
  316. else if (BrandId == 7)
  317. {
  318. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "盛付通" + KindName + "推送消息");
  319. }
  320. else if (BrandId == 8)
  321. {
  322. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "海科电签" + KindName + "推送消息");
  323. }
  324. else if (BrandId == 9)
  325. {
  326. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "海科大POS" + KindName + "推送消息");
  327. }
  328. else
  329. {
  330. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + content, "金控" + KindName + "推送消息");
  331. }
  332. }
  333. #endregion
  334. #region 返回报文
  335. private string BackInfo(int BrandId)
  336. {
  337. return "SUCCESS";
  338. }
  339. #endregion
  340. #region 解析get请求键值对
  341. private Dictionary<string, string> GetParams(string data)
  342. {
  343. Dictionary<string, string> result = new Dictionary<string, string>();
  344. string[] datalist = data.Split('&');
  345. foreach (string sub in datalist)
  346. {
  347. string[] subdatalist = sub.Split('=');
  348. result.Add(subdatalist[0], subdatalist[1]);
  349. }
  350. return result;
  351. }
  352. #endregion
  353. }