using System; using System.Collections.Generic; using System.Linq; using MySystem.PxcModels; using Library; using LitJson; using System.Text.RegularExpressions; using System.Threading; namespace MySystem { public class CheckAlipaySignService { public readonly static CheckAlipaySignService Instance = new CheckAlipaySignService(); private CheckAlipaySignService() { } public void Start() { Thread th = new Thread(StartListen); th.IsBackground = true; th.Start(); } public void StartListen() { while (true) { string content = RedisDbconn.Instance.RPop("AlipaySignQueue"); if (!string.IsNullOrEmpty(content)) { string result = StartDo(Newtonsoft.Json.JsonConvert.DeserializeObject(content)); if(result == "wait") { Thread.Sleep(10000); RedisDbconn.Instance.AddList("AlipaySignQueue", content); } } else { Thread.Sleep(2000); } } } public string StartDo(MerchantSign sign) { try { PxcModels.WebCMSEntities db = new PxcModels.WebCMSEntities(); string content = new AlipayFunction().QuerySignStatus(sign.BusinessCode); JsonData dic = JsonMapper.ToObject(content); if (dic["alipay_open_agent_order_query_response"]["code"].ToString() == "10000") { if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM") { string sign_url = dic["alipay_open_agent_order_query_response"]["confirm_url"].ToString(); PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount == 0); if (merchantadd != null) { merchantadd.QueryCount = 1; string confirm_url = "/static/alipay_confirm_url/"; string fileName = function.MD5_16(Guid.NewGuid().ToString()); function.CreateQRCode2(sign_url, fileName, "/" + confirm_url); string SignUrlList = function.CheckNull(merchantadd.SeoKeyword); if (string.IsNullOrEmpty(SignUrlList)) { SignUrlList = "Alipay:" + confirm_url + ";"; } else { SignUrlList = "Alipay:" + confirm_url+ ";" + SignUrlList; } merchantadd.SeoKeyword = SignUrlList; merchantadd.SeoTitle = dic["alipay_open_agent_order_query_response"]["merchant_pid"].ToString(); db.SaveChanges(); } return "wait"; } else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_CONFIRM_SUCCESS") { PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId && m.QueryCount < 2); if (merchantadd != null) { merchantadd.QueryCount = 2; db.SaveChanges(); } } else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_APPLY_ORDER_CANCELED") { PxcModels.MerchantAddInfo merchantadd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId); if (merchantadd != null) { string Season = function.CheckNull(merchantadd.SeoDescription); if (string.IsNullOrEmpty(Season)) { Season = "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";"; } else { Season = Regex.Replace(Season, "Alipay:.*?;", ""); Season += "Alipay:" + dic["alipay_open_agent_order_query_response"]["reject_reason"].ToString() + ";"; } merchantadd.SeoDescription = Season; merchantadd.QueryCount = -1; PxcModels.MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == sign.MerchantAddInfoId); if (merchant != null) { merchant.Status = -1; } db.SaveChanges(); } } else if (dic["alipay_open_agent_order_query_response"]["order_status"].ToString() == "MERCHANT_AUDITING") { return "wait"; } } } catch (Exception ex) { function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public:merchant:signerr"); } return ""; } } }