mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-22 12:17:21 +08:00
【新增】实现支付宝小程序适配。
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.24" />
|
||||
<PackageReference Include="AlipaySDKNet.Standard" Version="4.9.78" />
|
||||
<PackageReference Include="Aliyun.OSS.SDK.NetCore" Version="2.13.0" />
|
||||
<PackageReference Include="Essensoft.Paylink.Alipay" Version="4.1.3" />
|
||||
<PackageReference Include="Essensoft.Paylink.WeChatPay" Version="4.1.3" />
|
||||
|
||||
@@ -18,19 +18,19 @@ using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using CoreCms.Net.Model.Options;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Essensoft.Paylink.Alipay;
|
||||
using Essensoft.Paylink.Alipay.Domain;
|
||||
using Essensoft.Paylink.Alipay.Request;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Essensoft.Paylink.WeChatPay;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using static Aliyun.OSS.Model.LiveChannelStat;
|
||||
using Essensoft.Paylink.WeChatPay.V2.Request;
|
||||
using Essensoft.Paylink.WeChatPay.V2;
|
||||
using static SKIT.FlurlHttpClient.Wechat.Api.Models.ShopCouponGetResponse.Types.Result.Types.Coupon.Types.CouponDetail.Types.Discount.Types.DiscountCondidtion.Types;
|
||||
using Aop.Api;
|
||||
using static SKIT.FlurlHttpClient.Wechat.Api.Models.WxaICPApplyICPFilingRequest.Types;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
@@ -42,17 +42,19 @@ namespace CoreCms.Net.Services
|
||||
private readonly IAlipayClient _client;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IAlipayConfigServices _alipayConfigServices;
|
||||
private readonly AliPayOptions _options;
|
||||
|
||||
|
||||
|
||||
public AliPayServices(IWeChatPayRepository dal, IServiceProvider serviceProvider, IAlipayClient client, IAlipayConfigServices alipayConfigServices)
|
||||
public AliPayServices(IWeChatPayRepository dal, IServiceProvider serviceProvider, IAlipayClient client, IAlipayConfigServices alipayConfigServices, IOptions<AliPayOptions> options)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
_client = client;
|
||||
_alipayConfigServices = alipayConfigServices;
|
||||
_options = options.Value;
|
||||
BaseDal = dal;
|
||||
}
|
||||
|
||||
#region 发起支付宝支付
|
||||
/// <summary>
|
||||
/// 发起支付宝支付
|
||||
/// </summary>
|
||||
@@ -63,7 +65,14 @@ namespace CoreCms.Net.Services
|
||||
var jm = new WebApiCallBack();
|
||||
using var container = _serviceProvider.CreateScope();
|
||||
var billPaymentsServices = container.ServiceProvider.GetService<ICoreCmsBillPaymentsServices>();
|
||||
//var payment = await billPaymentsServices.QueryByClauseAsync(p => p.paymentId == entity.paymentId);
|
||||
var _aliPayUserInfoServices = container.ServiceProvider.GetService<ICoreCmsAliPayUserInfoServices>();
|
||||
|
||||
var aliUserInfo = await _aliPayUserInfoServices.QueryByClauseAsync(p => p.userInfoId == entity.userId);
|
||||
if (aliUserInfo == null)
|
||||
{
|
||||
jm.msg = "支付宝下单用户获取失败";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var tradeType = GlobalEnumVars.AliPayPayTradeType.ScanQRCodes.ToString();
|
||||
if (!string.IsNullOrEmpty(entity.parameters))
|
||||
@@ -73,8 +82,6 @@ namespace CoreCms.Net.Services
|
||||
tradeType = PayHelper.GetAliPayPayTradeType(value.ObjectToString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
var config = await _alipayConfigServices.QueryByClauseAsync(p => p.isDefault == true && p.isEnable == true && p.appType == tradeType);
|
||||
if (config == null)
|
||||
{
|
||||
@@ -90,7 +97,6 @@ namespace CoreCms.Net.Services
|
||||
|
||||
var notifyUrl = config.notifyUrl.EndsWith("/") ? config.notifyUrl + "m-" + config.appId : config.notifyUrl + "/m-" + config.appId;
|
||||
|
||||
|
||||
//构建linkPay请求配置实体
|
||||
var payOptions = new AlipayOptions
|
||||
{
|
||||
@@ -132,30 +138,43 @@ namespace CoreCms.Net.Services
|
||||
jm.status = !response.IsError;
|
||||
|
||||
}
|
||||
//支付宝小程序支付
|
||||
else if (tradeType == GlobalEnumVars.AliPayPayTradeType.JSAPI.ToString())
|
||||
{
|
||||
var model = new AlipayTradePagePayModel
|
||||
Aop.Api.IAopClient alipayClient = new Aop.Api.DefaultAopClient(_options.AliPublicApi, _options.AppId, _options.AppSecret, "json", "1.0", "RSA2", _options.AliPublicKey, "utf-8", false);
|
||||
|
||||
Aop.Api.Request.AlipayTradeCreateRequest request = new Aop.Api.Request.AlipayTradeCreateRequest();
|
||||
Aop.Api.Domain.AlipayTradeCreateModel model = new Aop.Api.Domain.AlipayTradeCreateModel();
|
||||
model.OutTradeNo = entity.paymentId;
|
||||
model.TotalAmount = entity.money.ToString(CultureInfo.InvariantCulture);
|
||||
model.Subject = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle;
|
||||
model.ProductCode = "JSAPI_PAY";
|
||||
model.OpAppId = _options.AppId;
|
||||
model.Body = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle;
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(aliUserInfo.userId))
|
||||
{
|
||||
OutTradeNo = entity.paymentId,
|
||||
Subject = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle,
|
||||
ProductCode = "JSAPI_PAY",
|
||||
TotalAmount = entity.money.ToString(CultureInfo.InvariantCulture),
|
||||
Body = entity.payTitle.Length > 40 ? entity.payTitle[..40] : entity.payTitle
|
||||
model.BuyerId = aliUserInfo.userId;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(aliUserInfo.openId))
|
||||
{
|
||||
model.OpBuyerOpenId = aliUserInfo.openId;
|
||||
}
|
||||
request.SetBizModel(model);
|
||||
request.SetNotifyUrl(notifyUrl);
|
||||
|
||||
Aop.Api.Response.AlipayTradeCreateResponse response = alipayClient.Execute(request);
|
||||
|
||||
jm.data = new
|
||||
{
|
||||
entity.paymentId,
|
||||
response.TradeNo
|
||||
};
|
||||
var req = new AlipayTradePagePayRequest();
|
||||
req.SetBizModel(model);
|
||||
req.SetNotifyUrl(notifyUrl);
|
||||
//req.SetReturnUrl(config.jumpUrl);
|
||||
|
||||
Loging.NLogUtil.WriteAll(NLog.LogLevel.Trace, Loging.LogType.Order, "支付宝JSAPI支付拼接支付宝小程序入参", JsonConvert.SerializeObject(model));
|
||||
var response = await _client.PageExecuteAsync(req, payOptions);
|
||||
Loging.NLogUtil.WriteAll(NLog.LogLevel.Trace, Loging.LogType.Order, "支付宝JSAPI支付返回数据", JsonConvert.SerializeObject(response));
|
||||
|
||||
jm.data = response.Body;
|
||||
//response.TradeNo = entity.paymentId;
|
||||
jm.otherData = response;
|
||||
jm.status = !response.IsError;
|
||||
jm.msg = response.IsError ? response.SubMsg : "支付宝小程序支付参数构建成功。";
|
||||
|
||||
}
|
||||
//PC网站支付
|
||||
else if (tradeType == GlobalEnumVars.AliPayPayTradeType.JSAPI_PC.ToString())
|
||||
@@ -179,7 +198,7 @@ namespace CoreCms.Net.Services
|
||||
|
||||
|
||||
jm.data = response.Body;
|
||||
//response.TradeNo = entity.paymentId;
|
||||
response.TradeNo = entity.paymentId;
|
||||
jm.otherData = response;
|
||||
jm.status = !response.IsError;
|
||||
|
||||
@@ -245,8 +264,9 @@ namespace CoreCms.Net.Services
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 用户退款
|
||||
/// <summary>
|
||||
/// 用户退款
|
||||
/// </summary>
|
||||
@@ -315,6 +335,47 @@ namespace CoreCms.Net.Services
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 换取授权访问令牌(alipay.system.oauth.token)
|
||||
/// <summary>
|
||||
/// 根据票据返回app_auth_token相关信息
|
||||
/// </summary>
|
||||
/// <param name="code">票据</param>
|
||||
/// <returns></returns>
|
||||
public Aop.Api.Response.AlipaySystemOauthTokenResponse GetAliPayAppAuthTokenBYCode(string code)
|
||||
{
|
||||
Aop.Api.IAopClient alipayClient = new Aop.Api.DefaultAopClient(_options.AliPublicApi, _options.AppId, _options.AppSecret, "json", "1.0", "RSA2", _options.AliPublicKey, "utf-8", false);
|
||||
|
||||
Aop.Api.Request.AlipaySystemOauthTokenRequest request = new Aop.Api.Request.AlipaySystemOauthTokenRequest();
|
||||
|
||||
request.GrantType = "authorization_code";
|
||||
request.Code = code;
|
||||
request.RefreshToken = _options.AliAccessTokenRefresh;
|
||||
|
||||
Aop.Api.Response.AlipaySystemOauthTokenResponse response = alipayClient.Execute(request);
|
||||
|
||||
return response;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 支付宝会员授权信息查询接口(alipay.user.info.share)
|
||||
/// <summary>
|
||||
/// 根据Token返回支付宝用户基本信息
|
||||
/// </summary>
|
||||
/// <param name="token">Token</param>
|
||||
public Aop.Api.Response.AlipayUserInfoShareResponse GetAliPayUserInfoByToken(string token)
|
||||
{
|
||||
Aop.Api.IAopClient alipayClient = new Aop.Api.DefaultAopClient(_options.AliPublicApi, _options.AppId, _options.AppSecret, "json", "1.0", "RSA2", _options.AliPublicKey, "utf-8", false);
|
||||
|
||||
Aop.Api.Request.AlipayUserInfoShareRequest request = new Aop.Api.Request.AlipayUserInfoShareRequest();
|
||||
Aop.Api.Response.AlipayUserInfoShareResponse response = alipayClient.Execute(request, token);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
||||
116
CoreCms.Net.Services/User/CoreCmsAliPayUserInfoServices.cs
Normal file
116
CoreCms.Net.Services/User/CoreCmsAliPayUserInfoServices.cs
Normal file
@@ -0,0 +1,116 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2024/4/10 星期三 22:28:09
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
|
||||
namespace CoreCms.Net.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 支付宝用户信息 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsAliPayUserInfoServices : BaseServices<CoreCmsAliPayUserInfo>, ICoreCmsAliPayUserInfoServices
|
||||
{
|
||||
private readonly ICoreCmsAliPayUserInfoRepository _dal;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
|
||||
public CoreCmsAliPayUserInfoServices(IUnitOfWork unitOfWork, ICoreCmsAliPayUserInfoRepository dal)
|
||||
{
|
||||
this._dal = dal;
|
||||
base.BaseDal = dal;
|
||||
_unitOfWork = unitOfWork;
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> InsertAsync(CoreCmsAliPayUserInfo entity)
|
||||
{
|
||||
return await _dal.InsertAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsAliPayUserInfo entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsAliPayUserInfo> entity)
|
||||
{
|
||||
return await _dal.UpdateAsync(entity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
return await _dal.DeleteByIdAsync(id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID集合的数据(批量删除)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
||||
{
|
||||
return await _dal.DeleteByIdsAsync(ids);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsAliPayUserInfo>> QueryPageAsync(Expression<Func<CoreCmsAliPayUserInfo, bool>> predicate,
|
||||
Expression<Func<CoreCmsAliPayUserInfo, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
return await _dal.QueryPageAsync(predicate, orderByExpression, orderByType, pageIndex, pageSize, blUseNoLock);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -571,7 +571,7 @@ public class CoreCmsUserServices : BaseServices<CoreCmsUser>, ICoreCmsUserServic
|
||||
/// <param name="loginType">登录方式(1普通,2短信,3微信小程序拉取手机号)</param>
|
||||
/// <param name="platform"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<WebApiCallBack> SmsLogin(FMWxAccountCreate entity,
|
||||
public async Task<WebApiCallBack> SmsLogin(FMComAccountCreate entity,
|
||||
int loginType = (int)GlobalEnumVars.LoginType.WeChatPhoneNumber,
|
||||
int platform = (int)GlobalEnumVars.CoreShopSystemCategory.Api)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user