Пример #1
0
 public ResponseResult Query([FromBody] QueryInfo query)
 {
     ColoPay.Model.Pay.Enterprise CurrEnterprise = bll.GetEnterpriseInfo(query.appid, query.secrit);
     if (CurrEnterprise == null)
     {
         return(FailResult(ResponseCode.ParamError, "appid or secrit is illegal"));
     }
     //判断订单是否存在
     ColoPay.Model.Pay.Order orderInfo = orderBll.GetModelEx(query.order_no, CurrEnterprise.EnterpriseID);
     if (orderInfo.PaymentStatus != 2)//订单状态未支付,则去支付平台查询一次
     {
         bool hasPaid = ColoPay.WebApi.PayApi.BZ_Pay.HasPaid(orderInfo.OrderCode);
         if (hasPaid)
         {
             bool isSuccess = orderBll.CompleteOrder(orderInfo);
             if (isSuccess)
             {
                 orderInfo.PaymentStatus = 2;
                 orderInfo.OrderStatus   = 1;
                 orderBll.HasNotify(orderInfo.OrderId);
             }
         }
     }
     YSWL.Json.JsonObject jsonObject = new JsonObject();
     jsonObject["appid"]      = query.appid;
     jsonObject["secrit"]     = query.secrit;
     jsonObject["order_no"]   = orderInfo.EnterOrder;
     jsonObject["amount"]     = orderInfo.Amount.ToString();
     jsonObject["sdorder_no"] = orderInfo.OrderCode;
     jsonObject["paytype"]    = orderInfo.PaymentGateway;
     jsonObject["status"]     = orderInfo.PaymentStatus.ToString();
     return(SuccessResult(jsonObject));
 }
Пример #2
0
        public static string Notify(ColoPay.Model.Pay.Order orderInfo)
        {
            //进行异步通知了,说明是已经支付成功了。
            orderInfo.PaymentStatus = 2;
            var           request = (HttpWebRequest)WebRequest.Create(orderInfo.AppNotifyUrl);
            StringBuilder builder = new StringBuilder();

            builder.Append(CreateField("appid", orderInfo.AppId));
            builder.Append(CreateField("secrit", orderInfo.AppSecrit));
            builder.Append(CreateField("order_no", orderInfo.EnterOrder));
            builder.Append(CreateField("amount", orderInfo.Amount.ToString()));
            builder.Append(CreateField("sdorder_no", orderInfo.OrderCode));
            builder.Append(CreateField("paytype", orderInfo.PaymentGateway));
            builder.Append(CreateField("status", orderInfo.PaymentStatus.ToString()));
            string postData = builder.ToString().Substring(1);
            var    data     = Encoding.UTF8.GetBytes(postData);

            request.Method        = "POST";
            request.ContentType   = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;
            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            var    response       = (HttpWebResponse)request.GetResponse();
            string responseString = new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd();

            if (responseString == "success")//如果是返回成功,则说明已经异步通知了,需要更新本地的订单状态
            {
                ColoPay.BLL.Pay.Order orderBll = new ColoPay.BLL.Pay.Order();
                //更新同步状态
                orderBll.HasNotify(orderInfo.OrderId);
            }
            return(responseString);
        }