protected virtual void EncryptMsg(ref string response) { if (this.SignModel != null && !string.IsNullOrEmpty(this.SignModel.msg_signature)) { MsgCryptUtility mc = new MsgCryptUtility(WeiXinContext.Config.Token, WeiXinContext.Config.EncodingAESKey, WeiXinContext.Config.AppID); var ret = mc.EncryptMsg(response, this.SignModel.timestamp, this.SignModel.nonce, ref response); if (ret != 0) { throw new Exception("消息加密失败"); } } }
protected virtual void DecryptMsg() { if (this.SignModel != null && !string.IsNullOrEmpty(this.SignModel.msg_signature)) { MsgCryptUtility mc = new MsgCryptUtility(WeiXinContext.Config.Token, WeiXinContext.Config.EncodingAESKey, WeiXinContext.Config.AppID); var requestXml = this.RequestXml; var ret = mc.DecryptMsg(this.SignModel.msg_signature, this.SignModel.timestamp, this.SignModel.nonce, requestXml, ref requestXml); if (ret != 0) { throw new Exception("消息解密失败"); } this.RequestXml = requestXml; } this.RequestMessage = RequestMessageFactory.GetRequestEntity(this.RequestXml); }