Skip to content

Commit ad22417

Browse files
committed
update 20251113
1 parent 1c82bd1 commit ad22417

File tree

5 files changed

+129
-31
lines changed

5 files changed

+129
-31
lines changed
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
namespace com.alipay.ams.api.entities
22
{
3-
public enum PaymentMethodCategoryType
3+
4+
public enum PaymentMethodCategoryType
45
{
5-
ALIPAY_PLUS, WALLET, MOBILE_BANKING_APP, BANK_TRANSFER, ONLINE_BANKING, CARD, OTC,VA
6+
ALIPAY_PLUS,
7+
WALLET,
8+
MOBILE_BANKING_APP,
9+
BANK_TRANSFER,
10+
ONLINE_BANKING,
11+
CARD,
12+
OTC,
13+
MPESA,VIETTELMONEY,CREDIT_PAY,CHECKOUT,DIGITAL_WALLET
614
}
7-
}
15+
}

ams-dotnet/src/com/alipay/ams/api/request/AMSRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public virtual String BuildBody()
1818
return JsonSerializer.Serialize(this, this.GetType(), JsonSerializerOptionsFactory.WriteNotIndented);
1919
}
2020

21-
public abstract void validate();
21+
public virtual void validate(){}
2222

2323
public Dictionary<string, string> BuildRequestHeader(string clientId, string agentToken, string privateKey)
2424
{

ams-dotnet/src/com/alipay/ams/util/JsonSerializerOptionsFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Text.Json;
22
using System.Text.Json.Serialization;
3+
using com.alipay.ams.api.entities;
34

45
namespace com.alipay.ams.util
56
{
@@ -16,8 +17,9 @@ public class JsonSerializerOptionsFactory
1617
public static JsonSerializerOptions WriteNotIndented = new JsonSerializerOptions
1718
{
1819
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
19-
IgnoreNullValues = true,
20-
WriteIndented = false
20+
IgnoreNullValues = false,
21+
WriteIndented = false,
22+
Converters = { new SafeEnumConverterFactory() }
2123
};
2224

2325
static JsonSerializerOptionsFactory()
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
namespace com.alipay.ams.util;
2+
3+
using System;
4+
using System.Text.Json;
5+
using System.Text.Json.Serialization;
6+
7+
public class SafeEnumConverterFactory : JsonConverterFactory
8+
{
9+
public override bool CanConvert(Type typeToConvert)
10+
{
11+
var type = Nullable.GetUnderlyingType(typeToConvert) ?? typeToConvert;
12+
return type.IsEnum;
13+
}
14+
15+
public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
16+
{
17+
var underlyingType = Nullable.GetUnderlyingType(typeToConvert);
18+
var converterType = underlyingType == null
19+
? typeof(SafeEnumConverterInner<>).MakeGenericType(typeToConvert)
20+
: typeof(SafeNullableEnumConverterInner<>).MakeGenericType(underlyingType);
21+
22+
return (JsonConverter)Activator.CreateInstance(converterType)!;
23+
}
24+
25+
private class SafeEnumConverterInner<T> : JsonConverter<T> where T : struct, Enum
26+
{
27+
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
28+
{
29+
try
30+
{
31+
if (reader.TokenType == JsonTokenType.String)
32+
{
33+
var value = reader.GetString();
34+
if (Enum.TryParse<T>(value, true, out var result))
35+
return result;
36+
}
37+
else if (reader.TokenType == JsonTokenType.Number)
38+
{
39+
int intValue = reader.GetInt32();
40+
if (Enum.IsDefined(typeof(T), intValue))
41+
return (T)Enum.ToObject(typeof(T), intValue);
42+
}
43+
}
44+
catch { }
45+
46+
return default; // 非可空枚举 → 返回默认值
47+
}
48+
49+
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
50+
{
51+
writer.WriteStringValue(value.ToString());
52+
}
53+
}
54+
55+
private class SafeNullableEnumConverterInner<T> : JsonConverter<T?> where T : struct, Enum
56+
{
57+
public override T? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
58+
{
59+
try
60+
{
61+
if (reader.TokenType == JsonTokenType.String)
62+
{
63+
var value = reader.GetString();
64+
if (Enum.TryParse<T>(value, true, out var result))
65+
return result;
66+
}
67+
else if (reader.TokenType == JsonTokenType.Number)
68+
{
69+
int intValue = reader.GetInt32();
70+
if (Enum.IsDefined(typeof(T), intValue))
71+
return (T)Enum.ToObject(typeof(T), intValue);
72+
}
73+
}
74+
catch { }
75+
76+
return null; // 可空枚举 → 返回 null
77+
}
78+
79+
public override void Write(Utf8JsonWriter writer, T? value, JsonSerializerOptions options)
80+
{
81+
if (value.HasValue)
82+
writer.WriteStringValue(value.Value.ToString());
83+
else
84+
writer.WriteNullValue();
85+
}
86+
}
87+
}

ams-dotnet/src/example/Program.cs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,41 +8,42 @@ namespace ams_dotnet
88
class Program
99
{
1010

11-
private const string GatewayUrl = "";
12-
private const string ClientId = "";
11+
private const string GatewayUrl = "https://open-sea.alipay.com";
12+
private const string ClientId = "SANDBOX_5YC31G2ZNMQK07357";
13+
private const string MerchantPrivateKey =
14+
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDhnOLYh3Tte5ELNzD6kr6TSN+F4oXaNlnKgx2aGf/xSSHIh1k+wihv6HbwPAexdtjpDQAgwEv4YXpdH3erQLuy3oBIBVsdbXWg09TRttyBeM8FzbMru6qR1TceypEPhR9W4/hP9DZEmn9XZmR7xR9KStDKJdnqSNr578IVFvp3hXUt2HfwoHbUwwOPbu8a66th9b1PyNJ5DOdSoTj52tvFMOyfCmKOn9U/bwtcT/EGEJFlIj1QjBSwlEeCBDUVwwKlo2ttMP5Omy7i4Lxi5NKAMdw+Cru49FqGEf9B/JKfovd6EcwrnUeDfXVltNrPJjdr19WzatDh0k0wE/9QT6EnAgMBAAECggEAZsbQdDFo69KRpZlT36I/3NqisNwbe+esidum/Y+Aj8tv72jxF+zc/PXaUOAX5RkuASSh/Ul8kj7dvlRacJJBr1868xQ1iLdXkZdOaOazluuQ66TkTTTlpB+MR6Oh538OYsf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";
15+
private const string AlipayPublicKey =
16+
"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq7zEydi4Q2VvUIb1Mjpm/I2R3NVWcSMddlhvHYJADZ07YOGjvlQPbH3iixhLMnk1Y0tT7Sw7B1Ov1kXDGUhnui/YmGQBDbz9vg4iPDXA8OU7TaSsIk2BbP4+uZoortx2AZu/ABTGBDvyhLyJBkNplJ7196Np+IMaxi2RlT2NEAV4vFIurUcfFl5vvMliyV1SacvIyONkurzixSLirlKBl35t1mGm44xqh7M40tcMScgdF8pIdkzVz0nAnBcGb0aTeD3YLQmYFFmbQhWIe7MAa0BPEK7sxTJ1x1PbRUCHEXiZURnPjZTD7FBsTfLlcGOlOe0DXB7mrWm+AP+fVBjbAwIDAQAB";
1317

14-
// Below are fake keys that are for demo purpose. Replace them with your own ones.
15-
private const string MerchantPrivateKey = "";
16-
private const string AlipayPublicKey = "";
1718

1819

1920
static void Main(string[] args)
2021
{
2122
PayDemo.alipay(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
22-
//PayDemo.query(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"PR20190000000001_1725381379719.623");
23-
// PayDemo.cancel(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"PR20190000000001_1725381024794.669");
24-
//PayDemo.refund(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"202409031940108001001889B0209199607");
25-
//PayDemo.queryRefund(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"erf_PR20190000000001_5751725381493062.314");
26-
//PayDemo.consult(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
27-
//PayDemo.createSession(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
23+
PayDemo.query(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"PR20190000000001_1725381379719.623");
24+
PayDemo.cancel(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"PR20190000000001_1725381024794.669");
25+
PayDemo.refund(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"202409031940108001001889B0209199607");
26+
PayDemo.queryRefund(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey),"erf_PR20190000000001_5751725381493062.314");
27+
PayDemo.consult(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
28+
PayDemo.createSession(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
2829

2930
var defaultAlipayClient = new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey);
30-
//AuthDemo.authConsult(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
31-
//AuthDemo.applyTokenConsult(defaultAlipayClient,"281001139639787089651362");
32-
//AuthDemo.revokeToken(defaultAlipayClient,"28288803001291161724296551000BgIrDiWzU0171000529");
31+
AuthDemo.authConsult(new DefaultAlipayClient(GatewayUrl, ClientId, MerchantPrivateKey, AlipayPublicKey));
32+
AuthDemo.applyTokenConsult(defaultAlipayClient,"281001139639787089651362");
33+
AuthDemo.revokeToken(defaultAlipayClient,"28288803001291161724296551000BgIrDiWzU0171000529");
3334

34-
//CustomsDemo.declare(defaultAlipayClient,"202408221940108001001887E0207467163");
35-
//List<string> ids = new List<string>() {"12343543543"};
36-
//CustomsDemo.inquiryDeclaration(defaultAlipayClient,ids);
35+
CustomsDemo.declare(defaultAlipayClient,"202408221940108001001887E0207467163");
36+
List<string> ids = new List<string>() {"12343543543"};
37+
CustomsDemo.inquiryDeclaration(defaultAlipayClient,ids);
3738

38-
// MarketplaceDemo.register(defaultAlipayClient);
39-
//MarketplaceDemo.update(defaultAlipayClient,"mid_zhangtianren_ztr_20230807_180716_981");
40-
// MarketplaceDemo.queryBalance(defaultAlipayClient,"mid_zhangtianren_ztr_20230807_180716_981");
41-
//SubscriptionDemo.SubscriptionsCreate(defaultAlipayClient);
42-
//SubscriptionDemo.SubscriptionsChange(defaultAlipayClient,"202410221900000000000001J0000010626");
43-
//SubscriptionDemo.subscriptionCancel(defaultAlipayClient,"202410221900000000000001J0000010626");
44-
//VaultingDemo.createVaultingSession(defaultAlipayClient);
45-
//VaultingDemo.inquireVaulting(defaultAlipayClient,"vaultingRequestId26bc8b51-1617-455f-ab32-9572da9cb99d");
39+
MarketplaceDemo.register(defaultAlipayClient);
40+
MarketplaceDemo.update(defaultAlipayClient,"mid_zhangtianren_ztr_20230807_180716_981");
41+
MarketplaceDemo.queryBalance(defaultAlipayClient,"mid_zhangtianren_ztr_20230807_180716_981");
42+
SubscriptionDemo.SubscriptionsCreate(defaultAlipayClient);
43+
SubscriptionDemo.SubscriptionsChange(defaultAlipayClient,"202410221900000000000001J0000010626");
44+
SubscriptionDemo.subscriptionCancel(defaultAlipayClient,"202410221900000000000001J0000010626");
45+
VaultingDemo.createVaultingSession(defaultAlipayClient);
46+
VaultingDemo.inquireVaulting(defaultAlipayClient,"vaultingRequestId26bc8b51-1617-455f-ab32-9572da9cb99d");
4647
}
4748

4849
}

0 commit comments

Comments
 (0)