Browse Source

完善开户意愿结果,从官方获取认证状态

lcl 1 year ago
parent
commit
a13483dc37

+ 2 - 0
Startup.cs

@@ -148,6 +148,8 @@ namespace MySystem
                 HaoDaExtHelper.Instance.StartAlipay();
                 HaoDaExtQueryHelper.Instance.StartWeChat();
                 HaoDaExtQueryHelper.Instance.StartAlipay();
+                HaoDaExtQueryAuthHelper.Instance.StartWeChat();
+                HaoDaExtQueryAuthHelper.Instance.StartAlipay();
                 HaoDaAuthQueryHelper.Instance.Start(); //查询实名认证状态
                 WeChatPayBackService.Instance.Start(); //支付回调
                 WeChatPayBackService.Instance.StartProfitShare(); //分账队列

+ 123 - 0
Util/HaoDa/Alipay/Request/AlipayMerchantIndirectSmidbindQueryRequest.cs

@@ -0,0 +1,123 @@
+using System;
+using Aop.Api.Domain;
+using System.Collections.Generic;
+using Aop.Api.Response;
+
+namespace Aop.Api.Request
+{
+    /// <summary>
+    /// AOP API: alipay.merchant.indirect.smidbind.query
+    /// </summary>
+    public class AlipayMerchantIndirectSmidbindQueryRequest : IAopRequest<AlipayMerchantIndirectSmidbindQueryResponse>
+    {
+        /// <summary>
+        /// 获取商户意愿确认状态
+        /// </summary>
+        public string BizContent { get; set; }
+
+        #region IAopRequest Members
+        private bool  needEncrypt=false;
+        private string apiVersion = "1.0";
+	    private string terminalType;
+	    private string terminalInfo;
+        private string prodCode;
+	    private string notifyUrl;
+        private string returnUrl;
+	    private AopObject bizModel;
+        private Dictionary<string, string> udfParams; //add user-defined text parameters
+
+		public void SetNeedEncrypt(bool needEncrypt){
+             this.needEncrypt=needEncrypt;
+        }
+
+        public bool GetNeedEncrypt(){
+
+            return this.needEncrypt;
+        }
+
+		public void SetNotifyUrl(string notifyUrl){
+            this.notifyUrl = notifyUrl;
+        }
+
+        public string GetNotifyUrl(){
+            return this.notifyUrl;
+        }
+
+        public void SetReturnUrl(string returnUrl){
+            this.returnUrl = returnUrl;
+        }
+
+        public string GetReturnUrl(){
+            return this.returnUrl;
+        }
+
+        public void SetTerminalType(String terminalType){
+			this.terminalType=terminalType;
+		}
+
+    	public string GetTerminalType(){
+    		return this.terminalType;
+    	}
+
+    	public void SetTerminalInfo(String terminalInfo){
+    		this.terminalInfo=terminalInfo;
+    	}
+
+    	public string GetTerminalInfo(){
+    		return this.terminalInfo;
+    	}
+
+        public void SetProdCode(String prodCode){
+            this.prodCode=prodCode;
+        }
+
+        public string GetProdCode(){
+            return this.prodCode;
+        }
+
+        public string GetApiName()
+        {
+            return "alipay.merchant.indirect.smidbind.query";
+        }
+
+        public void SetApiVersion(string apiVersion){
+            this.apiVersion=apiVersion;
+        }
+
+        public string GetApiVersion(){
+            return this.apiVersion;
+        }
+
+        public void PutOtherTextParam(string key, string value) 
+        {
+            if(this.udfParams == null) 
+            {
+                this.udfParams = new Dictionary<string, string>();
+            }
+            this.udfParams.Add(key, value);
+        }
+
+        public IDictionary<string, string> GetParameters()
+        {
+            AopDictionary parameters = new AopDictionary();
+            parameters.Add("biz_content", this.BizContent);
+            if(udfParams != null) 
+            {
+                parameters.AddAll(this.udfParams);
+            }
+            return parameters;
+        }
+
+		public AopObject GetBizModel()
+        {
+            return this.bizModel;
+        }
+
+        public void SetBizModel(AopObject bizModel)
+        {
+            this.bizModel = bizModel;
+        }
+
+        #endregion
+    }
+}

+ 17 - 0
Util/HaoDa/Alipay/Response/AlipayMerchantIndirectSmidbindQueryResponse.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Xml.Serialization;
+
+namespace Aop.Api.Response
+{
+    /// <summary>
+    /// AlipayMerchantIndirectSmidbindQueryResponse.
+    /// </summary>
+    public class AlipayMerchantIndirectSmidbindQueryResponse : AopResponse
+    {
+        /// <summary>
+        /// 确认状态,枚举:已确认(AUTHORIZED)/未确认(UNAUTHORIZED)/已销户(CLOSED)/smid不存在(SMID_NOT_EXIST)
+        /// </summary>
+        [XmlElement("check_result")]
+        public string CheckResult { get; set; }
+    }
+}

+ 27 - 0
Util/HaoDa/AlipayFunctionForHD.cs

@@ -171,6 +171,33 @@ namespace MySystem
 
         #endregion
 
+        #region 获取商家认证状态
+        public string AuthOrderAuthQuery(string MerchantId)
+        {
+            IAopClient client = new DefaultAopClient("https://openapi.alipay.com/gateway.do", AppId, PrivateKey, "json", "1.0", "RSA2", AlipayPublicKey, "utf-8", false);
+            AlipayMerchantIndirectSmidbindQueryRequest request = new AlipayMerchantIndirectSmidbindQueryRequest();
+            request.BizContent = "{" +
+            "  \"sub_merchant_id\":\"" + MerchantId + "\"" +
+            "}";
+            LogHelper.Instance.WriteLog(request.BizContent, "获取商家认证状态");
+            string result = "";
+            try
+            {
+                //{\"alipay_merchant_indirect_smidbind_query_response\":{\"code\":\"10000\",\"msg\":\"Success\",\"check_result\":\"AUTHORIZED\"},\"sign\":\"PZo+ozUifPnIJhT/v9xG3PxJu612XMoLX3dgloqBzyyTK05FBtv9i2Au57PxnJYTvZ226JFPJC+QAEiTA3FOHdbd/dXwRtUrTg06SmXsXBipRiwNEwFxxvlGrsXzIPOi4C6nWsyphMDi9CJhLqkUhjO9cpZQE4x3MJ6PIFFjbuvqStJ0dS8xQjCqzygSU3foEetyh7IWs3To1DU8AARDJZ9eOTJB0bznT4g7f8EJgx/MpohRDWmIWWqJYq6HnPhGYtqQcPyuVKej6e9OjjKYe2fHbZPC966QoKHnptzBcNay7gvce8bSp9c78nmiz20moHttGdzZYjvvQ4zOuftExw==\"}
+                AlipayMerchantIndirectSmidbindQueryResponse response = client.Execute(request);
+                result = response.Body;
+                LogHelper.Instance.WriteLog(result, "获取商家认证状态");
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Instance.WriteLog(ex.ToString(), "获取商家认证状态异常");
+                result = "";
+            }
+            return result;
+        }
+
+        #endregion
+
         #region 图片上传
 
         public string UploadPic(string path)

+ 2 - 0
Util/HaoDa/HaoDaExtHelper.cs

@@ -56,6 +56,7 @@ public class HaoDaExtHelper
                 JsonData json = JsonMapper.ToObject(result);
                 string applyment_id = json["applyment_id"].ToString();
                 RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
+                RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
                 LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "提交微信商户意愿申请单");
                 LogHelper.Instance.WriteLog("end", "提交微信商户意愿申请单");
             }
@@ -121,6 +122,7 @@ public class HaoDaExtHelper
                 LogHelper.Instance.WriteLog("success", "提交支付宝商户意愿申请单");
                 string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
                 RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
+                RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
                 LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "提交支付宝商户意愿申请单");
                 LogHelper.Instance.WriteLog("end", "提交支付宝商户意愿申请单");
             }

+ 141 - 0
Util/HaoDa/HaoDaExtQueryAuthHelper.cs

@@ -0,0 +1,141 @@
+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;
+using MySystem.Models.Main;
+
+public class HaoDaExtQueryAuthHelper
+{
+    public readonly static HaoDaExtQueryAuthHelper Instance = new HaoDaExtQueryAuthHelper();
+    private HaoDaExtQueryAuthHelper()
+    {
+    }
+
+    public void StartWeChat()
+    {
+        Thread th = new Thread(StartWeChatDo);
+        th.IsBackground = true;
+        th.Start();
+    }
+
+    private void StartWeChatDo()
+    {
+        while (true)
+        {
+            string content = RedisDbconn.Instance.RPop<string>("WeChatAuthResultForHaoDaQueue");
+            if (!string.IsNullOrEmpty(content))
+            {
+                JsonData json = JsonMapper.ToObject(content);
+                WeChatAddInfo(int.Parse(json["MerchantId"].ToString()));
+            }
+            else
+            {
+                Thread.Sleep(10000);
+            }
+        }
+    }
+
+    public void WeChatAddInfo(int Id)
+    {
+        try
+        {
+            LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取微信商户开户意愿确认状态");
+            LogHelper.Instance.WriteLog("start", "获取微信商户开户意愿确认状态");
+            WebCMSEntities db = new WebCMSEntities();
+            MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
+            string result = WeChatFunctionForHD.Instance.QueryAuthMerchant(info.WeChatMerchantId);
+            LogHelper.Instance.WriteLog(result, "获取微信商户开户意愿确认状态");
+            JsonData jsonObj = JsonMapper.ToObject(result);
+            if (jsonObj["authorize_state"].ToString() == "AUTHORIZE_STATE_AUTHORIZED")
+            {
+                LogHelper.Instance.WriteLog("starts", "获取微信商户开户意愿确认状态");
+                MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
+                info.Status = 2;
+                merchant.Status = 2;
+                db.SaveChanges();
+                LogHelper.Instance.WriteLog("startsend", "获取微信商户开户意愿确认状态");
+            }
+            else
+            {
+                LogHelper.Instance.WriteLog("starte", "获取微信商户开户意愿确认状态");
+                RedisDbconn.Instance.AddList("WeChatAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
+                LogHelper.Instance.WriteLog("start2end", "获取微信商户开户意愿确认状态");
+            }
+            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>("AlipayAuthResultForHaoDaQueue");
+            if (!string.IsNullOrEmpty(content))
+            {
+                JsonData json = JsonMapper.ToObject(content);
+                AlipayAddInfo(int.Parse(json["MerchantId"].ToString()));
+            }
+            else
+            {
+                Thread.Sleep(10000);
+            }
+        }
+    }
+
+    public void AlipayAddInfo(int Id)
+    {
+        try
+        {
+            LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "获取支付宝商家认证状态");
+            LogHelper.Instance.WriteLog("start", "获取支付宝商家认证状态");
+            WebCMSEntities db = new WebCMSEntities();
+            MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
+            string result = AlipayFunctionForHD.Instance.AuthOrderAuthQuery(info.AliMerchantId);
+            JsonData jsonObj = JsonMapper.ToObject(result);
+            LogHelper.Instance.WriteLog(result, "获取支付宝商家认证状态");
+            if (jsonObj["alipay_merchant_indirect_smidbind_query_response"]["code"].ToString() == "10000")
+            {
+                LogHelper.Instance.WriteLog("starts", "获取支付宝商家认证状态");
+                string order_status = jsonObj["alipay_merchant_indirect_smidbind_query_response"]["check_result"].ToString();
+                LogHelper.Instance.WriteLog(order_status, "获取支付宝商家认证状态");
+                if (order_status == "AUTHORIZED")
+                {
+                    LogHelper.Instance.WriteLog("start1", "获取支付宝商家认证状态");
+                    MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
+                    info.QueryCount = 2;
+                    merchant.QueryCount = 2;
+                    db.SaveChanges();
+                    LogHelper.Instance.WriteLog("start1end", "获取支付宝商家认证状态");
+                }
+                else
+                {
+                    RedisDbconn.Instance.AddList("AlipayAuthResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\"}");
+                }
+            }
+            db.Dispose();
+        }
+        catch (Exception ex)
+        {
+            LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "获取支付宝商家认证状态异常");
+        }
+    }
+}

+ 5 - 2
Util/HaoDa/TestHaoDaService.cs

@@ -34,10 +34,13 @@ namespace MySystem
             // AlipayAddInfo(828,"202309011037906510");//查询支付宝开户意愿申请状态
             // WeChatAddInfo(826);//提交微信开户意愿申请单
             // WeChatAddInfo(825,"2000002424428809");//查询微信开户意愿申请状态
-            // QueryMerchantStatus(824);//新建商户查询状态
-            // QueryAuthStatus(826);//查询实名认证状态
+            // QueryMerchantStatus(832);//新建商户查询状态
+            // QueryAuthStatus(827);//查询实名认证状态
             // ConfiemMer(808);//新建商户
             // ChangeMerchantCard(1);//商户修改银行卡
+            // AddOpenDivideAccounts(832); //添加分账方
+            // WeChatFunctionForHD.Instance.QueryAuthMerchant("599626767");
+            // AlipayFunctionForHD.Instance.AuthOrderAuthQuery("2088820527237169");
         }
 
         //新建商户查询状态

+ 21 - 0
Util/HaoDa/WeChatFunctionForHD.cs

@@ -189,6 +189,27 @@ namespace MySystem
         #endregion
 
 
+        #region 获取商户开户意愿确认状态
+
+        public string QueryAuthMerchant(string MchId)
+        {
+            string result = "";
+            try
+            {
+                result = postJson("https://api.mch.weixin.qq.com/v3/apply4subject/applyment/merchants/" + MchId + "/state", "", "GET");
+                //{\"authorize_state\":\"AUTHORIZE_STATE_AUTHORIZED\"}
+                LogHelper.Instance.WriteLog(MchId, "获取商户开户意愿确认状态");
+                LogHelper.Instance.WriteLog(result, "获取商户开户意愿确认状态");
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "获取商户开户意愿确认状态异常");
+            }
+            return result;
+        }
+        #endregion
+
+
 
         #region 获取平台证书
 

+ 1 - 1
Util/LogHelper.cs

@@ -13,7 +13,7 @@ public class LogHelper
     private LogHelper()
     { }
 
-    string[] BlackList = { "好哒查询商户审核状态", "好哒查询实名认证状态", "好哒分账交易详情查询", "间连商户开户意愿确认(提交申请单)查询申请单状态-请求参数", "查询支付宝商家认证申请单状态", "查询支付宝商户意愿申请状态" };
+    string[] BlackList = { "好哒查询商户审核状态", "好哒查询实名认证状态", "好哒分账交易详情查询", "间连商户开户意愿确认(提交申请单)查询申请单状态-请求参数", "查询支付宝商家认证申请单状态", "查询支付宝商户意愿申请状态", "获取微信商户开户意愿确认状态", "获取支付宝商家认证状态" };
 
     public void WriteLog(string Content, string FileName, string BrandId = "0")
     {