mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 16:03:25 +08:00
后端【新增】新增商家转账功能后台处理及接口回调获取。
This commit is contained in:
137
CoreCms.Net.Task/AutoRefreshPlatformCertificateJob.cs
Normal file
137
CoreCms.Net.Task/AutoRefreshPlatformCertificateJob.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* CreateTime: 2020-08-25 1:25:29
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using CoreCms.Net.IServices;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Settings;
|
||||
using SKIT.FlurlHttpClient.Wechat.TenpayV3.Models;
|
||||
|
||||
namespace CoreCms.Net.Task
|
||||
{
|
||||
/// <summary>
|
||||
/// 定时更新微信支付平台证书
|
||||
/// </summary>
|
||||
public class AutoRefreshPlatformCertificateJob
|
||||
{
|
||||
|
||||
private readonly IWeChatPayConfigServices _weChatPayConfigServices;
|
||||
private readonly IWechatTenpayClientFactory _wechatTenpayClientFactory;
|
||||
private readonly ICoreCmsWeChatPayPlatformCertificateServices _weChatPayPlatformCertificateServices;
|
||||
private readonly ISysTaskLogServices _taskLogServices;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
public AutoRefreshPlatformCertificateJob(IWeChatPayConfigServices weChatPayConfigServices, IWechatTenpayClientFactory wechatTenpayClientFactory, ICoreCmsWeChatPayPlatformCertificateServices weChatPayPlatformCertificateServices, ISysTaskLogServices taskLogServices)
|
||||
{
|
||||
_weChatPayConfigServices = weChatPayConfigServices;
|
||||
_wechatTenpayClientFactory = wechatTenpayClientFactory;
|
||||
_weChatPayPlatformCertificateServices = weChatPayPlatformCertificateServices;
|
||||
_taskLogServices = taskLogServices;
|
||||
}
|
||||
|
||||
public async System.Threading.Tasks.Task Execute()
|
||||
{
|
||||
var config = await _weChatPayConfigServices.QueryListByClauseAsync(p => p.isDefault == true && p.isEnable == true);
|
||||
if (config != null)
|
||||
{
|
||||
foreach (var item in config)
|
||||
{
|
||||
try
|
||||
{
|
||||
const string algorithmType = "RSA";
|
||||
var client = await _wechatTenpayClientFactory.Create(item.mchId);
|
||||
var request = new QueryCertificatesRequest() { AlgorithmType = algorithmType };
|
||||
var response = await client.ExecuteQueryCertificatesAsync(request);
|
||||
if (response.IsSuccessful())
|
||||
{
|
||||
// NOTICE:
|
||||
// 如果构造 Client 时启用了 `AutoDecryptResponseSensitiveProperty` 配置项,则无需再执行下面一行的手动解密方法:
|
||||
response = client.DecryptResponseSensitiveProperty(response);
|
||||
|
||||
foreach (var certificate in response.CertificateList)
|
||||
{
|
||||
var entity = CertificateEntry.Parse(algorithmType, certificate);
|
||||
|
||||
// 将证书添加到平台证书管理器中
|
||||
var model = await _weChatPayPlatformCertificateServices.QueryByClauseAsync(p =>
|
||||
p.merchantId == item.mchId);
|
||||
if (model != null)
|
||||
{
|
||||
model.algorithmType = entity.AlgorithmType;
|
||||
model.serialNumber = entity.SerialNumber;
|
||||
model.certificate = entity.Certificate;
|
||||
model.effectiveTime = entity.EffectiveTime.DateTime;
|
||||
model.expireTime = entity.ExpireTime.DateTime;
|
||||
|
||||
model.updataTime = DateTime.Now;
|
||||
await _weChatPayPlatformCertificateServices.UpdateAsync(model);
|
||||
}
|
||||
else
|
||||
{
|
||||
model = new CoreCmsWeChatPayPlatformCertificate();
|
||||
model.algorithmType = entity.AlgorithmType;
|
||||
model.serialNumber = entity.SerialNumber;
|
||||
model.certificate = entity.Certificate;
|
||||
model.effectiveTime = entity.EffectiveTime.DateTime;
|
||||
model.expireTime = entity.ExpireTime.DateTime;
|
||||
model.merchantId = item.mchId;
|
||||
model.createTime = DateTime.Now;
|
||||
await _weChatPayPlatformCertificateServices.InsertAsync(model);
|
||||
}
|
||||
//client.PlatformCertificateManager.AddEntry(entity);
|
||||
}
|
||||
|
||||
//插入日志
|
||||
var log = new SysTaskLog
|
||||
{
|
||||
createTime = DateTime.Now,
|
||||
isSuccess = true,
|
||||
name = "刷新微信商户平台证书成功",
|
||||
parameters = JsonConvert.SerializeObject(response)
|
||||
};
|
||||
await _taskLogServices.InsertAsync(log);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//插入日志
|
||||
var log = new SysTaskLog
|
||||
{
|
||||
createTime = DateTime.Now,
|
||||
isSuccess = true,
|
||||
name = "刷新微信商户平台证书失败",
|
||||
parameters = $"刷新微信商户平台证书失败(状态码:{response.GetRawStatus()},错误代码:{response.ErrorCode},错误描述:{response.ErrorMessage})。",
|
||||
};
|
||||
await _taskLogServices.InsertAsync(log);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
//插入日志
|
||||
var log = new SysTaskLog
|
||||
{
|
||||
createTime = DateTime.Now,
|
||||
isSuccess = true,
|
||||
name = "刷新微信商户平台证书遇到异常",
|
||||
parameters = JsonConvert.SerializeObject(ex)
|
||||
};
|
||||
await _taskLogServices.InsertAsync(log);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,6 +70,9 @@ namespace CoreCms.Net.Task
|
||||
//自动取消服务器订单任务
|
||||
RecurringJob.AddOrUpdate<AutoCancelServiceOrderJob>("AutoCancelServiceOrderJob", s => s.Execute(), "0 0/5 * * * ? ", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); // 每5分钟取消一次订单
|
||||
|
||||
//定时更新微信支付平台证书
|
||||
RecurringJob.AddOrUpdate<AutoRefreshPlatformCertificateJob>("AutoRefreshPlatformCertificateJob", s => s.Execute(), "0 0 6 * * ? ", new RecurringJobOptions { TimeZone = TimeZoneInfo.Local }); // 每天凌晨6点执行,首次可以自主进入定时任务页面手动执行一次
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user