Browse Source

Cleanup Code

Roc 6 years ago
parent
commit
13478cda6d

+ 29 - 28
samples/WebApplicationSample/Controllers/QPayController.cs

@@ -1,7 +1,7 @@
-using System.Security.Cryptography;
-using System.Threading.Tasks;
+using System.Threading.Tasks;
 using Essensoft.AspNetCore.Payment.QPay;
 using Essensoft.AspNetCore.Payment.QPay.Request;
+using Essensoft.AspNetCore.Payment.Security;
 using Microsoft.AspNetCore.Mvc;
 using WebApplicationSample.Models;
 
@@ -305,65 +305,66 @@ namespace WebApplicationSample.Controllers
         }
 
         /// <summary>
-        /// 对账单下载
+        /// 企业付款
         /// </summary>
         /// <returns></returns>
         [HttpGet]
-        public IActionResult StatementDown()
+        public IActionResult B2CPay()
         {
             return View();
         }
 
         /// <summary>
-        /// 对账单下载
+        /// 企业付款
         /// </summary>
         /// <param name="viewModel"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<IActionResult> StatementDown(QPayStatementDownViewModel viewModel)
+        public async Task<IActionResult> B2CPay(QPayB2CPayViewModel viewModel)
         {
-            var request = new QPayStatementDownRequest
+            var request = new QPayEPayB2CRequest
             {
-                BillDate = viewModel.BillDate,
-                BillType = viewModel.BillType,
-                TarType = viewModel.TarType
+                OpenId = viewModel.OpenId,
+                Uin = viewModel.Uin,
+                OutTradeNo = viewModel.OutTradeNo,
+                TotalFee = viewModel.TotalFee,
+                Memo = viewModel.Memo,
+                CheckRealName = viewModel.CheckRealName,
+                OpUserId = viewModel.OpUserId,
+                OpUserPasswd = MD5.Compute(viewModel.OpUserPasswd),
+                SpbillCreateIp = viewModel.SpbillCreateIp,
+                NotifyUrl = viewModel.NotifyUrl,
             };
-            var response = await _client.ExecuteAsync(request);
+            var response = await _client.ExecuteAsync(request, "qpayCertificateName");
             ViewData["response"] = response.Body;
             return View();
         }
+
         /// <summary>
-        /// 企业付款
+        /// 对账单下载
         /// </summary>
         /// <returns></returns>
         [HttpGet]
-        public IActionResult B2CPay()
+        public IActionResult StatementDown()
         {
             return View();
         }
+
         /// <summary>
-        /// 企业付款
+        /// 对账单下载
         /// </summary>
         /// <param name="viewModel"></param>
         /// <returns></returns>
         [HttpPost]
-        public async Task<IActionResult> B2CPay(QPayB2CPayViewModel viewModel)
+        public async Task<IActionResult> StatementDown(QPayStatementDownViewModel viewModel)
         {
-            var request = new QPayEPayB2CRequest
+            var request = new QPayStatementDownRequest
             {
-                OutTradeNo = viewModel.OutTradeNo,
-                TotalFee = viewModel.TotalFee,
-                SpbillCreateIp = viewModel.SpbillCreateIp,
-                NotifyUrl = viewModel.NotifyUrl,
-                AppId = viewModel.AppId,
-                Memo = viewModel.Memo,
-                OpenId = viewModel.OpenId,
-                OpUserId = viewModel.OpUserId,
-                OpUserPasswd= Essensoft.AspNetCore.Payment.Security.MD5.Compute(viewModel.OpUserPasswd),
-                CheckRealName="1",
-                Uin= viewModel.Uin
+                BillDate = viewModel.BillDate,
+                BillType = viewModel.BillType,
+                TarType = viewModel.TarType
             };
-            var response = await _client.ExecuteAsync(request,"test");
+            var response = await _client.ExecuteAsync(request);
             ViewData["response"] = response.Body;
             return View();
         }

+ 16 - 6
samples/WebApplicationSample/Models/QPayViewModel.cs

@@ -148,31 +148,41 @@ namespace WebApplicationSample.Models
         [Display(Name = "tar_type")]
         public string TarType { get; set; }
     }
+
     public class QPayB2CPayViewModel
     {
+        [Display(Name = "openid")]
+        public string OpenId { get; set; }
+
+        [Display(Name = "uin")]
+        public string Uin { get; set; }
+
         [Required]
         [Display(Name = "out_trade_no")]
         public string OutTradeNo { get; set; }
-        [Display(Name = "uin")]
-        public string Uin { get; set; }
-        [Display(Name = "appid")]
-        public string AppId { get; set; }
-        [Display(Name = "openid")]
-        public string OpenId { get; set; }
+
         [Display(Name = "total_fee")]
         [Required]
         public string TotalFee { get; set; }
+
         [Display(Name = "memo")]
         public string Memo { get; set; }
+
+        [Display(Name = "check_real_name")]
+        public string CheckRealName { get; set; }
+
         [Required]
         [Display(Name = "op_user_id")]
         public string OpUserId { get; set; }
+
         [Required]
         [Display(Name = "op_user_passwd")]
         public string OpUserPasswd { get; set; }
+
         [Required]
         [Display(Name = "spbill_create_ip")]
         public string SpbillCreateIp { get; set; }
+
         [Display(Name = "notify_url")]
         public string NotifyUrl { get; set; }
     }

+ 13 - 13
samples/WebApplicationSample/Views/QPay/B2CPay.cshtml

@@ -14,20 +14,16 @@
         <form asp-controller="QPay" asp-action="B2CPay">
             <div asp-validation-summary="All" class="text-danger"></div>
             <div class="form-group">
-                <label asp-for="OutTradeNo"></label>
-                <input type="text" class="form-control" asp-for="OutTradeNo" value="@DateTime.Now.ToString("yyyyMMddHHmmssfff")" />
+                <label asp-for="OpenId"></label>
+                <input type="text" class="form-control" asp-for="OpenId" />
             </div>
             <div class="form-group">
                 <label asp-for="Uin"></label>
-                <input type="text" class="form-control" asp-for="Uin" value="" />
-            </div>
-            <div class="form-group">
-                <label asp-for="AppId"></label>
-                <input type="text" class="form-control" asp-for="AppId" value="" />
+                <input type="text" class="form-control" asp-for="Uin" />
             </div>
             <div class="form-group">
-                <label asp-for="OpenId"></label>
-                <input type="text" class="form-control" asp-for="OpenId" value="" />
+                <label asp-for="OutTradeNo"></label>
+                <input type="text" class="form-control" asp-for="OutTradeNo" value="@DateTime.Now.ToString("yyyyMMddHHmmssfff")" />
             </div>
             <div class="form-group">
                 <label asp-for="TotalFee"></label>
@@ -35,15 +31,19 @@
             </div>
             <div class="form-group">
                 <label asp-for="Memo"></label>
-                <input type="text" class="form-control" asp-for="Memo" value="" />
+                <input type="text" class="form-control" asp-for="Memo" />
+            </div>
+            <div class="form-group">
+                <label asp-for="CheckRealName"></label>
+                <input type="text" class="form-control" asp-for="CheckRealName" value="0" />
             </div>
             <div class="form-group">
                 <label asp-for="OpUserId"></label>
-                <input type="text" class="form-control" asp-for="OpUserId" value="" />
+                <input type="text" class="form-control" asp-for="OpUserId" />
             </div>
             <div class="form-group">
                 <label asp-for="OpUserPasswd"></label>
-                <input type="text" class="form-control" asp-for="OpUserPasswd" value="" />
+                <input type="text" class="form-control" asp-for="OpUserPasswd" />
             </div>
             <div class="form-group">
                 <label asp-for="SpbillCreateIp"></label>
@@ -51,7 +51,7 @@
             </div>
             <div class="form-group">
                 <label asp-for="NotifyUrl"></label>
-                <input type="text" class="form-control" asp-for="NotifyUrl" value="" />
+                <input type="text" class="form-control" asp-for="NotifyUrl" />
             </div>
             <button type="submit" class="btn btn-primary">提交请求</button>
         </form>

+ 1 - 8
samples/WebApplicationSample/WebApplicationSample.csproj

@@ -8,7 +8,6 @@
 
   <ItemGroup>
     <PackageReference Include="Microsoft.AspNetCore.App" />
-    <PackageReference Include="Microsoft.Extensions.PlatformAbstractions" Version="1.1.0" />
     <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" />
   </ItemGroup>
 
@@ -20,11 +19,5 @@
     <ProjectReference Include="..\..\src\Essensoft.AspNetCore.Payment.UnionPay\Essensoft.AspNetCore.Payment.UnionPay.csproj" />
     <ProjectReference Include="..\..\src\Essensoft.AspNetCore.Payment.WeChatPay\Essensoft.AspNetCore.Payment.WeChatPay.csproj" />
   </ItemGroup>
-
-  <ItemGroup>
-    <Content Update="wwwroot\apiclient_cert.p12">
-      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
-    </Content>
-  </ItemGroup>
-
+ 
 </Project>