Skip to content

Commit

Permalink
Merge pull request dotnetcore#24 from dotnetcore/dev
Browse files Browse the repository at this point in the history
[Release] 2.4.0
  • Loading branch information
stulzq authored Dec 19, 2018
2 parents 386db7e + 19b9cb9 commit fb771c1
Show file tree
Hide file tree
Showing 13 changed files with 576 additions and 339 deletions.
6 changes: 3 additions & 3 deletions Alipay.AopSdk.AspnetCore/Alipay.AopSdk.AspnetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.3.1</Version>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<Version>2.4.0</Version>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<FileVersion>2.4.0.0</FileVersion>
<Copyright>Copyright 2017-2018 stulzq</Copyright>
<Authors>stulzq</Authors>
<Company>stulzq</Company>
Expand Down
35 changes: 28 additions & 7 deletions Alipay.AopSdk.AspnetCore/AlipayF2FService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Alipay.AopSdk.F2FPay.Business;
using System.Threading.Tasks;
using Alipay.AopSdk.F2FPay.Business;
using Alipay.AopSdk.F2FPay.Domain;
using Microsoft.Extensions.Options;

Expand All @@ -18,27 +19,47 @@ public AlipayF2FService(IOptions<AlipayOptions> alipayOptions)

public AlipayF2FPayResult TradePay(AlipayTradePayContentBuilder builder)
{
return _alipayClient.tradePay(builder);
return _alipayClient.TradePay(builder);
}

public AlipayF2FQueryResult TradeQuery(string outTradeNo)
{
return _alipayClient.tradeQuery(outTradeNo);
return _alipayClient.TradeQuery(outTradeNo);
}

public async Task<AlipayF2FQueryResult> TradeQueryAsync(string outTradeNo)
{
return await _alipayClient.TradeQueryAsync(outTradeNo);
}

public AlipayF2FRefundResult TradeRefund(AlipayTradeRefundContentBuilder builder)
{
return _alipayClient.tradeRefund(builder);
return _alipayClient.TradeRefund(builder);
}

public async Task<AlipayF2FRefundResult> TradeRefundAsync(AlipayTradeRefundContentBuilder builder)
{
return await _alipayClient.TradeRefundAsync(builder);
}

public AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder)
{
return _alipayClient.tradePrecreate(builder);
return _alipayClient.TradePrecreate(builder);
}

public async Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder)
{
return await _alipayClient.TradePrecreateAsync(builder);
}

public AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder, string notifyUrl)
{
return _alipayClient.TradePrecreate(builder, notifyUrl);
}

public AlipayF2FPrecreateResult TradePrecreate(AlipayTradePrecreateContentBuilder builder, string notify_url)
public async Task<AlipayF2FPrecreateResult> TradePrecreateAsync(AlipayTradePrecreateContentBuilder builder, string notifyUrl)
{
return _alipayClient.tradePrecreate(builder, notify_url);
return await _alipayClient.TradePrecreateAsync(builder, notifyUrl);
}
}
}
44 changes: 32 additions & 12 deletions Alipay.AopSdk.AspnetCore/AlipayService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Collections.Generic;
using System.Threading.Tasks;
using Alipay.AopSdk.Core;
using Alipay.AopSdk.Core.Util;
using Alipay.AopSdk.F2FPay.Business;
using Alipay.AopSdk.F2FPay.Domain;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

namespace Alipay.AopSdk.AspnetCore
Expand Down Expand Up @@ -37,17 +32,42 @@ public T Execute<T>(IAopRequest<T> request, string session, string appAuthToken)
return _aopClient.Execute(request, session,appAuthToken);
}

public T pageExecute<T>(IAopRequest<T> request) where T : AopResponse
public async Task<T> ExecuteAsync<T>(IAopRequest<T> request) where T : AopResponse
{
return await _aopClient.ExecuteAsync(request);
}

public async Task<T> ExecuteAsync<T>(IAopRequest<T> request, string session) where T : AopResponse
{
return await _aopClient.ExecuteAsync(request, session);
}

public async Task<T> ExecuteAsync<T>(IAopRequest<T> request, string session, string appAuthToken) where T : AopResponse
{
return await _aopClient.ExecuteAsync(request, session, appAuthToken);
}

public T PageExecute<T>(IAopRequest<T> request) where T : AopResponse
{
return _aopClient.pageExecute(request);
return _aopClient.PageExecute(request);
}

public T pageExecute<T>(IAopRequest<T> request, string session, string reqMethod) where T : AopResponse
public T PageExecute<T>(IAopRequest<T> request, string session, string reqMethod) where T : AopResponse
{
return _aopClient.pageExecute(request,session,reqMethod);
return _aopClient.PageExecute(request,session,reqMethod);
}

public T SdkExecute<T>(IAopRequest<T> request) where T : AopResponse
public async Task<T> PageExecuteAsync<T>(IAopRequest<T> request) where T : AopResponse
{
return await _aopClient.PageExecuteAsync(request);
}

public async Task<T> PageExecuteAsync<T>(IAopRequest<T> request, string session, string reqMethod) where T : AopResponse
{
return await _aopClient.PageExecuteAsync(request, session, reqMethod);
}

public T SdkExecute<T>(IAopRequest<T> request) where T : AopResponse
{
return _aopClient.SdkExecute(request);
}
Expand Down
8 changes: 4 additions & 4 deletions Alipay.AopSdk.AspnetCore/AlipayServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public static IServiceCollection AddAlipay(this IServiceCollection services,Acti
throw new ArgumentNullException(nameof(options));
services.AddOptions();
services.Configure(options);
services.AddScoped<AlipayService>();
services.AddScoped<AlipayF2FService>();
services.AddSingleton<AlipayService>();
services.AddSingleton<AlipayF2FService>();
return services;
}

Expand All @@ -31,8 +31,8 @@ public static IServiceCollection AddAlipay(this IServiceCollection services, ICo
throw new ArgumentNullException(nameof(section));
services.AddOptions();
services.Configure<AlipayOptions>(section);
services.AddScoped<AlipayService>();
services.AddScoped<AlipayF2FService>();
services.AddSingleton<AlipayService>();
services.AddSingleton<AlipayF2FService>();
return services;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Alipay.AopSdk.Core/Alipay.AopSdk.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>2.3.1</Version>
<Version>2.4.0</Version>
<Authors>stulzq</Authors>
<Description>支付宝(Alipay)服务端SDK,采用.NET Standard 2.0,支持.NET Core 2.0,与官方SDK接口完全相同。完全可以按照官方文档进行开发。除了支持支付以外,官方SDK支持的功能本SDK全部支持,且用法几乎一样,代码都可参考官方文档代码。github:https://github.com/stulzq/Alipay.AopSdk.Core,访问github获取demo以及使用文档。</Description>
<Copyright>Copyright 2017-2018 stulzq</Copyright>
Expand All @@ -12,14 +12,15 @@
<PackageTags>Alipay,AopSdk,支付宝服务端SDK,支付宝支付</PackageTags>
<PackageIconUrl>https://www.alipay.com/favicon.ico</PackageIconUrl>
<PackageReleaseNotes></PackageReleaseNotes>
<AssemblyVersion>2.3.1.0</AssemblyVersion>
<FileVersion>2.3.1.0</FileVersion>
<AssemblyVersion>2.4.0.0</AssemblyVersion>
<FileVersion>2.4.0.0</FileVersion>
<RepositoryUrl>https://github.com/stulzq/Alipay.AopSdk.Core</RepositoryUrl>
<RepositoryType>git</RepositoryType>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
</ItemGroup>

</Project>
76 changes: 50 additions & 26 deletions Alipay.AopSdk.Core/AlipayMobilePublicMultiMediaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Alipay.AopSdk.Core.Parser;
using Alipay.AopSdk.Core.Util;

Expand Down Expand Up @@ -44,12 +45,12 @@ public string Format
set => format = value;
}

public T pageExecute<T>(IAopRequest<T> request) where T : AopResponse
public T PageExecute<T>(IAopRequest<T> request) where T : AopResponse
{
throw new NotImplementedException();
}

public T pageExecute<T>(IAopRequest<T> request, string session, string reqMethod) where T : AopResponse
public T PageExecute<T>(IAopRequest<T> request, string session, string reqMethod) where T : AopResponse
{
throw new NotImplementedException();
}
Expand All @@ -59,7 +60,37 @@ public T SdkExecute<T>(IAopRequest<T> request) where T : AopResponse
throw new NotImplementedException();
}

private AopResponse DoGet(AopDictionary parameters, Stream outStream)
public Task<T> PageExecuteAsync<T>(IAopRequest<T> request) where T : AopResponse
{
throw new NotImplementedException();
}

public Task<T> PageExecuteAsync<T>(IAopRequest<T> request, string accessToken, string reqMethod) where T : AopResponse
{
throw new NotImplementedException();
}

public Task<T> ExecuteAsync<T>(IAopRequest<T> request) where T : AopResponse
{
throw new NotImplementedException();
}

public Task<T> ExecuteAsync<T>(IAopRequest<T> request, string accessToken) where T : AopResponse
{
throw new NotImplementedException();
}

public Task<T> ExecuteAsync<T>(IAopRequest<T> request, string accessToken, string appAuthToken) where T : AopResponse
{
throw new NotImplementedException();
}

private AopResponse DoGet(AopDictionary parameters, Stream outStream)
{
return AsyncHelper.RunSync(async () => await DoGetAsync(parameters, outStream));
}

private async Task<AopResponse> DoGetAsync(AopDictionary parameters, Stream outStream)
{
AlipayMobilePublicMultiMediaDownloadResponse response = null;

Expand All @@ -70,24 +101,21 @@ private AopResponse DoGet(AopDictionary parameters, Stream outStream)
else
url = url + "?" + WebUtils.BuildQuery(parameters, charset);

var req = webUtils.GetWebRequest(url, "GET");
req.ContentType = "application/x-www-form-urlencoded;charset=" + charset;

var rsp = (HttpWebResponse) req.GetResponse();
if (rsp.StatusCode == HttpStatusCode.OK)
if (rsp.ContentType.ToLower().Contains("text/plain"))
{
var encoding = Encoding.GetEncoding(rsp.CharacterSet);
var body = webUtils.GetResponseAsString(rsp, encoding);
IAopParser<AlipayMobilePublicMultiMediaDownloadResponse> tp =
new AopJsonParser<AlipayMobilePublicMultiMediaDownloadResponse>();
response = tp.Parse(body, charset);
}
else
{
GetResponseAsStream(outStream, rsp);
response = new AlipayMobilePublicMultiMediaDownloadResponse();
}
var client = webUtils.ConnectionPool.GetClient();
var query=new Uri(url).Query;
var resp = await client.GetAsync(query);
if (resp.StatusCode == HttpStatusCode.OK)
{

var body = await resp.Content.ReadAsStringAsync();
IAopParser<AlipayMobilePublicMultiMediaDownloadResponse> tp =
new AopJsonParser<AlipayMobilePublicMultiMediaDownloadResponse>();
response = tp.Parse(body, charset);
}
else
{
response = new AlipayMobilePublicMultiMediaDownloadResponse();
}
return response;
}

Expand Down Expand Up @@ -137,7 +165,7 @@ public AlipayMobilePublicMultiMediaClient(string serverUrl, string appId, string
this.appId = appId;
this.privateKeyPem = privateKeyPem;
this.serverUrl = serverUrl;
webUtils = new WebUtils();
webUtils = new WebUtils(serverUrl);
}

public AlipayMobilePublicMultiMediaClient(string serverUrl, string appId, string privateKeyPem, string format)
Expand All @@ -161,10 +189,6 @@ public AlipayMobilePublicMultiMediaClient(string serverUrl, string appId, string
this.signType = signType;
}

public void SetTimeout(int timeout)
{
webUtils.Timeout = timeout;
}

#endregion

Expand Down
Loading

0 comments on commit fb771c1

Please sign in to comment.