glhcp/server/vendor/alipaysdk/easysdk/csharp/README.md

249 lines
14 KiB
Java
Raw Normal View History

2023-08-10 06:59:52 +00:00
[![NuGet](https://badge.fury.io/nu/AlipayEasySDK.svg)](https://badge.fury.io/nu/AlipayEasySDK)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Falipay%2Falipay-easysdk?ref=badge_shield)
使 Alipay **Easy** SDK for .NET
Alipay Esay SDK for .NET访SDKHTTP
Alipay Easy SDK for .NET 使
##
[Alipay SDK](https://github.com/alipay/alipay-sdk-net-all)通用而全面的设计理念Alipay Easy SDK对开放能力的API进行了更加贴近高频场景的精心设计与裁剪简化了服务端调用方式让调用API像使用语言内置的函数一样简便。
APIAlipay Easy SDKAPI使
Alipay Easy SDK[](https://opendocs.alipay.com/mini/00am3f)相对应的代码组织结构让开发者可以快速找到不同能力对应的API。
Alipay Easy SDK****
##
1. Alipay Easy SDK for .NET`.Net Standard 2.0``.Net Framework 4.6.1`.`Net Core 2.0`
2. 使 Alipay Easy SDK for .NET [-](https://openhome.alipay.com/platform/developerIndex.htm)完成开发者接入的一些准备工作,包括创建应用、为应用添加功能包、设置应用的接口加签方式等。
3. 使SDK
*
`AppId`````````
*
`AppId`````
##
### [NuGet](https://www.nuget.org/packages/AlipayEasySDK/)程序包管理器在线安装依赖(推荐)
* `` ` NuGet ` `NuGet ` `` `AlipayEasySDK` `Authors` `antopen` ****NuGet ****
* .NET CLI
> dotnet add package AlipayEasySDK
### 线NuGet
1. 使`Visual Studio``README.md``AlipayEasySDK.sln`````
2. `AlipayEasySDK/bin/Debug``AlipayEasySDK/bin/Release``AlipayEasySDK.[version].nupkg`SDKNuGet线
3. [NuGet线使](https://yq.aliyun.com/articles/689227),在您的.NET应用项目工程中引入本SDK的NuGet离线包即可完成SDK的依赖安装。
##
###
使Alipay Easy SDK for .NETAPI3
1.
2. API
3.
```charp
using System;
using Alipay.EasySDK.Factory;
using Alipay.EasySDK.Kernel;
using Alipay.EasySDK.Kernel.Util;
using Alipay.EasySDK.Payment.FaceToFace.Models;
namespace SDKDemo
{
class Program
{
static void Main(string[] args)
{
// 1. 设置参数(全局只需设置一次)
Factory.SetOptions(GetConfig());
try
{
// 2. 发起API调用以创建当面付收款二维码为例
AlipayTradePrecreateResponse response = Factory.Payment.FaceToFace()
.PreCreate("Apple iPhone11 128G", "2234567234890", "5799.00");
// 3. 处理响应或异常
if (ResponseChecker.Success(response))
{
Console.WriteLine("调用成功");
}
else
{
Console.WriteLine("调用失败,原因:" + response.Msg + "" + response.SubMsg);
}
}
catch (Exception ex)
{
Console.WriteLine("调用遭遇异常,原因:" + ex.Message);
throw ex;
}
}
static private Config GetConfig()
{
return new Config()
{
Protocol = "https",
GatewayHost = "openapi.alipay.com",
SignType = "RSA2",
AppId = "<-- 请填写您的AppId例如2019091767145019 -->",
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
MerchantPrivateKey = "<-- 请填写您的应用私钥例如MIIEvQIBADANB ... ... -->",
MerchantCertPath = "<-- 请填写您的应用公钥证书文件路径,例如:/foo/appCertPublicKey_2019051064521003.crt -->",
AlipayCertPath = "<-- 请填写您的支付宝公钥证书文件路径,例如:/foo/alipayCertPublicKey_RSA2.crt -->",
AlipayRootCertPath = "<-- 请填写您的支付宝根证书文件路径,例如:/foo/alipayRootCert.crt -->",
// 如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
// AlipayPublicKey = "<-- 请填写您的支付宝公钥例如MIIBIjANBg... -->"
//可设置异步通知接收服务地址(可选)
NotifyUrl = "<-- 请填写您的支付类接口异步通知接收服务地址例如https://www.test.com/callback -->",
//可设置AES密钥调用AES加解密相关接口时需要可选
EncryptKey = "<-- 请填写您的AES密钥例如aa4BtZ4tspm2wnXLb1ThQA== -->"
};
}
}
}
```
###
#### ISV
```csharp
Factory.Payment.FaceToFace()
//调用Agent扩展方法设置app_auth_token完成ISV代调用
.Agent("ca34ea491e7146cc87d25fca24c4cD11")
.PreCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```csharp
Factory.Payment.FaceToFace()
// 调用AsyncNotify扩展方法可以为每此API调用设置独立的异步通知地址
// 此处设置的异步通知地址的优先级高于全局Config中配置的异步通知地址
.AsyncNotify("https://www.test.com/callback")
.PreCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```csharp
List<object> goodsDetailList = new List<object>();
Dictionary<string, object> goodsDetail = new Dictionary<string, object>
{
{ "goods_id", "apple-01" },
{ "goods_name", "Apple iPhone11 128G" },
{ "quantity", 1 },
{ "price", "5799.00" }
};
goodsDetailList.Add(goodsDetail);
Factory.Payment.FaceToFace()
// 调用Optional扩展方法完成可选业务参数biz_content下的可选字段的设置
.Optional("seller_id", "2088102146225135")
.Optional("discountable_amount", "8.88")
.Optional("goods_detail", goodsDetailList)
.PreCreate("Apple iPhone11 128G", "2234567890", "5799.00");
Dictionary<string, object> optionalArgs = new Dictionary<string, object>
{
{ "seller_id", "2088102146225135" },
{ "discountable_amount", "8.88" },
{ "goods_detail", goodsDetailList }
};
Factory.Payment.FaceToFace()
// 也可以调用BatchOptional扩展方法批量设置可选业务参数biz_content下的可选字段
.BatchOptional(optionalArgs)
.PreCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
####
```csharp
// 多种扩展方式可灵活组装(对扩展方法的调用顺序没有要求)
Factory.Payment.FaceToFace()
.Agent("ca34ea491e7146cc87d25fca24c4cD11")
.AsyncNotify("https://www.test.com/callback")
.Optional("seller_id", "2088102146225135")
.PreCreate("Apple iPhone11 128G", "2234567890", "5799.00");
```
## API
Alipay Easy SDKAPI
> Factory..().( ... )
使[](https://opendocs.alipay.com/mini/00am3f)中`营销能力`下的`模板消息`场景中的`小程序发送模板消息`,只需按如下形式编写调用代码即可(不同编程语言的连接符号可能不同)。
`Factory.Marketing.TemplateMessage().send( ... )`
OpenAPIOpenAPIOpenAPI使
Alipay Easy SDKAPI
## API
| | | | OpenAPI |
|-----------|-----------------|------------------------|-----------------------------------------------------------|
| Base | OAuth | getToken | alipay\.system\.oauth\.token |
| Base | OAuth | refreshToken | alipay\.system\.oauth\.token |
| Base | Qrcode | create | alipay\.open\.app\.qrcode\.create |
| Base | Image | upload | alipay\.offline\.material\.image\.upload |
| Base | Video | upload | alipay\.offline\.material\.image\.upload |
| Member | Identification | init | alipay\.user\.certify\.open\.initialize |
| Member | Identification | certify | alipay\.user\.certify\.open\.certify |
| Member | Identification | query | alipay\.user\.certify\.open\.query |
| Payment | Common | create | alipay\.trade\.create |
| Payment | Common | query | alipay\.trade\.query |
| Payment | Common | refund | alipay\.trade\.refund |
| Payment | Common | close | alipay\.trade\.close |
| Payment | Common | cancel | alipay\.trade\.cancel |
| Payment | Common | queryRefund | alipay\.trade\.fastpay\.refund\.query |
| Payment | Common | downloadBill | alipay\.data\.dataservice\.bill\.downloadurl\.query |
| Payment | Common | verifyNotify | - |
| Payment | Huabei | create | alipay\.trade\.create |
| Payment | FaceToFace | pay | alipay\.trade\.pay |
| Payment | FaceToFace | precreate | alipay\.trade\.precreate |
| Payment | App | pay | alipay\.trade\.app\.pay |
| Payment | Page | pay | alipay\.trade\.page\.pay |
| Payment | Wap | pay | alipay\.trade\.wap\.pay |
| Security | TextRisk | detect | alipay\.security\.risk\.content\.detect |
| Marketing | Pass | createTemplate | alipay\.pass\.template\.add |
| Marketing | Pass | updateTemplate | alipay\.pass\.template\.update |
| Marketing | Pass | addInstance | alipay\.pass\.instance\.add |
| Marketing | Pass | updateInstance | alipay\.pass\.instance\.update |
| Marketing | TemplateMessage | send | alipay\.open\.app\.mini\.templatemessage\.send |
| Marketing | OpenLife | createImageTextContent | alipay\.open\.public\.message\.content\.create |
| Marketing | OpenLife | modifyImageTextContent | alipay\.open\.public\.message\.content\.modify |
| Marketing | OpenLife | sendText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendImageText | alipay\.open\.public\.message\.total\.send |
| Marketing | OpenLife | sendSingleMessage | alipay\.open\.public\.message\.single\.send |
| Marketing | OpenLife | recallMessage | alipay\.open\.public\.life\.msg\.recall |
| Marketing | OpenLife | setIndustry | alipay\.open\.public\.template\.message\.industry\.modify |
| Marketing | OpenLife | getIndustry | alipay\.open\.public\.setting\.category\.query |
| Util | AES | decrypt | - |
| Util | AES | encrypt | - |
| Util | Generic | execute | - |
> API
##
[API Doc](./../APIDoc.md)
[Alipay Easy SDK](./../README.md)