6 changed files with 1244 additions and 0 deletions
-
31src/Shentun.WebPeis.Application.Contracts/Persons/GetPersonListInputDto.cs
-
34src/Shentun.WebPeis.Application.Contracts/Persons/PersonListDto.cs
-
98src/Shentun.WebPeis.Application.Contracts/WxPayHelpers/HttpHandler.cs
-
994src/Shentun.WebPeis.Application.Contracts/WxPayHelpers/WXPayHelper.cs
-
56src/Shentun.WebPeis.Application/Persons/PersonAppService.cs
-
31src/Shentun.WebPeis.Application/WxPayHelpers/WeiXinPayAppService.cs
@ -0,0 +1,31 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.WebPeis.Persons |
|||
{ |
|||
public class GetPersonListInputDto |
|||
{ |
|||
/// <summary>
|
|||
/// 人员姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 性别Id
|
|||
/// </summary>
|
|||
public char? SexId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号码
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Shentun.WebPeis.Persons |
|||
{ |
|||
public class PersonListDto |
|||
{ |
|||
/// <summary>
|
|||
/// 人员姓名
|
|||
/// </summary>
|
|||
public string PatientName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 性别
|
|||
/// </summary>
|
|||
public string SexName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 身份证号码
|
|||
/// </summary>
|
|||
public string IdNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 手机号码
|
|||
/// </summary>
|
|||
public string MobileTelephone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 注册时间
|
|||
/// </summary>
|
|||
public string CreationTime { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,98 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Net.Http; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using System.Threading; |
|||
|
|||
namespace Shentun.WebPeis.WxPayHelpers |
|||
{ |
|||
/// <summary>
|
|||
/// Http处理程序
|
|||
/// 此类为官方提供内容,此处不做任何修改
|
|||
/// 用于在请求微信接口时对请求构建签名信息,调用方式参照以下示例
|
|||
/// 使用方法:
|
|||
/// HttpClient client = new HttpClient(new HttpHandler("{商户号}", "{商户证书序列号}"));
|
|||
/// ...
|
|||
/// var response = client.GetAsync("https://api.mch.weixin.qq.com/v3/certificates");
|
|||
/// 官方文档参考:https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_0.shtml .NET示例代码
|
|||
/// </summary>
|
|||
public class HttpHandler : DelegatingHandler |
|||
{ |
|||
private readonly string merchantId; |
|||
private readonly string serialNo; |
|||
/// <summary>
|
|||
/// HttpHandler构造函数
|
|||
/// </summary>
|
|||
/// <param name="merchantId">商户号</param>
|
|||
/// <param name="merchantSerialNo">商户证书序列号</param>
|
|||
public HttpHandler(string merchantId, string merchantSerialNo) |
|||
{ |
|||
InnerHandler = new HttpClientHandler(); |
|||
|
|||
this.merchantId = merchantId; |
|||
this.serialNo = merchantSerialNo; |
|||
} |
|||
/// <summary>
|
|||
/// 发送请求方法
|
|||
/// </summary>
|
|||
/// <param name="request"></param>
|
|||
/// <param name="cancellationToken"></param>
|
|||
/// <returns></returns>
|
|||
protected async override Task<HttpResponseMessage> SendAsync( |
|||
HttpRequestMessage request, |
|||
CancellationToken cancellationToken) |
|||
{ |
|||
var auth = await BuildAuthAsync(request); |
|||
string value = $"WECHATPAY2-SHA256-RSA2048 {auth}"; |
|||
request.Headers.Add("Authorization", value); |
|||
|
|||
return await base.SendAsync(request, cancellationToken); |
|||
} |
|||
/// <summary>
|
|||
/// 创建签名方法
|
|||
/// </summary>
|
|||
/// <param name="request"></param>
|
|||
/// <returns></returns>
|
|||
protected async Task<string> BuildAuthAsync(HttpRequestMessage request) |
|||
{ |
|||
string method = request.Method.ToString(); |
|||
string body = ""; |
|||
if (method == "POST" || method == "PUT" || method == "PATCH") |
|||
{ |
|||
var content = request.Content; |
|||
body = await content.ReadAsStringAsync(); |
|||
} |
|||
|
|||
string uri = request.RequestUri.PathAndQuery; |
|||
var timestamp = DateTimeOffset.Now.ToUnixTimeSeconds(); |
|||
string nonce = Path.GetRandomFileName(); |
|||
|
|||
string message = $"{method}\n{uri}\n{timestamp}\n{nonce}\n{body}\n"; |
|||
string signature = Sign(message); |
|||
return $"mchid=\"{merchantId}\",nonce_str=\"{nonce}\",timestamp=\"{timestamp}\",serial_no=\"{serialNo}\",signature=\"{signature}\""; |
|||
} |
|||
/// <summary>
|
|||
/// 请求签名方法
|
|||
/// </summary>
|
|||
/// <param name="message"></param>
|
|||
/// <returns></returns>
|
|||
protected string Sign(string message) |
|||
{ |
|||
|
|||
////直接调用WXPayHelper中配置的商户私钥privateKey
|
|||
//string privateKey = WXPayHelper.privateKey;
|
|||
//byte[] keyData = Convert.FromBase64String(privateKey);
|
|||
|
|||
//var rsa = RSA.Create();
|
|||
////适用该方法的版本https://learn.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.asymmetricalgorithm.importpkcs8privatekey?view=net-7.0
|
|||
//rsa.ImportPkcs8PrivateKey(keyData, out _);
|
|||
//byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
|
|||
//return Convert.ToBase64String(rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
|
|||
|
|||
return ""; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,994 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Net.Http; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Shentun.WebPeis.WxPayHelpers |
|||
{ |
|||
// /// <summary>
|
|||
// /// 微信支付类
|
|||
// /// 微信支付版本:V3
|
|||
// /// 所有方法只使用了接口提供的部分参数,可更具业务场景需要修改接口参数
|
|||
// /// </summary>
|
|||
// public class WXPayHelper
|
|||
// {
|
|||
|
|||
// #region 公共参数
|
|||
// /// <summary>
|
|||
// /// 公众平台AppId
|
|||
// /// 这里填写你自己的公众平台AppId
|
|||
// /// </summary>
|
|||
// public static string appid = "自己的公众平台appid";
|
|||
// /// <summary>
|
|||
// /// 商户号
|
|||
// /// 这里填写你自己的商户号
|
|||
// /// </summary>
|
|||
// public static string mch_id = "1303919101";
|
|||
// /// <summary>
|
|||
// /// 特约商户微信支付API秘钥
|
|||
// /// 这里填写你自己的特约商户微信支付API秘钥
|
|||
// /// </summary>
|
|||
// public static string wxPayApiKey = "gfrdfhhjhjedt3457ywfdsf45665gert";
|
|||
// /// <summary>
|
|||
// /// 商户私钥
|
|||
// /// (微信支付文档->下载并配置商户证书时生成)
|
|||
// /// NOTE: 私钥不包括私钥文件起始的-----BEGIN PRIVATE KEY-----
|
|||
// /// 亦不包括结尾的-----END PRIVATE KEY-----
|
|||
// /// 这里填写你自己的商户私钥
|
|||
// /// </summary>
|
|||
// public static string privateKey = @"MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3xEIME1QnJQra
|
|||
//ZpNEDwCkK7TnGCW0mfhMMUbJDp/9eswa5+9pIqulcA/YRxjv+IMdYvk80yloSjOy
|
|||
//UVbBH6/TQyvgKXVRkqICovUPVkBAlC8QyQhC6ds8jWNRZ9iAsSoRe54isiEPrsV+
|
|||
//NU9pHsnjNYACSs9t4yJBraghQvd56MeNBSILwHll2w6L7/eWccB+L7g/xnI33KHT
|
|||
//rNXhkErhjSrEl1MGAIF1g2lpxzd4uUvNDc2JUagjpURp2t2X1XyfWYtndKd62pkg
|
|||
//tIJFZZJYgelyeeS+gBAeOatXI5zh+zvgcI1Ya+DzI92GLY2a5kjwP5RHH72lqV8O
|
|||
//UY8kpFlbAgMBAAECggEAXrvM9J6uPjPJYYeJmYdGZFunuY5oOa86IkUw4YspjSnV
|
|||
//uHUipYdbB0E62drlDyiEpwyTwfh1my7Ncbqex5ZHNNim8LtOoIu/+y34uTxUiTYb
|
|||
//AUMxgBVAkPmuXpPzN3ydXD/m6Kn9gzEs3IAs/NsDZp7467WXM2XpDgSw7Nyx6WTo
|
|||
//H3TRUWvyr5TMOEApDX8eINh6s/ewlr3BHLJSYMkjPGpzKWMqTLs9O88NL3NHQnv6
|
|||
//jOnF2EWtFVT81O7H+bViJUhW1y4iiHdet2L7Jk9p77DDjMJmz/WsCulxFN+Ahq6n
|
|||
//AZW5DBA4KLGCyKiz17t37Ky07YRByMi02/aiSlM/wQKBgQDl9pInNFv4hPxHIrJE
|
|||
//K3xQgSWaKAyuxDHnrMWg2ovbFl4XvRMDqLibcUQXBH01jIWwReiZOk9e6KRuZiBO
|
|||
//FEd7CD24PNdDctR3ddKAwT/gAigDk0pNAnvtjw029BobGmpJVDxMtChkGaQeAHh5
|
|||
//UXtYhMC6qMy+E5yDLy5rcIysYQKBgQDMkrD03l6KDO+xa9wiBOIePKd2086csMaD
|
|||
//quWblfHNyzdxYitkd9AEk1nAaiZ09qQvAZmd3EbT7vL33uQGQSTwqkC/jWpvdgJ0
|
|||
//gyRdNQ0D8b/PqKEoSMyZyqrKnU1ng+Bn2bjjimhjOUdoNw0OSEGL+zmciTJ9Q02M
|
|||
//maJgQwT/OwKBgDq30O3NwsYcPsZzJ42chOuRbmaEX2iolA2R4gyGgTt55KCvGJHQ
|
|||
//nQKj0z0FWms37FLsJs4pQ2b6hDHkRc9qAi56Fjha4KRKR9IQ9aUGsyahplHzY/9x
|
|||
//6O7pnfgwMBJHlmgO6C61ubKFkZBPknN3yMT7cLK4sz69hzM/8txgKqtBAoGAVkP1
|
|||
//gwzSaPyThwmoxl+wyndhVuZyVfjlfVhvgnB0iweK1bFEAxXTDlrkmhMpLGFlUr0l
|
|||
///j+JTo2Qv52qIkkOPr5Ml3oWy/HDj0ZN61AXsPYcoIDHlKk+PgwMgWxb267szl4t
|
|||
//bSZMZqscxYGRa9hka5cA8FWaiN/8r7GJm3YngUkCgYEAxvkA6NQW8VCCbb6FPO+g
|
|||
//0Qvlpih7RoHm42IBXQ83ZJEuwSdL09AClUR5ggvzwjQ5CfEqJS2qyEvvzat5WBXx
|
|||
//6nT/XTEUtoc81XsMLCavzn23g05pk10kOYlU7YFELIekJdIDWUSYKmdAfSQ2wmgZ
|
|||
//5GbnOxI81pOaqwbngc7zZJ0=";
|
|||
// /// <summary>
|
|||
// /// 商户证书序列号
|
|||
// /// (微信支付文档->下载并配置商户证书时生成)
|
|||
// /// 这里填写你自己的商户证书序列号
|
|||
// /// </summary>
|
|||
// public static string certificateKey = "790255968BA3791570CC54DD4F4BEB65B75D7A62";
|
|||
// /// <summary>
|
|||
// /// 回调地址
|
|||
// /// (微信支付后自动回调商户平台的外网地址,微信平台自动调用,用于处理支付后的工作)
|
|||
// /// 一般用于通过微信调用该接口地址传入的参数解析后获取支付结果,处理不同支付结果的业务逻辑
|
|||
// /// 需与微信商户号中支付目录地址配置一致
|
|||
// /// 回调地址随便外网能访问就行 /tPosition/WX_Callback
|
|||
// /// 注意!!!!!! 不以“/”结尾
|
|||
// /// </summary>
|
|||
// public static string notifyurl = "自己的回调地址";
|
|||
// /// <summary>
|
|||
// /// 统一退款接口
|
|||
// /// 微信支付平台提供的统一退款接口地址
|
|||
// /// </summary>
|
|||
// private readonly string OutUrl = "https://api.mch.weixin.qq.com/v3/refund/domestic/refunds";
|
|||
// #endregion
|
|||
|
|||
// #region 公共参数类
|
|||
// #region 下单基类
|
|||
// /// <summary>
|
|||
// /// 下单请求参数基类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml 请求参数
|
|||
// /// </summary>
|
|||
// private class PayOrderbodyModelBase
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 直连商户号
|
|||
// /// </summary>
|
|||
// public string mchid { get; set; }
|
|||
// /// <summary>
|
|||
// /// 应用ID
|
|||
// /// </summary>
|
|||
// public string appid { get; set; }
|
|||
// /// <summary>
|
|||
// /// 商品描述
|
|||
// /// </summary>
|
|||
// public string description { get; set; }
|
|||
|
|||
// /// <summary>
|
|||
// /// 商户订单号
|
|||
// /// </summary>
|
|||
// public string out_trade_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 通知地址
|
|||
// /// </summary>
|
|||
// public string notify_url { get; set; }
|
|||
// /// <summary>
|
|||
// /// 订单金额
|
|||
// /// </summary>
|
|||
// public object amount { get; set; }
|
|||
|
|||
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 下单返回结果基类
|
|||
// /// </summary>
|
|||
// private class ReturnParametersBase
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 返回结果【true/false】
|
|||
// /// </summary>
|
|||
// public bool result { get; set; }
|
|||
// /// <summary>
|
|||
// /// 错误描述
|
|||
// /// </summary>
|
|||
// public string errmsg { get; set; }
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 通用订单金额类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
|||
// /// 请求参数中 的 订单金额(amount)参数
|
|||
// /// </summary>
|
|||
// private class amount
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 金钱
|
|||
// /// </summary>
|
|||
// public int total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 货币类型
|
|||
// /// CNY:人民币,境内商户号仅支持人民币。
|
|||
// /// </summary>
|
|||
// public string currency { get; set; } = "CNY";
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 通用订单金额类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
|||
// /// 请求参数中 的 场景信息(scene_info)参数
|
|||
// /// </summary>
|
|||
// private class scene_info
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 用户终端IP
|
|||
// /// 用户的客户端IP,支持IPv4和IPv6两种格式的IP地址。
|
|||
// /// 示例值:14.23.150.211
|
|||
// /// </summary>
|
|||
// public string payer_client_ip { get; set; }
|
|||
// /// <summary>
|
|||
// /// H5场景信息
|
|||
// /// </summary>
|
|||
// public object h5_info { get; set; }
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 通用H5场景信息类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
|||
// /// 请求参数中 的 场景信息(scene_info)参数
|
|||
// /// </summary>
|
|||
// private class h5_info
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 场景类型
|
|||
// /// 示例值:iOS, Android, Wap
|
|||
// /// </summary>
|
|||
// public string type { get; set; }
|
|||
// }
|
|||
// #endregion
|
|||
// #region 支付通知结果
|
|||
// /// <summary>
|
|||
// /// 统一支付通知结果类
|
|||
// /// 详情参考:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml 通知参数
|
|||
// /// </summary>
|
|||
// public class PayResult
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 通知ID 通知的唯一ID 示例值:EV-2018022511223320873
|
|||
// /// </summary>
|
|||
// public string id { get; set; }
|
|||
// /// <summary>
|
|||
// /// 通知ID 通知的唯一ID 示例值:EV-2018022511223320873
|
|||
// /// </summary>
|
|||
// public string prepay_id { get; set; }
|
|||
// /// <summary>
|
|||
// /// 通知创建时间
|
|||
// /// 通知创建的时间,遵循rfc3339标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss.表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示北京时间2015年05月20日13点29分35秒。
|
|||
// /// 示例值:2015-05-20T13:29:35+08:00
|
|||
// /// </summary>
|
|||
// public string create_time { get; set; }
|
|||
// /// <summary>
|
|||
// /// 通知数据类型
|
|||
// /// </summary>
|
|||
// public string resource_type { get; set; }
|
|||
// /// <summary>
|
|||
// /// 通知类型
|
|||
// /// </summary>
|
|||
// public string event_type { get; set; }
|
|||
// /// <summary>
|
|||
// /// 回调摘要
|
|||
// /// </summary>
|
|||
// public string summary { get; set; }
|
|||
// /// <summary>
|
|||
// /// 返回成功的链接
|
|||
// /// </summary>
|
|||
// public Resource resource { get; set; }
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// 统一通知数据类
|
|||
// /// 详情参考:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
|
|||
// /// 通知参数 中 通知数据(resource)成员
|
|||
// /// </summary>
|
|||
// public class Resource
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 原始类型
|
|||
// /// </summary>
|
|||
// public string original_type { get; set; }
|
|||
// /// <summary>
|
|||
// /// 加密算法类型
|
|||
// /// </summary>
|
|||
// public string algorithm { get; set; }
|
|||
// /// <summary>
|
|||
// /// 数据密文
|
|||
// /// </summary>
|
|||
// public string ciphertext { get; set; }
|
|||
// /// <summary>
|
|||
// /// 附加数据
|
|||
// /// </summary>
|
|||
// public string associated_data { get; set; }
|
|||
// /// <summary>
|
|||
// /// 随机串
|
|||
// /// </summary>
|
|||
// public string nonce { get; set; }
|
|||
// }
|
|||
// #endregion
|
|||
// #region 订单/支付通知结果报文解析结果
|
|||
// /// <summary>
|
|||
// /// 统一通知数据解析结果类
|
|||
// /// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml 返回参数
|
|||
// /// </summary>
|
|||
// public class ResourceReslt
|
|||
// {
|
|||
// /*微信支付查询订单接口返回参数*/
|
|||
// /// <summary>
|
|||
// /// 商户订单号
|
|||
// /// </summary>
|
|||
// public string out_trade_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 微信支付订单号
|
|||
// /// </summary>
|
|||
// public string transaction_id { get; set; }
|
|||
// /// <summary>
|
|||
// /// 交易类型
|
|||
// /// </summary>
|
|||
// public string trade_type { get; set; }
|
|||
// /// <summary>
|
|||
// /// 交易状态
|
|||
// /// 交易状态,枚举值:
|
|||
// ///SUCCESS:支付成功
|
|||
// ///REFUND:转入退款
|
|||
// ///NOTPAY:未支付
|
|||
// ///CLOSED:已关闭
|
|||
// ///REVOKED:已撤销(付款码支付)
|
|||
// ///USERPAYING:用户支付中(付款码支付)
|
|||
// ///PAYERROR:支付失败(其他原因,如银行返回失败)
|
|||
// /// </summary>
|
|||
// public string trade_state { get; set; }
|
|||
// /// <summary>
|
|||
// /// 交易状态描述
|
|||
// /// </summary>
|
|||
// public string trade_state_desc { get; set; }
|
|||
// /// <summary>
|
|||
// /// 支付完成时间
|
|||
// /// </summary>
|
|||
// public string success_time { get; set; }
|
|||
// /// <summary>
|
|||
// /// 支付者
|
|||
// /// </summary>
|
|||
|
|||
// public payPerson payer { get; set; }
|
|||
|
|||
// /// <summary>
|
|||
// /// 订单金额
|
|||
// /// </summary>
|
|||
|
|||
// public ResourceReslt_amount amount { get; set; }
|
|||
// /*自定义扩展参数*/
|
|||
// /// <summary>
|
|||
// /// 返回结果标识(0失败,1成功)
|
|||
// /// </summary>
|
|||
// public int code { get; set; }
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// 统一通知数据解析结果金额类
|
|||
// /// 详情参考:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml
|
|||
// /// 支付成功通知参数 中 订单金额(amount) 成员
|
|||
// /// </summary>
|
|||
// public class ResourceReslt_amount
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 总金额 订单总金额,单位为分。
|
|||
// /// </summary>
|
|||
// public int total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 用户支付金额 用户支付金额,单位为分。
|
|||
// /// </summary>
|
|||
// public int payer_total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 货币类型
|
|||
// /// </summary>
|
|||
// public string currency { get; set; } = "CNY";
|
|||
// /// <summary>
|
|||
// /// 用户支付币种
|
|||
// /// </summary>
|
|||
// public string payer_currency { get; set; } = "CNY";
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// 通用支付者类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
|||
// /// 请求参数中 的 支付者(payer)参数
|
|||
// /// </summary>
|
|||
// public class payPerson
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 用户标识
|
|||
// /// </summary>
|
|||
// public string openid { get; set; }
|
|||
// }
|
|||
// #endregion
|
|||
// #region 退款
|
|||
// /// <summary>
|
|||
// /// 统一退款请求参数类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml 请求参数
|
|||
// /// </summary>
|
|||
// private class OutBodyModel
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 商户订单号 必填
|
|||
// /// </summary>
|
|||
// public string out_trade_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 商户退款单号 必填
|
|||
// /// </summary>
|
|||
// public string out_refund_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款原因 非必填
|
|||
// /// </summary>
|
|||
// public string reason { get; set; } = "退款";
|
|||
|
|||
|
|||
// //public string notify_url { get; set; } = "";
|
|||
// /// <summary>
|
|||
// /// 金额信息 必填
|
|||
// /// </summary>
|
|||
// public object amount { get; set; }
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 统一退款请求参数 金额信息类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
|
|||
// /// 请求参数中 的 金额信息(amount)参数
|
|||
// /// </summary>
|
|||
// private class Out_amount
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 退款金额 必填
|
|||
// /// 退款金额,单位为分,只能为整数,不能超过原订单支付金额。
|
|||
// /// </summary>
|
|||
// public int refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 原订单金额 必填
|
|||
// /// 原支付交易的订单总金额,单位为分,只能为整数。
|
|||
// /// </summary>
|
|||
// public int total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款币种 必填
|
|||
// /// 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
|
|||
// /// </summary>
|
|||
// public string currency { get; set; } = "CNY";
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 统一退款返回参数类
|
|||
// /// 请求统一申请退款接口返回参数类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml 返回参数
|
|||
// /// </summary>
|
|||
// public class Out_result
|
|||
// {
|
|||
// /*微信支付申请退款接口返回参数*/
|
|||
// /// <summary>
|
|||
// /// 微信支付退款单号 必填
|
|||
// /// </summary>
|
|||
// public string refund_id { get; set; }
|
|||
// /// <summary>
|
|||
// /// 商户退款单号 必填
|
|||
// /// </summary>
|
|||
// public string out_refund_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 微信支付订单号 必填
|
|||
// /// </summary>
|
|||
// public string transaction_id { get; set; }
|
|||
|
|||
// /// <summary>
|
|||
// /// 商户订单号 必填
|
|||
// /// </summary>
|
|||
// public string out_trade_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款渠道 必填
|
|||
// /// </summary>
|
|||
// public string channel { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款入账账户 必填
|
|||
// /// </summary>
|
|||
// public string user_received_account { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款成功时间 非必填
|
|||
// /// </summary>
|
|||
// public string success_time { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款创建时间 必填
|
|||
// /// </summary>
|
|||
// public string create_time { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款状态 必填
|
|||
// /// </summary>
|
|||
// public string status { get; set; }
|
|||
// /// <summary>
|
|||
// /// 资金账户 必填
|
|||
// /// </summary>
|
|||
// public string funds_account { get; set; }
|
|||
// /// <summary>
|
|||
// /// 金额信息 必填
|
|||
// /// </summary>
|
|||
// public Out_result_amount amount { get; set; }
|
|||
// /*自定义扩展参数*/
|
|||
// /// <summary>
|
|||
// /// 状态码:200成功,其他失败
|
|||
// /// </summary>
|
|||
// public int code { get; set; } = 400;
|
|||
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// 统一退款返回参数 金额信息类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
|
|||
// /// 返回参数中 的 金额信息(amount)参数
|
|||
// /// </summary>
|
|||
// public class Out_result_amount
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 退款金额 必填
|
|||
// /// 退款标价金额,单位为分,可以做部分退款
|
|||
// /// </summary>
|
|||
// public int refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 订单金额 必填
|
|||
// /// 订单总金额,单位为分
|
|||
// /// </summary>
|
|||
// public int total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 用户支付金额 必填
|
|||
// /// 现金支付金额,单位为分,只能为整数
|
|||
// /// </summary>
|
|||
// public int payer_refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 用户退款金额 必填
|
|||
// /// 退款给用户的金额,不包含所有优惠券金额
|
|||
// /// </summary>
|
|||
// public int payer_total { get; set; }
|
|||
|
|||
// /// <summary>
|
|||
// /// 应结退款金额 必填
|
|||
// /// 去掉非充值代金券退款金额后的退款金额,单位为分,退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
|
|||
// /// </summary>
|
|||
// public int settlement_refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 应结订单金额 必填
|
|||
// /// 应结订单金额=订单金额-免充值代金券金额,应结订单金额<=订单金额,单位为分
|
|||
// /// </summary>
|
|||
// public int settlement_total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 优惠退款金额 必填
|
|||
// /// 优惠退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金,说明详见代金券或立减优惠,单位为分
|
|||
// /// </summary>
|
|||
// public int discount_refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 手续费退款金额 非必填
|
|||
// /// 手续费退款金额,单位为分。
|
|||
// /// </summary>
|
|||
// public int refund_fee { get; set; }
|
|||
|
|||
// /// <summary>
|
|||
// /// 退款币种 必填
|
|||
// /// 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
|
|||
// /// </summary>
|
|||
// public string currency { get; set; } = "CNY";
|
|||
// }
|
|||
|
|||
// #endregion
|
|||
// #endregion
|
|||
|
|||
|
|||
// //#region 公共方法 (已测试上线)(适用于JSAPI、APP、H5、Native、小程序)
|
|||
// ///// <summary>
|
|||
// ///// 统一查询订单接口
|
|||
// ///// 微信支付平台提供的JSAPI统一查询订单接口地址:https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}
|
|||
// ///// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_2.shtml
|
|||
// ///// </summary>
|
|||
// ///// <param name="out_trade_no">商户平台订单编号 必填</param>
|
|||
// ///// 其他参数更具业务需要自行添加
|
|||
// ///// <returns></returns>
|
|||
// //public async Task<string> SearchOrder(string out_trade_no)
|
|||
// //{
|
|||
// // LogHelper.WriteWithTime("JSAPISearchOrder进入");
|
|||
// // LogHelper.WriteWithTime("mchid:" + mch_id + "out_trade_no" + out_trade_no);
|
|||
// // //签名后发起请求
|
|||
// // HttpClient client = new HttpClient(new HttpHandler(mch_id, certificateKey));
|
|||
// // //请求头部添加Accept参数,值为application/json,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|||
// // //请求头部添加User-Agent参数,值为Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
|
|||
// // //发起GET请求并等待结果返回,传入参数为商户平台订单编号和商户号
|
|||
// // var response = await client.GetAsync($@"https://api.mch.weixin.qq.com/v3/pay/transactions/out-trade-no/{out_trade_no}" + "?mchid=" + mch_id);
|
|||
// // LogHelper.WriteWithTime("response : " + JsonConvert.SerializeObject(response));
|
|||
// // //等待返回结果读取
|
|||
// // var respStr = await response.Content.ReadAsStringAsync();
|
|||
// // LogHelper.WriteWithTime("respStr : " + JsonConvert.SerializeObject(respStr));
|
|||
// // //创建通知数据解析结果类实例
|
|||
// // ResourceReslt jo = new ResourceReslt();
|
|||
// // if (response.IsSuccessStatusCode)
|
|||
// // {
|
|||
// // //如果IsSuccessStatusCode为成功,则返回订单查询结果
|
|||
// // jo = JsonConvert.DeserializeObject<ResourceReslt>(respStr);
|
|||
// // jo.code = 1;
|
|||
// // }
|
|||
// // else
|
|||
// // {
|
|||
// // //如果IsSuccessStatusCode为失败,则返回失败状态码
|
|||
// // jo.code = 0;
|
|||
// // }
|
|||
// // return JsonConvert.SerializeObject(jo);
|
|||
|
|||
// //}
|
|||
// ///// <summary>
|
|||
// ///// 统一退款接口
|
|||
// ///// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_9.shtml
|
|||
// ///// </summary>
|
|||
// ///// <param name="out_trade_no">商户订单号</param>
|
|||
// ///// <param name="out_refund_no">商户退款单号(商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。)</param>
|
|||
// ///// <param name="refund">退款金额(元)(退款金额,单位为分,只能为整数,不能超过原订单支付金额。)</param>
|
|||
// ///// <param name="total">订单金额(元)(原支付交易的订单总金额,单位为分,只能为整数。)</param>
|
|||
// ///// 其他参数更具业务需要自行添加
|
|||
// ///// <returns></returns>
|
|||
// //public async Task<string> Refunds(string out_trade_no, string out_refund_no, double refund, double total)
|
|||
// //{
|
|||
// // //创建jsapi返回结果类的实例 returnParameters
|
|||
// // Out_result returnParameters = new Out_result();
|
|||
// // //构建即将发起的POST请求的body参数
|
|||
// // var formData = new OutBodyModel
|
|||
// // {
|
|||
// // out_trade_no = out_trade_no,//商户订单号
|
|||
// // out_refund_no = out_refund_no,//商户退款单号
|
|||
// // amount = new Out_amount
|
|||
// // {
|
|||
// // total = Convert.ToInt32(total * 100),//订单金额
|
|||
// // refund = Convert.ToInt32(refund * 100),//退款金额
|
|||
// // }
|
|||
// // };
|
|||
// // LogHelper.WriteWithTime("OutBodyModel : " + JsonConvert.SerializeObject(formData));
|
|||
// // //使用示例:HttpClient client = new HttpClient(new HttpHandler("{商户号}", "{商户证书序列号}"));
|
|||
// // //HttpClient client = new HttpClient(new HttpHandler("1500536401", "340A5D32A5040892B41217F0730EDC5137A76405"));
|
|||
// // HttpClient client = new HttpClient(new HttpHandler(mch_id, certificateKey));
|
|||
// // //请求头部添加Accept参数,值为application/json,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|||
// // //请求头部添加User-Agent参数,值为Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
|
|||
// // var bodyJson = new StringContent(JsonConvert.SerializeObject(formData), Encoding.UTF8, "application/json");
|
|||
// // //发起请求并等待请求结果返回
|
|||
// // var response = await client.PostAsync(OutUrl, bodyJson);
|
|||
// // LogHelper.WriteWithTime("response : " + JsonConvert.SerializeObject(response));
|
|||
// // //等待返回结果
|
|||
// // var respStr = await response.Content.ReadAsStringAsync();
|
|||
// // LogHelper.WriteWithTime("respStr : " + JsonConvert.SerializeObject(respStr));
|
|||
|
|||
// // //JObject jo = (JObject)JsonConvert.DeserializeObject(respStr);
|
|||
// // if (response.IsSuccessStatusCode)
|
|||
// // {
|
|||
// // //如果请求成功将返回的JSON字符串转换为对象
|
|||
// // returnParameters = JsonConvert.DeserializeObject<Out_result>(respStr);
|
|||
// // returnParameters.code = 200;
|
|||
// // }//失败则返回初始化的returnParameters
|
|||
|
|||
// // //返回returnParameters
|
|||
// // return JsonConvert.SerializeObject(returnParameters);
|
|||
|
|||
// //}
|
|||
// ///// <summary>
|
|||
// ///// 统一查询单笔退款接口
|
|||
// ///// 微信支付平台提供的JSAPI统一查询订单接口地址:https://api.mch.weixin.qq.com/v3/refund/domestic/refunds/{out_refund_no}
|
|||
// ///// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_10.shtml
|
|||
// ///// </summary>
|
|||
// ///// <param name="out_refund_no">商户平台退款单号 必填</param>
|
|||
// ///// 其他参数更具业务需要自行添加
|
|||
// ///// <returns></returns>
|
|||
// //public async Task<string> SearchRefunds(string out_refund_no)
|
|||
// //{
|
|||
// // LogHelper.WriteWithTime("JSAPISearchOrder进入");
|
|||
// // LogHelper.WriteWithTime("mchid:" + mch_id + "out_trade_no" + out_refund_no);
|
|||
// // //签名后发起请求
|
|||
// // HttpClient client = new HttpClient(new HttpHandler(mch_id, certificateKey));
|
|||
// // //请求头部添加Accept参数,值为application/json,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|||
// // //请求头部添加User-Agent参数,值为Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36,固定参数,无需修改
|
|||
// // client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
|
|||
// // //发起GET请求并等待结果返回,传入参数为商户平台订单编号和商户号
|
|||
// // var response = await client.GetAsync($@"https://api.mch.weixin.qq.com/v3/refund/domestic/refunds/{out_refund_no}");
|
|||
// // LogHelper.WriteWithTime("response : " + JsonConvert.SerializeObject(response));
|
|||
// // //等待返回结果读取
|
|||
// // var respStr = await response.Content.ReadAsStringAsync();
|
|||
// // LogHelper.WriteWithTime("respStr : " + JsonConvert.SerializeObject(respStr));
|
|||
// // //创建通知数据解析结果类实例
|
|||
// // Out_result jo = new Out_result();
|
|||
// // if (response.IsSuccessStatusCode)
|
|||
// // {
|
|||
// // //如果IsSuccessStatusCode为成功,则返回订单查询结果
|
|||
// // jo = JsonConvert.DeserializeObject<Out_result>(respStr);
|
|||
// // jo.code = 1;
|
|||
// // }
|
|||
// // else
|
|||
// // {
|
|||
// // //如果IsSuccessStatusCode为失败,则返回失败状态码
|
|||
// // jo.code = 0;
|
|||
// // }
|
|||
// // return JsonConvert.SerializeObject(jo);
|
|||
|
|||
// //}
|
|||
// //#endregion
|
|||
|
|||
// #region JSAPI支付(已完成测试上线)
|
|||
// #region JSAPI参数
|
|||
// /// <summary>
|
|||
// /// 统一下单接口(JSAPI)
|
|||
// /// 微信支付平台提供的JSAPI统一下单接口地址
|
|||
// /// </summary>
|
|||
// private readonly string JSAPIurl = "https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi";
|
|||
// #endregion
|
|||
// #region JSAPI参数类
|
|||
// /// <summary>
|
|||
// /// 调起支付参数类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_4.shtml 接口定义
|
|||
// /// </summary>
|
|||
// private class JSAPICallUpPaymentParams
|
|||
// {
|
|||
// /*微信调起支付要求参数*/
|
|||
// /// <summary>
|
|||
// /// 公众号AppId
|
|||
// /// 商户申请的公众号对应的appid,由微信支付生成,可在公众号后台查看
|
|||
// /// </summary>
|
|||
// public string appid { get; set; }
|
|||
// /// <summary>
|
|||
// /// 时间戳
|
|||
// /// 时间戳,标准北京时间,时区为东八区,自1970年1月1日 0点0分0秒以来的秒数。注意:部分系统取到的值为毫秒级,需要转换成秒(10位数字)。
|
|||
// /// </summary>
|
|||
// public string timeStamp { get; set; }
|
|||
// /// <summary>
|
|||
// /// 随机字符串
|
|||
// /// 随机字符串,不长于32位。
|
|||
// /// </summary>
|
|||
// public string nonceStr { get; set; }
|
|||
// /// <summary>
|
|||
// /// 订单详情扩展字符串
|
|||
// /// JSAPI下单接口返回的prepay_id参数值,提交格式如:prepay_id=***
|
|||
// /// </summary>
|
|||
// public string package { get; set; }
|
|||
// /// <summary>
|
|||
// /// 签名方式
|
|||
// /// 签名类型,默认为RSA,仅支持RSA。
|
|||
// /// 示例值:RSA
|
|||
// /// </summary>
|
|||
// public string signType { get; set; }
|
|||
// /// <summary>
|
|||
// /// 签名
|
|||
// /// 使用字段appId、timeStamp、nonceStr、package计算得出的签名值
|
|||
// /// 签名生成调用Sign()方法
|
|||
// /// </summary>
|
|||
// public string paySign { get; set; }
|
|||
// /*自定义扩展参数*/
|
|||
// /// <summary>
|
|||
// /// 商户平台订单号
|
|||
// /// </summary>
|
|||
// public string orderCode { get; set; }
|
|||
// /// <summary>
|
|||
// /// 返回结果标识(0失败,1成功)
|
|||
// /// </summary>
|
|||
// public int code { get; set; }
|
|||
|
|||
// }
|
|||
|
|||
// /// <summary>
|
|||
// /// jsapi返回结果类
|
|||
// /// </summary>
|
|||
// private class JSAPIreturnParameters : ReturnParametersBase
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 预支付交易会话标识
|
|||
// /// 用于后续接口调用中使用,该值有效期为2小时
|
|||
// /// </summary>
|
|||
// public string prepay_id { get; set; }
|
|||
// }
|
|||
// #region 下单
|
|||
// /// <summary>
|
|||
// /// JSAPI下单请求参数类
|
|||
// /// 详情参见链接:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml 请求参数
|
|||
// /// </summary>
|
|||
// private class JSAPIbodyModel : PayOrderbodyModelBase
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 支付者信息
|
|||
// /// </summary>
|
|||
// public object payer { get; set; }
|
|||
// }
|
|||
|
|||
|
|||
// #endregion
|
|||
// #endregion
|
|||
// #region JSAPI方法
|
|||
|
|||
// /// <summary>
|
|||
// /// JSAPI调用的统一支付接口
|
|||
// /// 用户返回前端需要处理的数据内容
|
|||
// /// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_4.shtml
|
|||
// /// </summary>
|
|||
// /// <param name="description">商品描述 必填</param>
|
|||
// /// <param name="total">商品金额,以“元”为单位 必填</param>
|
|||
// /// <param name="openid">微信公众号用户openid 必填</param>
|
|||
// /// <param name="orderCode">商户平台订单编号 必填</param>
|
|||
// /// 其他参数更具业务需要自行添加
|
|||
// /// <returns></returns>
|
|||
// public async Task<object> JsApiPay(string description, decimal total, string openid, string orderCode)
|
|||
// {
|
|||
// LogHelper.WriteWithTime("JsApiPay 进入调起支付接口");
|
|||
// //获取prepay_id
|
|||
// string resultStr = await JSAPIGetprepay(description, total, orderCode, openid);
|
|||
|
|||
// JSAPIreturnParameters result = JsonConvert.DeserializeObject<JSAPIreturnParameters>(resultStr);
|
|||
// LogHelper.WriteWithTime("resultStr" + resultStr);
|
|||
// //订单详情扩展字符串
|
|||
// string prepay_id = "";
|
|||
// //时间戳
|
|||
// string timeStamp = "";
|
|||
// //随机字符串 不长于32位
|
|||
// string nonceStr = "";
|
|||
// //微信签名
|
|||
// string paySign = "";
|
|||
// //接口返回结果标识(0失败,1成功)
|
|||
// int code = 0;
|
|||
// if (result.result)
|
|||
// {//如果获取prepay_id成功 则执行以下代码
|
|||
// prepay_id = "prepay_id=" + result.prepay_id;
|
|||
// //获取时间戳
|
|||
// timeStamp = GetTimestamp10(DateTime.Now);
|
|||
// //生成随机字符串
|
|||
// nonceStr = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|||
// //生成签名字符串
|
|||
// paySign = Sign(appid + "\n" + timeStamp + "\n" + nonceStr + "\n" + prepay_id + "\n", privateKey);
|
|||
// //接口返回结果标识设置为成功
|
|||
// code = 1;
|
|||
// }
|
|||
// //返回的结果对象,结果对象内容按照微信支付提供的JSAPI调起支付参数进定义
|
|||
// JSAPICallUpPaymentParams returnObj = new JSAPICallUpPaymentParams()
|
|||
// {
|
|||
// appid = appid,
|
|||
// timeStamp = timeStamp,
|
|||
// nonceStr = nonceStr,
|
|||
// package = prepay_id,
|
|||
// signType = "RSA",
|
|||
// paySign = paySign,
|
|||
// orderCode = orderCode,
|
|||
// code = code
|
|||
// };
|
|||
|
|||
// return returnObj;
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// JSAPI下单接口
|
|||
// /// 成功返回prepay_id,失败返回https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi接口错误信息
|
|||
// /// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_1.shtml
|
|||
// /// </summary>
|
|||
// /// <param name="description">商品描述 必填</param>
|
|||
// /// <param name="total">金额,以“元”为单位 必填</param>
|
|||
// /// <param name="out_trade_no">商户平台订单号 必填</param>
|
|||
// /// <param name="openId">微信公众号openid 必填</param>
|
|||
// /// 其他参数更具业务需要自行添加
|
|||
// /// <returns></returns>
|
|||
// private async Task<string> JSAPIGetprepay(string description, decimal total, string out_trade_no, string openId)
|
|||
// {
|
|||
// //创建jsapi返回结果类的实例 returnParameters
|
|||
// JSAPIreturnParameters returnParameters = new JSAPIreturnParameters();
|
|||
// //构建即将发起的POST请求的body参数
|
|||
// var formData = new JSAPIbodyModel
|
|||
// {
|
|||
// appid = appid,//应用ID
|
|||
// mchid = mch_id,//商户号
|
|||
// description = description,//商品描述
|
|||
// out_trade_no = out_trade_no,//商户订单号
|
|||
// //attach = attach,//附加数据
|
|||
// notify_url = notifyurl,//通知地址
|
|||
// amount = new amount
|
|||
// {
|
|||
// total = Convert.ToInt32(total * 100),//金额
|
|||
// currency = "CNY"
|
|||
// },
|
|||
// payer = new payPerson()
|
|||
// {
|
|||
// openid = openId
|
|||
// }
|
|||
// };
|
|||
// //使用示例:HttpClient client = new HttpClient(new HttpHandler("{商户号}", "{商户证书序列号}"));
|
|||
// //HttpClient client = new HttpClient(new HttpHandler("1500536401", "340A5D32A5040892B41217F0730EDC5137A76405"));
|
|||
// HttpClient client = new HttpClient(new HttpHandler(mch_id, certificateKey));
|
|||
// //请求头部添加Accept参数,值为application/json,固定参数,无需修改
|
|||
// client.DefaultRequestHeaders.Add("Accept", "application/json");
|
|||
// //请求头部添加User-Agent参数,值为Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36,固定参数,无需修改
|
|||
// client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36");
|
|||
// var bodyJson = new StringContent(JsonConvert.SerializeObject(formData), Encoding.UTF8, "application/json");
|
|||
// //发起请求并等待请求结果返回
|
|||
// var response = await client.PostAsync(JSAPIurl, bodyJson);
|
|||
// LogHelper.WriteWithTime("response : " + JsonConvert.SerializeObject(response));
|
|||
// //等待返回结果
|
|||
// var respStr = await response.Content.ReadAsStringAsync();
|
|||
// LogHelper.WriteWithTime("respStr : " + JsonConvert.SerializeObject(respStr));
|
|||
// //将返回的JSON字符串转换为对象
|
|||
// JObject jo = (JObject)JsonConvert.DeserializeObject(respStr);
|
|||
// if (response.IsSuccessStatusCode)
|
|||
// {
|
|||
// //如果IsSuccessStatusCode为成功,获取请求结果中的prepay_id赋值到returnParameters.prepay_id
|
|||
// returnParameters.prepay_id = jo["prepay_id"].ToString();
|
|||
// returnParameters.result = true;
|
|||
// }
|
|||
// else
|
|||
// {
|
|||
// //如果IsSuccessStatusCode为失败,获取请求结果中的message赋值到returnParameters.errmsg
|
|||
// returnParameters.errmsg = jo["message"].ToString();
|
|||
// returnParameters.result = false;
|
|||
// }
|
|||
// //返回returnParameters
|
|||
// return JsonConvert.SerializeObject(returnParameters);
|
|||
|
|||
// }
|
|||
|
|||
// #endregion
|
|||
// #endregion
|
|||
|
|||
|
|||
// #region 通用方法
|
|||
// /// <summary>
|
|||
// /// 获取时间戳10位(秒)
|
|||
// /// </summary>
|
|||
// /// <param name="dateTime"></param>
|
|||
// /// <returns></returns>
|
|||
// public string GetTimestamp10(DateTime dateTime)
|
|||
// {
|
|||
// return ((dateTime.ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// 通用签名方法
|
|||
// /// </summary>
|
|||
// /// <param name="message">签名内容</param>
|
|||
// /// <param name="privateKey">商户私钥</param>
|
|||
// /// 调用示例:string paySign = Sign(appid + "\n" + timeStamp + "\n" + nonceStr + "\n" + prepay_id + "\n", privateKey);
|
|||
// /// <returns></returns>
|
|||
// public string Sign(string message, string privateKey)
|
|||
// {
|
|||
// byte[] keyData = Convert.FromBase64String(privateKey);
|
|||
// using CngKey cngKey = CngKey.Import(keyData, CngKeyBlobFormat.Pkcs8PrivateBlob);
|
|||
// using RSACng rsa = new RSACng(cngKey);
|
|||
// byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
|
|||
// return Convert.ToBase64String(rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1));
|
|||
// }
|
|||
// #endregion
|
|||
|
|||
// #region 解密类
|
|||
// /// <summary>
|
|||
// /// 解密类
|
|||
// /// 用于解密微信回调商户平台提供的回调接口时传输的加密报文
|
|||
// /// 详情参见:https://pay.weixin.qq.com/wiki/doc/apiv3/wechatpay/wechatpay4_2.shtml .NET示例代码
|
|||
// /// </summary>
|
|||
// public class AesGcm
|
|||
// {
|
|||
// private static string ALGORITHM = "AES/GCM/NoPadding";
|
|||
// private static int TAG_LENGTH_BIT = 128;
|
|||
// private static int NONCE_LENGTH_BYTE = 12;
|
|||
// private static string AES_KEY = wxPayApiKey;//APIv3密钥
|
|||
// /// <summary>
|
|||
// /// 报文解密方法
|
|||
// /// 参数内容参见:https://pay.weixin.qq.com/wiki/doc/apiv3/apis/chapter3_1_5.shtml 参数解密
|
|||
// /// </summary>
|
|||
// /// <param name="associatedData">附加数据</param>
|
|||
// /// <param name="nonce">随机串 加密使用的随机串</param>
|
|||
// /// <param name="ciphertext">数据密文 Base64编码后的开启/停用结果数据密文</param>
|
|||
// /// <returns></returns>
|
|||
// public static string AesGcmDecrypt(string associatedData, string nonce, string ciphertext)
|
|||
// {
|
|||
// GcmBlockCipher gcmBlockCipher = new GcmBlockCipher(new AesEngine());
|
|||
// AeadParameters aeadParameters = new AeadParameters(
|
|||
// new KeyParameter(Encoding.UTF8.GetBytes(AES_KEY)),
|
|||
// 128,
|
|||
// Encoding.UTF8.GetBytes(nonce),
|
|||
// Encoding.UTF8.GetBytes(associatedData));
|
|||
// gcmBlockCipher.Init(false, aeadParameters);
|
|||
|
|||
// byte[] data = Convert.FromBase64String(ciphertext);
|
|||
// byte[] plaintext = new byte[gcmBlockCipher.GetOutputSize(data.Length)];
|
|||
// int length = gcmBlockCipher.ProcessBytes(data, 0, data.Length, plaintext, 0);
|
|||
// gcmBlockCipher.DoFinal(plaintext, length);
|
|||
// return Encoding.UTF8.GetString(plaintext);
|
|||
// }
|
|||
|
|||
|
|||
// }
|
|||
// #endregion
|
|||
// }
|
|||
// /// <summary>
|
|||
// /// 微信支付 支付,退款接口参数
|
|||
// /// </summary>
|
|||
// public class WXApiParams
|
|||
// {
|
|||
// /// <summary>
|
|||
// /// 支付描述
|
|||
// /// </summary>
|
|||
// public string description { get; set; }
|
|||
// /// <summary>
|
|||
// /// 订单金额(元)
|
|||
// /// </summary>
|
|||
// public decimal total { get; set; }
|
|||
// /// <summary>
|
|||
// /// 平台订单号
|
|||
// /// </summary>
|
|||
// public string out_trade_no { get; set; }
|
|||
// /// <summary>
|
|||
// /// 微信公众平台OPENID
|
|||
// /// </summary>
|
|||
// public string openId { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款金额(元)
|
|||
// /// </summary>
|
|||
// public decimal refund { get; set; }
|
|||
// /// <summary>
|
|||
// /// 对应业务表主键
|
|||
// /// </summary>
|
|||
// public string F_BusinessId { get; set; }
|
|||
// /// <summary>
|
|||
// /// 创建人用户ID
|
|||
// /// </summary>
|
|||
// public string F_CreatorUserId { get; set; }
|
|||
// /// <summary>
|
|||
// /// 物业公司表主键ID
|
|||
// /// </summary>
|
|||
// public string F_PropertyId { get; set; }
|
|||
// /// <summary>
|
|||
// /// 订单类型 1为商超,2为餐饮,3物业费
|
|||
// /// </summary>
|
|||
// public int orderType { get; set; }
|
|||
// /// <summary>
|
|||
// /// 退款类型:1为商家退款,2为居民申请退款
|
|||
// /// </summary>
|
|||
// public int refundType { get; set; }
|
|||
// }
|
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
using Microsoft.AspNetCore.Authorization; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using NPOI.Util; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Net.Http; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace Shentun.WebPeis.WxPayHelpers |
|||
{ |
|||
/// <summary>
|
|||
/// 微信支付下单
|
|||
/// </summary>
|
|||
[ApiExplorerSettings(GroupName = "Work")] |
|||
[Authorize] |
|||
public class WeiXinPayAppService : ApplicationService |
|||
{ |
|||
|
|||
|
|||
public WeiXinPayAppService() |
|||
{ |
|||
} |
|||
|
|||
|
|||
|
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue