| | |
| | | /// 支付宝资金二级商户KYB代进件 |
| | | /// </summary> |
| | | public class AlipayFundExpandindirectCommandHandler( |
| | | IOptions<AlipayOptions> options, |
| | | AlipayUtils alipayUtils, |
| | | IHttpRemoteService httpRemoteService, |
| | | IRepository<AlipayFundExpandindirectOrder> rep |
| | | ) : |
| | | IRequestHandler<AlipayFundExpandindirectCreateCommand, Guid>, |
| | | IRequestHandler<AlipayFundExpandindirectImageUploadCommand, string>, |
| | | IRequestHandler<AlipayFundExpandindirectOrderCancelCommand, Guid>, |
| | | IRequestHandler<AlipayFundExpandindirectCreateNotifyCommand, Guid> |
| | | { |
| | | private readonly IOptions<AlipayOptions> options = options; |
| | | private readonly AlipayUtils alipayUtils = alipayUtils; |
| | | private readonly IHttpRemoteService httpRemoteService = httpRemoteService; |
| | | private readonly IRepository<AlipayFundExpandindirectOrder> rep = rep; |
| | |
| | | else |
| | | { |
| | | entity = new AlipayFundExpandindirectOrder(); |
| | | } |
| | | if (request.SceneImageOssUrl.IsNotNull() && entity.SceneImageOssUrl != request.SceneImageOssUrl) |
| | | { |
| | | entity.SceneImage = await GetAlipayImageIdAsync(request, request.SceneImageOssUrl); |
| | | } |
| | | if (request.SceneQualificationText.IsNotNull()) |
| | | { |
| | | entity.SceneQualificationImage = request.SceneQualificationText; |
| | | } |
| | | else if (request.SceneQualificationImageOssUrl.IsNotNull() && entity.SceneQualificationImageOssUrl != request.SceneQualificationImageOssUrl) |
| | | { |
| | | entity.SceneQualificationImage = await GetAlipayImageIdAsync(request, request.SceneQualificationImageOssUrl); |
| | | } |
| | | entity.Sites = request.SitesInfo.ToJson(); |
| | | request.Adapt(entity); |
| | |
| | | secondaryPartnerInfo.Name = entity.Name; |
| | | secondaryPartnerInfo.IdentityType = entity.IdentityType; |
| | | model.SecondaryPartnerInfo = secondaryPartnerInfo; |
| | | var result = alipayUtils.FundExpandindirectCreate(model, $"{options.Value.NotifyUrl}/api/user/enterpriseWallet/alipayFundExpandindirectCreateNotify"); |
| | | var result = alipayUtils.FundExpandindirectCreate(model, $"/api/user/enterpriseWallet/alipayFundExpandindirectCreateNotify"); |
| | | if (result.IsError) |
| | | { |
| | | entity.RiskReviewRemark = result.Msg; |
| | |
| | | throw Oops.Oh(EnumErrorCodeType.s510, result.Msg); |
| | | } |
| | | return entity.Id; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 支付宝资金二级商户KYB代进件文件上传接口 |
| | | /// </summary> |
| | | /// <param name="request"></param> |
| | | /// <param name="cancellationToken"></param> |
| | | /// <returns></returns> |
| | | public async Task<string> Handle(AlipayFundExpandindirectImageUploadCommand request, CancellationToken cancellationToken) |
| | | { |
| | | using (var memoryStream = new MemoryStream()) |
| | | { |
| | | await request.File.CopyToAsync(memoryStream); |
| | | var bytes = memoryStream.ToArray(); |
| | | var result = alipayUtils.FundExpandindirectImageUpload(new Aop.Api.Request.AlipayFundExpandindirectImageUploadRequest |
| | | { |
| | | ProductCode = request.ProductCode, |
| | | BizScene = request.BizScene, |
| | | ImageType = Path.GetExtension(request.File.FileName).Trim('.').ToLower(), |
| | | ImageContent = new Aop.Api.Util.FileItem(request.File.FileName, bytes) |
| | | }); |
| | | if (result.IsError) throw Oops.Oh(EnumErrorCodeType.s510, result.Msg); |
| | | return result.ImageId; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | public Task<Guid> Handle(AlipayFundExpandindirectCreateNotifyCommand request, CancellationToken cancellationToken) |
| | | { |
| | | return Task.FromResult(Guid.Empty); |
| | | } |
| | | |
| | | private async Task<string> GetAlipayImageIdAsync(AlipayFundExpandindirectCreateCommand request, string ossUrl) |
| | | { |
| | | var url = AliyunOSSUtils.GetUrl(ossUrl); |
| | | var bytes = await httpRemoteService.GetAsByteArrayAsync(url); |
| | | var imageType = url.Substring(url.LastIndexOf(".") + 1); |
| | | var fileName = url.Substring(url.LastIndexOf("/") + 1); |
| | | var result = alipayUtils.FundExpandindirectImageUpload(new Aop.Api.Request.AlipayFundExpandindirectImageUploadRequest |
| | | { |
| | | ProductCode = request.ProductCode, |
| | | BizScene = request.BizScene, |
| | | ImageType = imageType, |
| | | ImageContent = new Aop.Api.Util.FileItem(fileName, bytes) |
| | | }); |
| | | if (result.IsError) throw Oops.Oh(EnumErrorCodeType.s510, result.Msg); |
| | | return result.ImageId; |
| | | } |
| | | } |
| | | } |