mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2026-03-25 00:27:21 +08:00
【新增】增加MySql.Data组件,防止出现Nlog新版mysql不写入的问题。
【优化】优化本地上传写入文件夹缺少反斜杠的问题。 【修复】修复appsetting.json微信公众号配置项命名错误的问题。 【新增】定时任务增加微信公众号获取JS-Token并且全局缓存功能。 【新增】增加微信公众号获取JS-SDK使用权限签名算法。 【新增】新增微信公众号【微信被动回复消息】功能,用于关于公众号提醒,微信聊天被动关键词回复等。 【新增】新增微信公众号【微信菜单管理】功能,用于管理公众号底部三列五横的链接。 【新增】新增微信公众号【消息推送】接口及业务处理。用于接收从微信公众号推送的事件交互。 【新增】新增微信公众号【授权鉴权跳转】功能,用于验证是否为微信公众号访问,及获取openid等信息。 【新增】新增微信公众号用户accressToekn存储机制。 【新增】新增微信公众号发送模板消息方法。 【新增】数据库新增【WeChatMessageResponse】【WeChatUserAccessToken】两个表,【CoreCmsUserWeChatInfo】增加【isSubscribe】是否关注字段。 【新增】商品品牌管理品牌logo增加原图上传 【新增】商品分类管理分类图片增加原图上传 【新增】新增最新后台左侧管理菜单目录脚本,完整数据库脚本备份新增最新商品商品示例。
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
using CoreCms.Net.Caching.AccressToken;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AccressToken;
|
||||
using CoreCms.Net.Model;
|
||||
using CoreCms.Net.WeChat.Service.Enums;
|
||||
using CoreCms.Net.WeChat.Service.HttpClients;
|
||||
using CoreCms.Net.WeChat.Service.Options;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Options;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api;
|
||||
using SKIT.FlurlHttpClient.Wechat.Api.Models;
|
||||
|
||||
namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
{
|
||||
@@ -14,14 +23,17 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
[ApiController]
|
||||
public class WeChatOffiaccountController : Controller
|
||||
{
|
||||
private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
|
||||
private readonly WeChatOptions _weChatOptions;
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数
|
||||
/// </summary>
|
||||
/// <param name="weChatOptions"></param>
|
||||
public WeChatOffiaccountController(IOptions<WeChatOptions> weChatOptions)
|
||||
/// <param name="weChatApiHttpClientFactory"></param>
|
||||
public WeChatOffiaccountController(IOptions<WeChatOptions> weChatOptions, IWeChatApiHttpClientFactory weChatApiHttpClientFactory)
|
||||
{
|
||||
_weChatApiHttpClientFactory = weChatApiHttpClientFactory;
|
||||
_weChatOptions = weChatOptions.Value;
|
||||
}
|
||||
|
||||
@@ -54,6 +66,93 @@ namespace CoreCms.Net.Web.WebApi.Controllers
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通用发送模板消息方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<ActionResult> Send(TmpMsgModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = _weChatApiHttpClientFactory.CreateWeXinClient();
|
||||
var accessToken = WeChatCacheAccessTokenHelper.GetWeChatAccessToken();
|
||||
var request = new CgibinMessageTemplateSendRequest
|
||||
{
|
||||
AccessToken = accessToken,
|
||||
ToUserOpenId = model.OpenId,
|
||||
TemplateId = model.TemplateId,
|
||||
MiniProgram = null,
|
||||
Data = new ConcurrentDictionary<string, CgibinMessageTemplateSendRequest.Types.DataItem>()
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Url))
|
||||
{
|
||||
request.Url = model.Url;
|
||||
}
|
||||
|
||||
const string color = "#CCC";
|
||||
|
||||
if (!string.IsNullOrEmpty(model.First))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("first", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.First }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword1))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword1", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword1 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword2))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword2", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword2 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword3))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword3", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword3 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword4))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword4", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword4 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword5))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword5", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword5 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword6))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword6", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword6 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword7))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword7", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword7 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword8))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword8", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword8 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword9))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword9", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword9 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Keyword10))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("keyword10", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Keyword10 }));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(model.Remark))
|
||||
{
|
||||
request.Data.Add(new KeyValuePair<string, CgibinMessageTemplateSendRequest.Types.DataItem>("remark", new CgibinMessageTemplateSendRequest.Types.DataItem() { Color = color, Value = model.Remark }));
|
||||
}
|
||||
|
||||
var response = await client.ExecuteCgibinMessageTemplateSendAsync(request, HttpContext.RequestAborted);
|
||||
return response.ErrorCode != (int)WeChatReturnCode.ReturnCode.请求成功
|
||||
? Json(new { ResultCode = "1", Msg = "错误:" + response.ErrorMessage })
|
||||
: Json(new { ResultCode = "0", Msg = "已发送成功", Data = response.MessageId });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Json(new { ResultCode = "1", Msg = ex.ToString() });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user