问题遇到的现象和发生背景
以前微信支付结果通知是用aspx接收的,现在要改为webapi接收,现在测试下来,接收不到,我想问一下,代码是不是有啥问题的
问题相关代码,请勿粘贴截图
[HttpPost]
public dynamic ReceiveFromWctPayResult()
{
try
{
string strXML = string.Empty;
using (StreamReader sr = new StreamReader(Request.Body, Encoding.UTF8))
{
strXML = sr.ReadToEndAsync().Result;
}
STM_Applet applet = uow.Query<STM_Applet>().FirstOrDefault();
if (applet != null)
{
WctPayEntity receiveWctPayEntity = new WctPayEntity();
if (!string.IsNullOrEmpty(strXML) && receiveWctPayEntity.FromXml(strXML, true, applet.ApiKey) && receiveWctPayEntity.GetValue("return_code").ToString() == "SUCCESS")
{
WctAttachEntity wctAttachEntity = JsonHelper.Deserialize<WctAttachEntity>(distributedCache.GetString(receiveWctPayEntity.GetValue("attach").ToString()));
if (wctAttachEntity != null)
{
Order currentOrder = uow.Query<Order>().Where(x => x.OrderNo == receiveWctPayEntity.GetValue("out_trade_no").ToString()).FirstOrDefault();
#region 更新订单状态
currentOrder.OrderStatus = currentOrder.OrderGoodsType == Order.OrderGoodsTypeEnum.商品 ? OrderStatus.待发货 : OrderStatus.待预约;
#endregion 更新订单状态
#region 更新支付流水
List<Order_Payment> currentOrderPayments = uow.Query<Order_Payment>().Where(x => x.OrderPayNo == currentOrder.OrderNo).ToList();
for (int i = 0; i < currentOrderPayments.Count; i++)
{
currentOrderPayments[i].ConfirmStatus = Order_Payment.ConfirmStatusEnum.已确认;
currentOrderPayments[i].ConfirmTime = DateTime.Now;
currentOrderPayments[i].PayStatus = Order_Payment.PayStatusEnum.已支付;
currentOrderPayments[i].ModifyTime = DateTime.Now;
currentOrderPayments[i].PayTime = Convert.ToDateTime(receiveWctPayEntity.GetValue("time_end").ToString());
if (currentOrderPayments[i].PayType == Order_Payment.PayTypeEnum.微信)
{
currentOrderPayments[i].PayMentTradeNo = receiveWctPayEntity.GetValue("transaction_id").ToString();
}
else
{
#region 卡冻结操作记录(冻结)
BMS_PrepaidCard_Public currentPrepaidCardPublic = uow.FindObject<BMS_PrepaidCard_Public>(CriteriaOperator.Parse("CardCode='" + currentOrderPayments[i].PayMentTradeNo + "'"));
if (currentPrepaidCardPublic != null)
{
currentPrepaidCardPublic.FreezeMoney += currentOrderPayments[i].PayMoney;
BMS_PrepaidCard_Frozen currentPrepaidCardFrozen = new BMS_PrepaidCard_Frozen(uow);
currentPrepaidCardFrozen.BeforeMoney = currentPrepaidCardPublic.CardMoney;
currentPrepaidCardFrozen.CardCode = currentPrepaidCardPublic.CardCode;
currentPrepaidCardFrozen.ChipCode = currentPrepaidCardPublic.ChipCode;
currentPrepaidCardFrozen.CurrentMoney = 0;
currentPrepaidCardFrozen.FrozenMoney = currentOrderPayments[i].PayMoney;
currentPrepaidCardFrozen.FrozenStatus = 0;
currentPrepaidCardFrozen.FrozenSource = "1";
currentPrepaidCardFrozen.OperateType = 1;
currentPrepaidCardFrozen.OrderID = currentOrder.Oid.ToString();
currentPrepaidCardFrozen.PublicID = currentPrepaidCardPublic.Oid.ToString();
currentPrepaidCardFrozen.Remark = "平台冻结金额";
}
#endregion 卡冻结操作记录(冻结)
}
}
#endregion 更新支付流水
#region 创建订单明细
if (currentOrder.OrderGoodsType != Order.OrderGoodsTypeEnum.商品)
{
for (int i = 0; i < currentOrder.Details.Count; i++)
{
for (int j = 0; j < currentOrder.Details[j].BuyCount; j++)
{
Order_Credentials currentCredentials = new Order_Credentials(uow);
currentCredentials.CredentialNo = "不知道咋生成的";
currentCredentials.CredentialsType = string.IsNullOrEmpty(currentOrder.Details[j].UnionCode) ? 1 : 0;
currentCredentials.CardExpiredDate = DateTime.Now.AddMonths(3);
currentCredentials.OrderId = currentOrder.Oid;
currentCredentials.OrderNo = currentOrder.OrderNo;
currentCredentials.OrderPackageID = currentOrder.Details[j].OrderPackageId;
currentCredentials.PackageTitle = currentOrder.OrderGoodsType == Order.OrderGoodsTypeEnum.套餐 ? currentOrder.Details[j].Title : currentOrder.Details[j].Title + "自定义";
currentCredentials.Price = currentOrder.Details[j].Price;
currentCredentials.Status = Order_Credentials.StatusEnum.待预约;
currentCredentials.UnionCode = currentOrder.Details[j].UnionCode;
currentCredentials.UnionID = currentOrder.Details[j].UnionId;
currentCredentials.UnionName = currentOrder.Details[j].UnionName;
currentCredentials.UserID = currentOrder.UserID.Oid;
currentCredentials.CreateTime = DateTime.Now;
currentCredentials.CreateTrueName = "平台";
currentCredentials.ModifyTime = DateTime.Now;
currentCredentials.ModifyTrueName = "平台";
}
}
}
#endregion 创建订单明细
uow.CommitChanges();
}
WctPayEntity responseWctPayEntity = new WctPayEntity();
responseWctPayEntity.SetValue("return_code", "![CDATA[SUCCESS]]");
responseWctPayEntity.SetValue("return_msg", "![CDATA[OK]] ");
return responseWctPayEntity.ToXml();
}
}
}
catch (Exception)
{
}
return null;
}