123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Linq;
- using Microsoft.Extensions.Hosting;
- using MySystem;
- using MySystem.Models;
- using LitJson;
- using Library;
- public class HaoDaExtQueryHelper
- {
- public readonly static HaoDaExtQueryHelper Instance = new HaoDaExtQueryHelper();
- private HaoDaExtQueryHelper()
- {
- }
-
- public void StartWeChat()
- {
- Thread th = new Thread(StartWeChatDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartWeChatDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("WeChatResultForHaoDaQueue");
- if (!string.IsNullOrEmpty(content))
- {
- JsonData json = JsonMapper.ToObject(content);
- WeChatAddInfo(int.Parse(json["MerchantId"].ToString()), json["ApplymentId"].ToString());
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void WeChatAddInfo(int Id, string ApplymentId)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = WeChatFunctionForHD.Instance.QueryMerchant(ApplymentId);
- JsonData jsonObj = JsonMapper.ToObject(result);
- if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_FINISHED")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.Status = 1;
- merchant.Status = 1;
- info.WeChatRemark = "";
- info.WeChatSignUrl = jsonObj["sign_url"].ToString();
- db.SaveChanges();
- }
- else if (jsonObj["applyment_state"].ToString() == "APPLYMENT_STATE_REJECTED")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.Status = -1;
- merchant.Status = -1;
- info.WeChatRemark = jsonObj["reject_reason"].ToString();
- db.SaveChanges();
- }
- else
- {
- RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + ApplymentId + "\"}");
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
- }
- }
- public void StartAlipay()
- {
- Thread th = new Thread(StartAlipayDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartAlipayDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("AlipayResultForHaoDaQueue");
- if (!string.IsNullOrEmpty(content))
- {
- JsonData json = JsonMapper.ToObject(content);
- AlipayAddInfo(int.Parse(json["MerchantId"].ToString()), json["order_no"].ToString());
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void AlipayAddInfo(int Id, string OrderNo)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = AlipayFunctionForHD.Instance.AuthOrderQuery(OrderNo);
- JsonData jsonObj = JsonMapper.ToObject(result);
- if (jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["code"].ToString() == "10000")
- {
- string order_status = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["order_status"].ToString();
- if (order_status == "CONTACT_CONFIRM")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = 1;
- merchant.QueryCount = 1;
- info.AlipayRemark = "";
- info.AlipaySignUrl = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["qr_code"].ToString();
- db.SaveChanges();
- }
- else if (order_status == "AUDIT_PASS" || order_status == "AUDIT_REJECT" || order_status == "AUDIT_FREEZE")
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
- db.SaveChanges();
- }
- else
- {
- RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + OrderNo + "\"}");
- }
- }
- else
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_querystatus_response"]["msg"].ToString();
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
- }
- }
- }
|