Closed joesjiang closed 7 years ago
微信回调的 Content-Type 为 text-xml,在这种情况下,不能获取 Request.Form。
修复方案,可以简单的加上 ContentType 的判断即可。
ResponseHandler.cs 的98行:
if (this.HttpContext.Request.Method.ToUpper() == "POST")
修改为:
if (this.HttpContext.Request.Method.ToUpper() == "POST" && this.HttpContext.Request.HasFormContentType)
异常信息:
System.InvalidOperationException: Incorrect Content-Type: text-xml at Microsoft.AspNetCore.Http.Features.FormFeature.ReadForm() at Senparc.Weixin.MP.TenPayLibV3.ResponseHandler..ctor(HttpContext httpContext) in E:\Senparc项目\WeiXinMPSDK\src\Senparc.Weixin.MP\Senparc.Weixin.MP\TenPayLibV3\ResponseHandler.cs:line 99 at Weishop.Areas.Mobile.Controllers.WeixinController.PayNotify() in ...
原因:在ResponseHandler的构造函数中读取Form信息时,仅判断了 HttpMethod ,没有判断 Content-Type。而在Asp.Net Core的对应实现中是会判断读取Form时Content-type :
https://github.com/aspnet/HttpAbstractions/blob/dev/src/Microsoft.AspNetCore.Http/Features/FormFeature.cs