예제 #1
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);
        }