예제 #1
0
        /// <summary>
        /// 获取微信消息加密工具
        /// </summary>
        /// <param name="channelId"></param>
        /// <returns></returns>
        private static WXBizMsgCrypt GetWXBizMsgCrypt(int channelId)
        {
            var configDto = WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId).Result;

            var crypt = new WXBizMsgCrypt(configDto.Token, configDto.EncodingAESKey, configDto.AppId);

            return(crypt);
        }
예제 #2
0
        /// <summary>
        /// 校验微信公众号签名
        /// </summary>
        /// <param name="channelId">渠道id</param>
        /// <param name="msg_signature">微信加密签名,signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数</param>
        /// <param name="timestamp">时间戳</param>
        /// <param name="nonce">随机数</param>
        /// <returns></returns>
        public static bool CheckSignature(int channelId, string msg_signature, string timestamp, string nonce, string echo, out string replyEcho)
        {
            replyEcho = string.Empty;
            var configDto = WeixinConfigHelper.GetWeixinConfigDTOAsync(channelId).Result;
            var result    = msg_signature == GetSignature(timestamp, nonce, configDto.Token);

            if (result)
            {
                replyEcho = echo;
            }
            return(result);
        }