liujunjieonline 2022-04-13 15:19 采纳率: 68.8%
浏览 70
已结题

微信支付结果回调不通,不知道为啥,有经验的帮我瞅瞅

问题遇到的现象和发生背景

以前微信支付结果通知是用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;
    }
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

2条回答 默认 最新

  • liujunjieonline 2022-04-13 15:39
    关注

    路过的给点意见吧

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月22日
  • 创建了问题 4月13日

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试