Selaa lähdekoodia

添加支付宝-手机网站支付通知 及相关例程更新

Roc 7 vuotta sitten
vanhempi
sitoutus
6828d8b887

+ 35 - 2
samples/WebApplicationSample/Controllers/AlipayController.cs

@@ -38,6 +38,26 @@ namespace WebApplicationSample.Controllers
             return Redirect(response.Body);
         }
 
+        [HttpPost]
+        public async Task<IActionResult> WapPay(string out_trade_no, string subject, string total_amount, string body, string product_code, string notify_url, string return_url)
+        {
+            var model = new AlipayTradeWapPayModel()
+            {
+                Body = body,
+                Subject = subject,
+                TotalAmount = total_amount,
+                OutTradeNo = out_trade_no,
+                ProductCode = product_code,
+            };
+            var req = new AlipayTradeWapPayRequest();
+            req.SetBizModel(model);
+            req.SetNotifyUrl(notify_url);
+            req.SetReturnUrl(return_url);
+
+            var response = await _client.PageExecuteAsync(req, null, "GET");
+            return Redirect(response.Body);
+        }
+
         [HttpPost]
         public async Task<IActionResult> PreCreate(string out_trade_no, string subject, string total_amount, string body, string notify_url)
         {
@@ -172,9 +192,8 @@ namespace WebApplicationSample.Controllers
             return Ok(response.Body);
         }
 
-
         [HttpGet]
-        public IActionResult Return()
+        public IActionResult PagePayReturn()
         {
             try
             {
@@ -186,5 +205,19 @@ namespace WebApplicationSample.Controllers
                 return Content("error", "text/plain");
             }
         }
+
+        [HttpGet]
+        public IActionResult WapPayReturn()
+        {
+            try
+            {
+                var notify = _notifyClient.Execute<AlipayTradeWapPayReturnResponse>(Request);
+                return Content("success", "text/plain");
+            }
+            catch
+            {
+                return Content("error", "text/plain");
+            }
+        }
     }
 }

+ 26 - 1
samples/WebApplicationSample/Controllers/NotifyController.cs

@@ -22,7 +22,7 @@ namespace WebApplicationSample.Controllers
         }
 
         /// <summary>
-        /// 网页支付异步通知
+        /// 电脑网站支付异步通知
         /// </summary>
         /// <returns></returns>
         [Route("pagepay")]
@@ -46,6 +46,31 @@ namespace WebApplicationSample.Controllers
             }
         }
 
+        /// <summary>
+        /// 手机支付异步通知
+        /// </summary>
+        /// <returns></returns>
+        [Route("wappay")]
+        [HttpPost]
+        public IActionResult WapPay()
+        {
+            try
+            {
+                var notify = _client.Execute<AlipayTradeWapPayNotifyResponse>(Request);
+                if ("TRADE_SUCCESS" == notify.TradeStatus)
+                {
+                    Console.WriteLine("OutTradeNo: " + notify.OutTradeNo);
+
+                    return Content("success", "text/plain");
+                }
+                return NoContent();
+            }
+            catch
+            {
+                return NoContent();
+            }
+        }
+
         /// <summary>
         /// 扫码支付异步通知
         /// </summary>

+ 60 - 19
samples/WebApplicationSample/Views/Home/Index.cshtml

@@ -31,15 +31,16 @@
         <div id="tabs-api-alipay">
             <div id="tabs-purchase-alipay">
                 <ul>
-                    <li><a href="#tabs-purchase-1">网页支付</a></li>
-                    <li><a href="#tabs-purchase-2">扫码支付</a></li>
-                    <li><a href="#tabs-purchase-3">交易查询</a></li>
-                    <li><a href="#tabs-purchase-4">交易退款</a></li>
-                    <li><a href="#tabs-purchase-5">退款查询</a></li>
-                    <li><a href="#tabs-purchase-6">交易关闭</a></li>
-                    <li><a href="#tabs-purchase-7">单笔转账</a></li>
-                    <li><a href="#tabs-purchase-8">转账查询</a></li>
-                    <li><a href="#tabs-purchase-9">对账查询</a></li>
+                    <li><a href="#tabs-purchase-1">电脑网站支付</a></li>
+                    <li><a href="#tabs-purchase-2">手机网站支付</a></li>
+                    <li><a href="#tabs-purchase-3">扫码支付</a></li>
+                    <li><a href="#tabs-purchase-4">交易查询</a></li>
+                    <li><a href="#tabs-purchase-5">交易退款</a></li>
+                    <li><a href="#tabs-purchase-6">退款查询</a></li>
+                    <li><a href="#tabs-purchase-7">交易关闭</a></li>
+                    <li><a href="#tabs-purchase-8">单笔转账</a></li>
+                    <li><a href="#tabs-purchase-9">转账查询</a></li>
+                    <li><a href="#tabs-purchase-10">对账查询</a></li>
                 </ul>
                 <div id="tabs-purchase-1">
                     <form class="api-form" asp-controller="Alipay" asp-action="PagePay" method="post" target="_blank">
@@ -49,7 +50,7 @@
                         </p>
                         <p>
                             <label>subject:</label>
-                            <input type="text" name="subject" value="支付宝网页支付测试">
+                            <input type="text" name="subject" value="支付宝电脑网站支付测试">
                         </p>
                         <p>
                             <label>total_amount:</label>
@@ -69,7 +70,7 @@
                         </p>
                         <p>
                             <label>return_url:</label>
-                            <input type="text" name="return_url" value="http://www.baidu.com/alipay/return">
+                            <input type="text" name="return_url" value="http://www.baidu.com/alipay/pagepayreturn">
                         </p>
                         <p>
                             <label>&nbsp;</label>
@@ -81,8 +82,48 @@
                         <a href="https://docs.open.alipay.com/270/alipay.trade.page.pay" target="_blank">* 查看接口 请求参数、响应参数</a>
                     </p>
                 </div>
-
                 <div id="tabs-purchase-2">
+                    <form class="api-form" asp-controller="Alipay" asp-action="WapPay" method="post" target="_blank">
+                        <p>
+                            <label>out_trade_no:</label>
+                            <input type="text" name="out_trade_no" value="@DateTime.Now.ToString("yyyyMMddHHmmssfff")">
+                        </p>
+                        <p>
+                            <label>subject:</label>
+                            <input type="text" name="subject" value="支付宝手机网站支付测试">
+                        </p>
+                        <p>
+                            <label>total_amount:</label>
+                            <input type="text" name="total_amount" value="0.01" title="单位为元,精确至小数点后2位。">
+                        </p>
+                        <p>
+                            <label>body:</label>
+                            <input type="text" name="body">
+                        </p>
+                        <p>
+                            <label>product_code:</label>
+                            <input type="text" name="product_code" value="QUICK_WAP_WAY">
+                        </p>
+                        <p>
+                            <label>notify_url:</label>
+                            <input type="text" name="notify_url" value="http://www.baidu.com/notify/alipay/wappay">
+                        </p>
+                        <p>
+                            <label>return_url:</label>
+                            <input type="text" name="return_url" value="http://www.baidu.com/alipay/wappayreturn">
+                        </p>
+                        <p>
+                            <label>&nbsp;</label>
+                            <input type="submit" class="button" value="提交">
+                        </p>
+                    </form>
+                    <hr />
+                    <p class="faq">
+                        <a href="https://docs.open.alipay.com/203/107090/" target="_blank">* 查看接口 请求参数、响应参数</a>
+                    </p>
+                </div>
+
+                <div id="tabs-purchase-3">
                     <form class="api-form" asp-controller="Alipay" asp-action="PreCreate" method="post" target="_blank">
                         <p>
                             <label>out_trade_no:</label>
@@ -115,7 +156,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-3">
+                <div id="tabs-purchase-4">
                     <form class="api-form" asp-controller="Alipay" asp-action="Query" method="post" target="_blank">
                         <p>
                             <label>out_trade_no:</label>
@@ -136,7 +177,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-4">
+                <div id="tabs-purchase-5">
                     <form class="api-form" asp-controller="Alipay" asp-action="Refund" method="post" target="_blank">
                         <p>
                             <label>out_trade_no:</label>
@@ -169,7 +210,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-5">
+                <div id="tabs-purchase-6">
                     <form class="api-form" asp-controller="Alipay" asp-action="RefundQuery" method="post" target="_blank">
                         <p>
                             <label>out_trade_no:</label>
@@ -194,7 +235,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-6">
+                <div id="tabs-purchase-7">
                     <form class="api-form" asp-controller="Alipay" asp-action="Close" method="post" target="_blank">
                         <p>
                             <label>out_trade_no:</label>
@@ -215,7 +256,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-7">
+                <div id="tabs-purchase-8">
                     <form class="api-form" asp-controller="Alipay" asp-action="Trans" method="post" target="_blank">
                         <p>
                             <label>out_biz_no:</label>
@@ -247,7 +288,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-8">
+                <div id="tabs-purchase-9">
                     <form class="api-form" asp-controller="Alipay" asp-action="TransQuery" method="post" target="_blank">
                         <p>
                             <label>out_biz_no:</label>
@@ -268,7 +309,7 @@
                     </p>
                 </div>
 
-                <div id="tabs-purchase-9">
+                <div id="tabs-purchase-10">
                     <form class="api-form" asp-controller="Alipay" asp-action="Close" method="post" target="_blank">
                         <p>
                             <label>bill_date:</label>

+ 1 - 1
src/Essensoft.AspNetCore.Alipay/Notify/AlipayTradePagePayNotifyResponse.cs

@@ -4,7 +4,7 @@ namespace Essensoft.AspNetCore.Alipay.Notify
 {
     /// <summary>
     /// 电脑网站支付结果异步通知
-    /// 更新时间:2017/07/28 
+    /// 更新时间:2017/10/27
     /// </summary>
     public class AlipayTradePagePayNotifyResponse : AlipayObject
     {

+ 197 - 0
src/Essensoft.AspNetCore.Alipay/Notify/AlipayTradeWapPayNotifyResponse.cs

@@ -0,0 +1,197 @@
+using Newtonsoft.Json;
+
+namespace Essensoft.AspNetCore.Alipay.Notify
+{
+    /// <summary>
+    /// 手机网站支付结果异步通知
+    /// 更新时间:2017/10/27
+    /// </summary>
+    public class AlipayTradeWapPayNotifyResponse : AlipayObject
+    {
+        /// <summary>
+        /// 通知时间
+        /// </summary>
+        [JsonProperty("notify_time")]
+        public string NotifyTime { get; set; }
+
+        /// <summary>
+        /// 通知类型
+        /// </summary>
+        [JsonProperty("notify_type")]
+        public string NotifyType { get; set; }
+
+        /// <summary>
+        /// 通知校验ID
+        /// </summary>
+        [JsonProperty("notify_id")]
+        public string NotifyId { get; set; }
+
+        /// <summary>
+        /// 开发者的app_id
+        /// </summary>
+        [JsonProperty("app_id")]
+        public string AppId { get; set; }
+
+        /// <summary>
+        /// 编码格式
+        /// </summary>
+        [JsonProperty("charset")]
+        public string Charset { get; set; }
+
+        /// <summary>
+        /// 接口版本
+        /// </summary>
+        [JsonProperty("version")]
+        public string Version { get; set; }
+
+        /// <summary>
+        /// 签名类型
+        /// </summary>
+        [JsonProperty("sign_type")]
+        public string SignType { get; set; }
+
+        /// <summary>
+        /// 签名
+        /// </summary>
+        [JsonProperty("sign")]
+        public string Sign { get; set; }
+
+        /// <summary>
+        /// 支付宝交易号
+        /// </summary>
+        [JsonProperty("trade_no")]
+        public string TradeNo { get; set; }
+
+        /// <summary>
+        /// 商户订单号
+        /// </summary>
+        [JsonProperty("out_trade_no")]
+        public string OutTradeNo { get; set; }
+
+        /// <summary>
+        /// 商户业务号
+        /// </summary>
+        [JsonProperty("out_biz_no")]
+        public string OutBizNo { get; set; }
+        
+        /// <summary>
+        /// 买家支付宝用户号
+        /// </summary>
+        [JsonProperty("buyer_id")]
+        public string BuyerId { get; set; }
+
+        /// <summary>
+        /// 买家支付宝账号
+        /// </summary>
+        [JsonProperty("buyer_logon_id")]
+        public string BuyerLogonId { get; set; }
+
+        /// <summary>
+        /// 卖家支付宝用户号
+        /// </summary>
+        [JsonProperty("seller_id")]
+        public string SellerId { get; set; }
+
+        /// <summary>
+        /// 卖家支付宝账号
+        /// </summary>
+        [JsonProperty("seller_email")]
+        public string SellerEmail { get; set; }
+
+        /// <summary>
+        /// 交易状态
+        /// </summary>
+        [JsonProperty("trade_status")]
+        public string TradeStatus { get; set; }
+
+        /// <summary>
+        /// 订单金额
+        /// </summary>
+        [JsonProperty("total_amount")]
+        public string TotalAmount { get; set; }
+
+        /// <summary>
+        /// 实收金额
+        /// </summary>
+        [JsonProperty("receipt_amount")]
+        public string ReceiptAmount { get; set; }
+
+        /// <summary>
+        /// 开票金额
+        /// </summary>
+        [JsonProperty("invoice_amount")]
+        public string InvoiceAmount { get; set; }
+
+        /// <summary>
+        /// 付款金额
+        /// </summary>
+        [JsonProperty("buyer_pay_amount")]
+        public string BuyerPayAmount { get; set; }
+
+        /// <summary>
+        /// 集分宝金额
+        /// </summary>
+        [JsonProperty("point_amount")]
+        public string PointAmount { get; set; }
+
+        /// <summary>
+        /// 总退款金额
+        /// </summary>
+        [JsonProperty("refund_fee")]
+        public string RefundFee { get; set; }
+
+        /// <summary>
+        /// 订单标题
+        /// </summary>
+        [JsonProperty("subject")]
+        public string Subject { get; set; }
+
+        /// <summary>
+        /// 商品描述
+        /// </summary>
+        [JsonProperty("body")]
+        public string Body { get; set; }
+
+        /// <summary>
+        /// 交易创建时间
+        /// </summary>
+        [JsonProperty("gmt_create")]
+        public string GmtCreate { get; set; }
+
+        /// <summary>
+        /// 交易付款时间
+        /// </summary>
+        [JsonProperty("gmt_payment")]
+        public string GmtPayment { get; set; }
+
+        /// <summary>
+        /// 交易退款时间
+        /// </summary>
+        [JsonProperty("gmt_refund")]
+        public string GmtRefund { get; set; }
+
+        /// <summary>
+        /// 交易结束时间
+        /// </summary>
+        [JsonProperty("gmt_close")]
+        public string GmtClose { get; set; }
+
+        /// <summary>
+        /// 支付金额信息
+        /// </summary>
+        [JsonProperty("fund_bill_list")]
+        public string FundBillList { get; set; }
+
+        /// <summary>
+        /// 回传参数
+        /// </summary>
+        [JsonProperty("passback_params")]
+        public string PassbackParams { get; set; }
+
+        /// <summary>
+        /// 优惠券信息
+        /// </summary>
+        [JsonProperty("voucher_detail_list")]
+        public string VoucherDetailList { get; set; }
+    }
+}

+ 81 - 0
src/Essensoft.AspNetCore.Alipay/Notify/AlipayTradeWapPayReturnResponse.cs

@@ -0,0 +1,81 @@
+using Newtonsoft.Json;
+
+namespace Essensoft.AspNetCore.Alipay.Notify
+{
+    /// <summary>
+    /// 手机网站支付页面回跳参数
+    /// 更新时间:2017-10-20
+    /// </summary>
+    public class AlipayTradeWapPayReturnResponse : AlipayObject
+    {
+        // 公共参数
+
+        /// <summary>
+        /// 开发者的app_id
+        /// </summary>
+        [JsonProperty("app_id")]
+        public string AppId { get; set; }
+
+        /// <summary>
+        /// 接口
+        /// </summary>
+        [JsonProperty("method")]
+        public string Method { get; set; }
+
+        /// <summary>
+        /// 签名类型
+        /// </summary>
+        [JsonProperty("sign_type")]
+        public string SignType { get; set; }
+
+        /// <summary>
+        /// 签名
+        /// </summary>
+        [JsonProperty("sign")]
+        public string Sign { get; set; }
+
+        /// <summary>
+        /// 编码格式
+        /// </summary>
+        [JsonProperty("charset")]
+        public string Charset { get; set; }
+
+        /// <summary>
+        /// 时间戳
+        /// </summary>
+        [JsonProperty("timestamp")]
+        public string Timestamp { get; set; }
+
+        /// <summary>
+        /// 接口版本
+        /// </summary>
+        [JsonProperty("version")]
+        public string Version { get; set; }
+
+        // 业务参数
+
+        /// <summary>
+        /// 商户订单号
+        /// </summary>
+        [JsonProperty("out_trade_no")]
+        public string OutTradeNo { get; set; }
+
+        /// <summary>
+        /// 支付宝交易号
+        /// </summary>
+        [JsonProperty("trade_no")]
+        public string TradeNo { get; set; }
+
+        /// <summary>
+        /// 订单金额
+        /// </summary>
+        [JsonProperty("total_amount")]
+        public string TotalAmount { get; set; }
+
+        /// <summary>
+        /// 卖家支付宝用户号
+        /// </summary>
+        [JsonProperty("seller_id")]
+        public string SellerId { get; set; }
+    }
+}