Score
0
Watch 60 Star 76 Fork 30

Kevin / OSS.PaySdkC#Apache-2.0

Join us
Explore and code with more than 2 million developers,Free private repositories !:)
Sign up
OSS开源支付SDK,主要打造微信支付,支付宝支付,以及其他银行支付接口标准库项目,同时支持.net framework和.net core spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

快速了解

OSS支付SDK,主要打造微信支付,支付宝支付,以及其他银行支付接口标准库项目
此项目以标准库的形式提供服务,也就是可以同时支持.Net Framework(4.6及以上版本) 和 .Net Core

如果有问题,也可以在公众号(osscoder)中提问:

osscoder

OSS.PayCenter 使用

一. 安装使用

   nuget下安装命令:Install-Package OSS.PaySdk.Wx (微信支付 nuget下安装命令:Install-Package OSS.PaySdk.Ali (支付宝支付

二. 调用示例

  1. 微信调用示例:
// 声明配置
private static WxPayCenterConfig config= new WxPayCenterConfig()
{
    AppSource = "11",
    AppId = "wx2428e34e0e7dc6ef",
    MchId = "1233410002",
    Key = "e10adc3849ba56abbe56e056f20f883e",
    AppSecret = "51c56b886b5be869567dd389b3e5d1d6",

    CertPassword = "1233410002",
    CertPath = "cert/apiclient_cert.p12",
    NotifyUrl = "http://www.osscoder.com",
    // 设置证书附加请求方式
    SetCertificata = (handler, cert) =>
    {
        handler.ServerCertificateCustomValidationCallback = (msg, c, chain, sslErrors) => true;
        handler.ClientCertificates.Add(cert);
    }
};
//  调用示例
private static WxPayTradeApi m_Api=new WxPayTradeApi(config);

public void AddUniOrderAsyncTest()
{
    var order = new WxAddPayUniOrderReq();

    order.device_info = "WEB";
    order.body = "测试商品支付";
    order.openid = "sdfvsfdbf345678888fhngfbsdfbsdfb";

    order.out_trade_no = "2017022423560123";
    order.trade_type = "JSAPI";
    order.total_fee = 100;

    var res = m_Api.AddUniOrderAsync(order).WaitResult();
    Assert.IsTrue(res.IsSuccess);
}
  1. 支付宝调用示例
 private static string privateKey = "自定义私钥";
 private static string publicKey = "支付宝提供的公钥";

protected static ZPayCenterConfig ZPayConfig { get; set; } = new ZPayCenterConfig()
{
    AppSource = "1",
    AppId = "2016080300153582",
    AppPrivateKey = privateKey,
    AppPublicKey = publicKey
};

protected static ZPayTradeApi zPayApi = new ZPayTradeApi(ZPayConfig);

public async Task<IActionResult> ZPay(PayOrderMo order)
{
    string orderNum = DateTime.Now.ToString("yyyyMMddHHmmss");

    var payReq = new ZAddPreTradeReq("http://pay.sample.osscoder.com/base/ZCallBack");

    payReq.body = order.order_name;
    payReq.out_trade_no = orderNum;
    payReq.total_amount = order.order_price;
    payReq.subject = order.order_name;

    var res =await zPayApi.AddPreTradeAsync(payReq);
    return Json(res);
}

三. 注意事项

因为底层接口使用了Task返回,在.Net Framework MVC项目中如果你的在action中通过 Result或者wait等方式,直接返回ActionResult对象,界面会出现假死状态,解决方案:
1. action 返回类型 ActionResult 修改为 async Task<ActionResult>, 全程异步
2. 将异步调用方法 通过 var task=  Task.Run(()=> 异步方法 )返回异步对象,再使用task.Result即可

Comments ( 8 )

Sign in for post a comment

C#
1
https://gitee.com/KevinW/OSS.PayCenter.git
git@gitee.com:KevinW/OSS.PayCenter.git
KevinW
OSS.PayCenter
OSS.PaySdk
master

Help Search