mirror of
https://github.com/CoreUnion/CoreShop.git
synced 2026-10-21 16:26:01 +08:00
cd4c2acb05
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、【接口】增加微信消息推送的实现及事件处理方法,目前只做了用户发送文字信息转发客服,其他可自行进行拓展。
69 lines
3.0 KiB
C#
69 lines
3.0 KiB
C#
/***********************************************************************
|
|
* Project: CoreCms
|
|
* ProjectName: 核心内容管理系统
|
|
* Web: https://www.corecms.net
|
|
* Author: 大灰灰
|
|
* Email: jianweie@163.com
|
|
* CreateTime: 2021/7/29 21:44:44
|
|
* Description: 暂无
|
|
***********************************************************************/
|
|
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using CoreCms.Net.WeChat.Service.Models;
|
|
|
|
namespace CoreCms.Net.WeChat.Service.Utilities
|
|
{
|
|
/// <summary>签名验证类</summary>
|
|
public class CheckSignature
|
|
{
|
|
/// <summary>在网站没有提供Token(或传入为null)的情况下的默认Token,建议在网站中进行配置。</summary>
|
|
public const string Token = "weixin";
|
|
|
|
/// <summary>检查签名是否正确</summary>
|
|
/// <param name="signature"></param>
|
|
/// <param name="postModel">需要提供:Timestamp、Nonce、Token</param>
|
|
/// <returns></returns>
|
|
public static bool Check(string signature, PostModel postModel) => CheckSignature.Check(signature, postModel.Timestamp, postModel.Nonce, postModel.Token);
|
|
|
|
/// <summary>检查签名是否正确</summary>
|
|
/// <param name="signature"></param>
|
|
/// <param name="timestamp"></param>
|
|
/// <param name="nonce"></param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
public static bool Check(string signature, string timestamp, string nonce, string token = null) => signature == CheckSignature.GetSignature(timestamp, nonce, token);
|
|
|
|
/// <summary>返回正确的签名</summary>
|
|
/// <param name="postModel">需要提供:Timestamp、Nonce、Token</param>
|
|
/// <returns></returns>
|
|
public static string GetSignature(PostModel postModel) => CheckSignature.GetSignature(postModel.Timestamp, postModel.Nonce, postModel.Token);
|
|
|
|
/// <summary>返回正确的签名</summary>
|
|
/// <param name="timestamp"></param>
|
|
/// <param name="nonce"></param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
public static string GetSignature(string timestamp, string nonce, string token = null)
|
|
{
|
|
token = token ?? "weixin";
|
|
string s = string.Join("", ((IEnumerable<string>)new string[3]
|
|
{
|
|
token,
|
|
timestamp,
|
|
nonce
|
|
}).OrderBy<string, string>((Func<string, string>)(z => z)).ToArray<string>());
|
|
byte[] hash = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(s));
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
foreach (byte num in hash)
|
|
stringBuilder.AppendFormat("{0:x2}", (object)num);
|
|
return stringBuilder.ToString();
|
|
}
|
|
}
|
|
}
|