Commit 2ae59b01 authored by 吴春's avatar 吴春

提交代码

parent d5d7ada2
using System;
using System.Collections.Generic;
using System.Text;
using VT.FW.DB;
namespace Mall.Model.Entity.User
{
/// <summary>
/// 小程序实体类
/// </summary>
[Serializable]
[DB(ConnectionName = "DefaultConnection")]
public class RB_WeChatPublicAccount
{
public int ID { get; set; }
/// <summary>
/// 小程序主键Id
/// </summary>
public int MallBaseId
{
get;
set;
}
/// <summary>
/// 商户号
/// </summary>
public int TenantId
{
get;
set;
}
public string Token { get; set; }
public string EncodingAESKey { get; set; }
public string AppId { get; set; }
public string Appsecret { get; set; }
/// <summary>
/// Openid 多个英文逗号隔开 ("1,2,3")
/// </summary>
public string Openids { get; set; }
/// <summary>
/// 下单成功提醒(类目:服装/鞋/箱包)
/// </summary>
public string OrderSuccessTpl
{
get;
set;
}
/// <summary>
/// 订单取消提醒(类目:服装/鞋/箱包)
/// </summary>
public string OrderCancelTpl
{
get;
set;
}
/// <summary>
/// 创建时间
/// </summary>
public DateTime? CreateDate
{
get;
set;
}
/// <summary>
/// 状态(0-正常,1-禁用)
/// </summary>
public int Status { get; set; }
}
}
......@@ -44,6 +44,8 @@ namespace Mall.Module.Product
/// </summary>
public partial class OrderModule
{
private readonly RB_WeChatPublicAccountModule weChatPublicAccountModule = new RB_WeChatPublicAccountModule();
/// <summary>
/// 素材管理
/// </summary>
......@@ -7849,6 +7851,18 @@ namespace Mall.Module.Product
MallBaseId = mallBaseId,
TenantId = tenantId
}));
if (type == 2 && omodel.OrderClassify == 0 && omodel.TenantId == 16 && omodel.MallBaseId == 6)
{
try
{
weChatPublicAccountModule.SendOrderCancelMsg(omodel.TenantId, omodel.MallBaseId, omodel.OrderNo, DateTime.Now.ToString("yyyy年MM月dd日 HH时mm分"), omodel.Income.ToString());
}
catch (Exception ex)
{
}
}
}
goods_OrderRepository.DBSession.Commit();
return flag;
......
......@@ -4,6 +4,11 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Senparc.Weixin" Version="6.8.101" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.11.101" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Mall.AOP\Mall.AOP.csproj" />
<ProjectReference Include="..\Mall.CacheManager\Mall.CacheManager.csproj" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mall.Repository.User;
using Senparc.Weixin.MP.AdvancedAPIs;
using Senparc.Weixin.MP.AdvancedAPIs.TemplateMessage;
using Senparc.Weixin.MP.Containers;
namespace Mall.Module.User
{
public class RB_WeChatPublicAccountModule
{
/// <summary>
/// 商户仓储层对象
/// </summary>
private readonly RB_WeChatPublicAccountRepository weChatPublicAccountRepository = new RB_WeChatPublicAccountRepository();
/// <summary>
/// 下单成功发送订阅消息
/// </summary>
/// <param name="TenantId"></param>
/// <param name="MallBaseId"></param>
/// <param name="OpenId"></param>
/// <param name="OrderNo">订单编号</param>
/// <param name="OrderCreate">下单时间</param>
/// <param name="OrderPay">支付金额</param>
/// <param name="GoodsName">商品</param>
/// <returns></returns>
public bool SendOrderSucceedMsg(int TenantId, int MallBaseId, string OrderNo, string OrderCreate, string CustomerName, string GoodsName)
{
var appletWeChatModel = weChatPublicAccountRepository.GetWeChatPublicAccountListRepository(new Model.Entity.User.RB_WeChatPublicAccount { TenantId = TenantId, MallBaseId = MallBaseId }).FirstOrDefault();
if (appletWeChatModel == null || appletWeChatModel.ID == 0)
{
return false;
}
if (!AccessTokenContainer.CheckRegistered(appletWeChatModel.AppId))
{
AccessTokenContainer.RegisterAsync(appletWeChatModel.AppId, appletWeChatModel.Appsecret, "");
System.Threading.Thread.Sleep(3000);
}
string access_token = "";
try
{
access_token = AccessTokenContainer.GetAccessTokenResult(appletWeChatModel.AppId).access_token;
}
catch (Exception ex)
{
try
{
access_token = AccessTokenContainer.GetAccessTokenResult(appletWeChatModel.AppId).access_token;
}
catch (Exception exs)
{
}
}
if (string.IsNullOrWhiteSpace(access_token))
{
return false;
}
string TemplateId = appletWeChatModel.OrderSuccessTpl;
string linkUrl = "";
var data = new
{
first = new
{
value = "您收到了一条新的订单"
},
tradeDateTime = new
{
value = OrderCreate
},
orderType = new
{
value = "商品订单"
},
customerInfo = new
{
value = CustomerName
},
orderItemName = new
{
value = "订单信息"
},
orderItemData = new
{
value = GoodsName
},
remark = new
{
value = "订单号:" + OrderNo
}
};
try
{
foreach (var item in appletWeChatModel.Openids.Split(","))
{
if (!string.IsNullOrWhiteSpace(item))
{
try
{
SendTemplateMessageResult sendResult = TemplateApi.SendTemplateMessage(access_token, item, TemplateId, linkUrl, data);
}
catch (Exception ex)
{
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
/// 下单取消发送订阅消息
/// </summary>
/// <param name="TenantId"></param>
/// <param name="MallBaseId"></param>
/// <param name="OpenId"></param>
/// <param name="OrderNo">订单编号</param>
/// <param name="CancelReason">取消原因</param>
/// <param name="OrderMoney">订单金额</param>
/// <param name="GoodsName">商品</param>
/// <returns></returns>
public bool SendOrderCancelMsg(int TenantId, int MallBaseId, string OrderNo, string OrderCreate, string OrderMoney)
{
var appletWeChatModel = weChatPublicAccountRepository.GetWeChatPublicAccountListRepository(new Model.Entity.User.RB_WeChatPublicAccount { TenantId = TenantId, MallBaseId = MallBaseId }).FirstOrDefault();
if (appletWeChatModel == null || appletWeChatModel.ID == 0)
{
return false;
}
if (!AccessTokenContainer.CheckRegistered(appletWeChatModel.AppId))
{
AccessTokenContainer.RegisterAsync(appletWeChatModel.AppId, appletWeChatModel.Appsecret, "");
System.Threading.Thread.Sleep(3000);
}
string access_token = "";
try
{
access_token = AccessTokenContainer.GetAccessTokenResult(appletWeChatModel.AppId).access_token;
}
catch (Exception ex)
{
try
{
access_token = AccessTokenContainer.GetAccessTokenResult(appletWeChatModel.AppId).access_token;
}
catch (Exception exs)
{
}
}
if (string.IsNullOrWhiteSpace(access_token))
{
return false;
}
string TemplateId = appletWeChatModel.OrderCancelTpl;
string linkUrl = "";
var data = new
{
first = new
{
value = "您收到了一条新的订单取消"
},
keyword1 = new
{
value = OrderNo
},
keyword2 = new
{
value = OrderMoney
},
keyword3 = new
{
value = OrderCreate
},
remark = new
{
value = "请及时查看"
}
};
try
{
foreach (var item in appletWeChatModel.Openids.Split(","))
{
if (!string.IsNullOrWhiteSpace(item))
{
try
{
SendTemplateMessageResult sendResult = TemplateApi.SendTemplateMessage(access_token, item, TemplateId, linkUrl, data);
}
catch (Exception ex)
{
}
}
}
return true;
}
catch (Exception ex)
{
return false;
}
}
}
}
......@@ -122,6 +122,8 @@ namespace Mall.Module.User
private readonly MiniProgramMsgModule appletWeChatModule = new MiniProgramMsgModule();
private readonly RB_WeChatPublicAccountModule weChatPublicAccountModule = new RB_WeChatPublicAccountModule();
/// <summary>
/// vip购买仓储层
/// </summary>
......@@ -427,7 +429,7 @@ namespace Mall.Module.User
});
}
//获取缓存信息
TransactionPriceInfo transactionPriceInfo= CacheManager.User.UserReidsCache.GetTransactionPriceInfo(oldOrder.MallBaseId);
TransactionPriceInfo transactionPriceInfo = CacheManager.User.UserReidsCache.GetTransactionPriceInfo(oldOrder.MallBaseId);
if (transactionPriceInfo == null)
{
transactionPriceInfo = new TransactionPriceInfo();
......@@ -435,7 +437,8 @@ namespace Mall.Module.User
transactionPriceInfo.MallBaseId = oldOrder.MallBaseId;
transactionPriceInfo.TotalPrice = totalPrice;
}
else {
else
{
transactionPriceInfo.TotalPrice += totalPrice;
}
CacheManager.User.UserReidsCache.TransactionPriceSet(CacheKey.UserModuleCacheKeyConfig.Transaction_Price_ + oldOrder.MallBaseId, transactionPriceInfo, Config.JwtExpirTime);
......@@ -597,6 +600,17 @@ namespace Mall.Module.User
{
goodsName = goodsName.Substring(0, 10);
}
}
try
{
if (oldOrder.TenantId == 16 && oldOrder.MallBaseId == 6)
{
weChatPublicAccountModule.SendOrderSucceedMsg(oldOrder.TenantId, oldOrder.MallBaseId, oldOrder.OrderNo, oldOrder.CreateDate.Value.ToString("MM月dd日 HH时mm分"), umodel.Name, goodsName);
}
}
catch (Exception ex)
{
}
appletWeChatModule.SendOrderSucceedMsg(oldOrder.TenantId, oldOrder.MallBaseId, umodel.OpenId, oldOrder.OrderNo, oldOrder.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss"), (oldOrder.Income ?? 0).ToString(), goodsName);
......@@ -656,6 +670,8 @@ namespace Mall.Module.User
}
}
}
}
return flag;
}
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mall.Model.Entity.User;
namespace Mall.Repository.User
{
public class RB_WeChatPublicAccountRepository : BaseRepository<RB_WeChatPublicAccount>
{
/// <summary>
/// 根据查询条件获取公众号列表
/// </summary>
/// <param name="query">查询条件</param>
/// <returns></returns>
public List<RB_WeChatPublicAccount> GetWeChatPublicAccountListRepository(RB_WeChatPublicAccount query)
{
StringBuilder builder = new StringBuilder();
builder.Append(" SELECT * FROM RB_WeChatPublicAccount WHERE Status=0 ");
if (query != null)
{
if (query.TenantId > 0)
{
builder.AppendFormat(" AND TenantId={0} ", query.TenantId);
}
if (query.MallBaseId > 0)
{
builder.AppendFormat(" AND MallBaseId={0} ", query.MallBaseId);
}
}
return Get<RB_WeChatPublicAccount>(builder.ToString()).ToList();
}
}
}
......@@ -876,5 +876,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
#endregion
}
}
\ No newline at end of file
......@@ -405,7 +405,7 @@ namespace Mall.WebApi.Controllers.AppletWeChat
public ApiResult TestReturn()
{
RB_MiniProgram_Extend miniProgram = new RB_MiniProgram_Extend(); //2020年5月26号新增
miniProgram = new RB_MiniProgram_Extend { MiniAppId = "wxacd9f8cc3480d29e", WeChatApiSecret = "936110e2c2214340b9829a3608bde6b0", WeChatPayMerchants = "1562277941" }; // programModule.GetMiniProgramModule(new RB_MiniProgram_Extend { MallBaseId = 1, TenantId =1 });
miniProgram = new RB_MiniProgram_Extend { MiniAppId = "wx1bf3a7c76b10bb6d", WeChatApiSecret = "1e54ed9de09f99d87970aaf798cbc936", WeChatPayMerchants = "1554826431" }; // programModule.GetMiniProgramModule(new RB_MiniProgram_Extend { MallBaseId = 1, TenantId =1 });
string RefundOrderNo = "2020052916044326411";
var pram = new Common.Pay.WeChatPat.PayParam()
{
......
......@@ -24,6 +24,8 @@
<PackageReference Include="DotNetCore.CAP.RabbitMQ" Version="2.6.0" />
<PackageReference Include="JWT" Version="5.3.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
<PackageReference Include="Senparc.Weixin" Version="6.8.101" />
<PackageReference Include="Senparc.Weixin.MP" Version="16.11.101" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
</ItemGroup>
......
......@@ -16,6 +16,12 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Senparc.CO2NET;
using Senparc.CO2NET.RegisterServices;
using Senparc.Weixin;
using Senparc.Weixin.Entities;
using Senparc.Weixin.RegisterServices;
namespace Mall.WebApi
{
......@@ -36,8 +42,8 @@ namespace Mall.WebApi
.Configure<IISServerOptions>(x => x.AllowSynchronousIO = true);
services.AddControllers();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>(); //注入http上下文
services.AddSenparcGlobalServices(Configuration)//Senparc.CO2NET 全局注册
.AddSenparcWeixinServices(Configuration);//Senparc.Weixin 注册
services.AddMvc().AddJsonOptions(options =>
{
options.JsonSerializerOptions.Encoder = JavaScriptEncoder.Create(UnicodeRanges.All);
......@@ -82,7 +88,7 @@ namespace Mall.WebApi
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime, IOptions<SenparcSetting> senparcSetting, IOptions<SenparcWeixinSetting> senparcWeixinSetting)
{
if (env.IsDevelopment())
{
......@@ -102,7 +108,12 @@ namespace Mall.WebApi
endpoints.MapControllers();
});
// 启动 CO2NET 全局注册,必须!
IRegisterService register = RegisterService.Start(senparcSetting.Value)
.UseSenparcGlobal(false, null);
//开始注册微信信息,必须!
register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);
System.WebHttpContext.HttpContext.Configure(app.ApplicationServices.GetRequiredService<Microsoft.AspNetCore.Http.IHttpContextAccessor>());
//启动信息发送
Task.Run(() => MessageCore.Init());
......@@ -118,12 +129,12 @@ namespace Mall.WebApi
{
Timers.TimerJobj.RunStop(); //网站停止完成执行
});
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
Path.Combine(Directory.GetCurrentDirectory(), "upfile")),
RequestPath = "/upfile"
});
//app.UseStaticFiles(new StaticFileOptions
//{
// FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(
// Path.Combine(Directory.GetCurrentDirectory(), "upfile")),
// RequestPath = "/upfile"
//});
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment