Przeglądaj źródła

服务费支付回调,区分直联银联

lcl 1 rok temu
rodzic
commit
aed3ad4b45
1 zmienionych plików z 54 dodań i 0 usunięć
  1. 54 0
      Areas/Api/Controllers/AlipayController.cs

+ 54 - 0
Areas/Api/Controllers/AlipayController.cs

@@ -118,5 +118,59 @@ namespace MySystem.Areas.Api.Controllers.v1
         }
         #endregion
 
+
+        // 支付回调
+        public string NoticePay()
+        {
+            StreamReader sr = new StreamReader(Request.Body);
+            string requestMes = sr.ReadToEnd();
+            function.WriteLog(DateTime.Now.ToString() + "\r\n" + requestMes + "\r\n\r\n", "支付宝支付回调2");
+            return PayCallBack2("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnw14hKejqS+si/XZpNQpFAVOVXJIThj5Qn7H14n/vsb7uRLug1+Jcve8ehTkaN3s5ibrrELCnz0dvshi3cOz9svDSbLG5OdC1biAvZzpDkvVPswOd9f9jO8Jvqk3QTXTI3MSN9gOpKomI0te3qs5kkOQx6kRozzKjU/G//o/PbJCxpBxf/QNRV3XmCwJLZMBE7ukYqi1WO9Jra8jdczFKwrd/nhiKBKdupAtVVeKlylGD2i2YLkGAH1cLsPUN9DtzrXNblGXm2HK3l9SnMDjqnakiVdEQJTNYNpEiHaOJsVmPQL38nM6miz5wNd4gTchKzXPtoZWqto+eIvYaEA/KwIDAQAB", requestMes);
+        }
+
+        public string PayCallBack2(string publickey, string requestMes, bool IsRedis = false)
+        {
+            // Library.function.WriteLog(requestMes, "支付宝回调日志");
+            var result = "fail";
+            var sPara = GetRequestPost(requestMes);
+            if (sPara.Count > 0) //判断是否有带返回参数
+            {
+                // Library.function.WriteLog("有参数", "支付宝回调日志");
+                bool verifyResult = false;
+                var aliNotify = new Com.Alipay.Notify();
+                string signtype = sPara["sign_type"];
+                var total_fee = 0m;
+                string strPrice = sPara["total_amount"];//金额
+                decimal.TryParse(strPrice, out total_fee);
+                verifyResult = AlipaySignature.RSACheckV1(sPara, publickey, "UTF-8", signtype, false);
+                // Library.function.WriteLog(verifyResult.ToString(), "支付宝回调日志");
+                if (verifyResult) //验证成功
+                {
+                    // Library.function.WriteLog("验证成功\r\n\r\n", "支付宝回调日志");
+                    //商户订单号
+                    string out_trade_no = sPara["out_trade_no"];
+                    //支付宝交易号
+                    string trade_no = sPara["trade_no"];
+                    //交易状态 TRADE_SUCCESS
+                    string trade_status = sPara["trade_status"];
+
+                    //交易成功
+                    if (trade_status == "TRADE_FINISHED" || trade_status == "TRADE_SUCCESS")
+                    {
+                        if(out_trade_no.StartsWith("D"))
+                        {
+                            RedisDbconn.Instance.AddList("AlipayCallBack1", "{\"out_trade_no\":\"" + out_trade_no + "\",\"transaction_id\":\"" + trade_no + "\",\"total_fee\":\"" + total_fee + "\",\"pay_mode\":\"1\",\"openid\":\"\",\"attach\":\"\"}");
+                        }
+                        else
+                        {
+                            RedisDbconn.Instance.AddList("AlipayCallBack2", "{\"out_trade_no\":\"" + out_trade_no + "\",\"transaction_id\":\"" + trade_no + "\",\"total_fee\":\"" + total_fee + "\",\"pay_mode\":\"1\",\"openid\":\"\",\"attach\":\"\"}");
+                        }
+                        result = "success";
+                    }
+                }
+            }
+            return result;
+        }
+        
     }
 }