Files
CoreShop/CoreCms.Net.WeChat.Service/Utilities/RequestUtility.cs
T
JianWeie cd4c2acb05 1、【后端】移除业务逻辑中的【MediatR】及中介者模式,启用【Redis队列】处理。
2、【后端】因盛派过于臃肿及社区生态质量越来越低下,移除【Senparc】相关组件。启用【SKIT.FlurlHttpClient.Wechat】纯API组件,使交互更加灵活。
3、【后端】移除因依赖【Senparc】相关组件而创建的【CoreCms.Net.WeChatService】类库;增加SKIT.FlurlHttpClient.Wechat相应支撑组件的类库【CoreCms.Net.WeChat.Service】。
4、【后端】移除【sessionIdAuth】返回,直接使用【openId】作为识别码。
5、【接口】增加获取微信【AccessToken】的交互定时任务。
6、【数据库】增加【WeChatAccessToken】表备份数据库及SQL脚本。
8、【接口】增加微信消息推送的实现及事件处理方法,目前只做了用户发送文字信息转发客服,其他可自行进行拓展。
2021-08-01 17:45:29 +08:00

77 lines
3.4 KiB
C#

/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2021/7/29 23:24:45
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
namespace CoreCms.Net.WeChat.Service.Utilities
{
/// <summary>HTTP 请求工具类</summary>
public static class RequestUtility
{
/// <summary>【异步方法】从 Request.Body 中读取流,并复制到一个独立的 MemoryStream 对象中</summary>
/// <param name="request"></param>
/// <param name="allowSynchronousIO"></param>
/// <returns></returns>
public static async Task<Stream> GetRequestMemoryStreamAsync(
this HttpRequest request,
bool? allowSynchronousIO = true)
{
IHttpBodyControlFeature bodyControlFeature = request.HttpContext.Features.Get<IHttpBodyControlFeature>();
if (bodyControlFeature != null && allowSynchronousIO.HasValue)
bodyControlFeature.AllowSynchronousIO = allowSynchronousIO.Value;
return (Stream)new MemoryStream(Encoding.UTF8.GetBytes(await new StreamReader(request.Body).ReadToEndAsync()));
}
/// <summary>从 Request.Body 中读取流,并复制到一个独立的 MemoryStream 对象中</summary>
/// <param name="request"></param>
/// <param name="allowSynchronousIO"></param>
/// <returns></returns>
public static Stream GetRequestStream(
this HttpRequest request,
bool? allowSynchronousIO = true)
{
IHttpBodyControlFeature bodyControlFeature = request.HttpContext.Features.Get<IHttpBodyControlFeature>();
if (bodyControlFeature != null && allowSynchronousIO.HasValue)
bodyControlFeature.AllowSynchronousIO = allowSynchronousIO.Value;
return (Stream)new MemoryStream(Encoding.UTF8.GetBytes(new StreamReader(request.Body).ReadToEnd()));
}
/// <summary>从 Request.Body 中读取流,并复制到一个独立的 MemoryStream 对象中</summary>
/// <param name="request"></param>
/// <param name="allowSynchronousIO"></param>
/// <returns></returns>
public static MemoryStream GetRequestMemoryStream(
this HttpRequest request,
bool? allowSynchronousIO = true)
{
IHttpBodyControlFeature bodyControlFeature = request.HttpContext.Features.Get<IHttpBodyControlFeature>();
if (bodyControlFeature != null && allowSynchronousIO.HasValue)
bodyControlFeature.AllowSynchronousIO = allowSynchronousIO.Value;
return new MemoryStream(Encoding.UTF8.GetBytes(new StreamReader(request.Body).ReadToEnd()));
}
}
}