protected bool Verify(XDocument rescontent, out XDocument content) { content = new XDocument(); XElement xml = rescontent.Root; XElement signElement = xml.Element("head").Element("md"); XElement bodyElement = xml.Element("body"); if (bodyElement.Value.VerifyMd5(signElement.Value) == false) { return(false); } XElement result = xml.Element("head").Element("result"); if (result.Value != "0") { return(false); } content = _crypter.Decrypt(bodyElement.Value, _options.SecretKey).ParseXml(); return(true); }
protected bool Verify(string msg, out string CipherText) { CipherText = string.Empty; ResContent rescon = JsonConvert.DeserializeObject <ResContent>(msg); if (rescon.resCode.Equals("0")) { string s = string.Format("{0}{1}{2}{3}{4}", rescon.apiCode, rescon.content, rescon.messageId, rescon.resCode, rescon.resMsg); string hmac = s.hmac_md5(_options.SecretKey.Substring(0, 16)).ToLower(); if (rescon.hmac != hmac) { return(false); } CipherText = _crypter.Decrypt(rescon.content, _options.SecretKey); } else { return(false); } return(true); }
/// <summary> /// /// </summary> /// <param name="httpContext"></param> /// <returns></returns> public async Task Invoke(HttpContext httpContext) { ResContent rescon = new ResContent(); try { var result = string.Empty; using (var reader = new StreamReader(httpContext.Request.Body, Encoding.UTF8)) { result = await reader.ReadToEndAsync(); ReqContent reqcon = JsonConvert.DeserializeObject <ReqContent>(result); string apicode = reqcon.apiCode; string partnerid = reqcon.partnerId; string messageid = reqcon.messageId; string hmac = reqcon.hmac; rescon.version = "1.0"; rescon.content = string.Empty; rescon.partnerId = partnerid; rescon.resCode = "1"; rescon.resMsg = ""; rescon.apiCode = apicode; rescon.messageId = messageid; string s = string.Format("{0}{1}{2}{3}", apicode, reqcon.content, messageid, partnerid); var merchanter = await _lotteryMerchanterApplicationService.FindMerchanterAsync(partnerid); string sign = s.hmac_md5(merchanter.SecretKey.Substring(0, 16)).ToLower(); if (sign == reqcon.hmac) { string CipherText = _crypter.Decrypt(reqcon.content, merchanter.SecretKey); if (apicode == "300002") { if (await TicketNoticing(CipherText)) { rescon.resCode = "0"; } } if (apicode == "300003") { if (await AwardNoticing(CipherText)) { rescon.resCode = "0"; } } } else { rescon.resMsg = "签名错误"; } } } catch (Exception ex) { _logger.LogError(ex.Message); } string json = JsonExtensions.ToJsonString(rescon); //HttpContent content = new StringContent(json, Encoding.UTF8, "application/json"); await httpContext.Response.WriteAsync(json); }