public JsonResult AjaxComfirmedOrder(int id)
        {
            var order = offlineDB.CustomOrder.SingleOrDefault(m => m.Id == id);

            if (order != null)
            {
                order.OrderStatus = 2;
                offlineDB.SaveChanges();
                GPRSPrint.SendGprsPrintContent(GPRSPrint.TemplateCode(order.OrderNumber));
                //GPRSPrint.SendGprsPrintContent(GPRSPrint.TemplateCode(order.OrderNumber));
                return(Json(new { result = "SUCCESS" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { result = "FAIL" }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public ActionResult wx_pay_nofity()
        {
            StreamReader reader = new StreamReader(Request.InputStream, Encoding.UTF8);
            XmlDocument  doc    = new XmlDocument();

            doc.Load(reader);
            //CommonUtilities.writeLog(doc.OuterXml);
            string return_code = doc.GetElementsByTagName("return_code")[0].InnerText;

            try
            {
                if (return_code == "SUCCESS")
                {
                    string appid          = doc.GetElementsByTagName("appid")[0] == null ? "" : doc.GetElementsByTagName("appid")[0].InnerText;
                    string mch_id         = doc.GetElementsByTagName("mch_id")[0] == null ? "" : doc.GetElementsByTagName("mch_id")[0].InnerText;
                    string is_subscribe   = doc.GetElementsByTagName("is_subscribe")[0] == null ? "" : doc.GetElementsByTagName("is_subscribe")[0].InnerText;
                    string nonce_str      = doc.GetElementsByTagName("nonce_str")[0] == null ? "" : doc.GetElementsByTagName("nonce_str")[0].InnerText;
                    string request_sign   = doc.GetElementsByTagName("sign")[0] == null ? "" : doc.GetElementsByTagName("sign")[0].InnerText;
                    string result_code    = doc.GetElementsByTagName("result_code")[0] == null ? "" : doc.GetElementsByTagName("result_code")[0].InnerText;
                    string openid         = doc.GetElementsByTagName("openid")[0] == null ? "" : doc.GetElementsByTagName("openid")[0].InnerText;
                    string trade_type     = doc.GetElementsByTagName("trade_type")[0] == null ? "" : doc.GetElementsByTagName("trade_type")[0].InnerText;
                    string bank_type      = doc.GetElementsByTagName("bank_type")[0] == null ? "" : doc.GetElementsByTagName("bank_type")[0].InnerText;
                    string total_fee      = doc.GetElementsByTagName("total_fee")[0] == null ? "" : doc.GetElementsByTagName("total_fee")[0].InnerText;
                    string fee_type       = doc.GetElementsByTagName("fee_type")[0] == null ? "" : doc.GetElementsByTagName("fee_type")[0].InnerText;
                    string transaction_id = doc.GetElementsByTagName("transaction_id")[0] == null ? "" : doc.GetElementsByTagName("transaction_id")[0].InnerText;
                    string out_trade_no   = doc.GetElementsByTagName("out_trade_no")[0] == null ? "" : doc.GetElementsByTagName("out_trade_no")[0].InnerText;
                    string attach         = doc.GetElementsByTagName("attach")[0] == null ? "" : doc.GetElementsByTagName("attach")[0].InnerText;
                    string time_end       = doc.GetElementsByTagName("time_end")[0] == null ? "" : doc.GetElementsByTagName("time_end")[0].InnerText;
                    string device_info    = doc.GetElementsByTagName("device_info")[0] == null ? "" : doc.GetElementsByTagName("device_info")[0].InnerText;
                    var    order          = offlineDB.WxPayOrder.SingleOrDefault(m => m.Trade_No == out_trade_no);
                    if (order != null)
                    {
                        // 已成功订单
                        CommonUtilities.writeLog("有订单");
                        if (order.Trade_Status == WeChatUtilities.TRADE_STATUS_SUCCESS)
                        {
                            CommonUtilities.writeLog("已成功");
                            string xmldoc = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                            return(Content(xmldoc, "text/plain"));
                        }
                        // 通知成功
                        if (result_code == "SUCCESS")
                        {
                            //order.Attach = attach;
                            order.Bank_Type    = bank_type;
                            order.Fee_Type     = fee_type;
                            order.Trade_Status = WeChatUtilities.TRADE_STATUS_SUCCESS;
                            order.Trade_Type   = trade_type;
                            //CommonUtilities.writeLog("修改订单");

                            order.Time_Expire = DateTime.ParseExact(time_end, "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                            offlineDB.SaveChanges();
                            //判断是否需要打印小票
                            if (device_info != "")
                            {
                                string printContent = "上海寿全斋电子商务有限公司\r\n" +
                                                      "订单编号:" + transaction_id + "\r\n" +
                                                      "订单金额:" + (double)Convert.ToInt32(total_fee) / 100 + "元\r\n" +
                                                      "付款时间:" + time_end + "\r\n" + "<q>http://www.shouquanzhai.cn/</q>";
                                GPRSPrint.SendGprsPrintContent(printContent);
                            }
                            string xmldoc = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                            return(Content(xmldoc, "text/plain"));
                        }
                        else
                        {
                            string xmldoc = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[未知错误]]></return_msg></xml>";
                            return(Content(xmldoc, "text/plain"));
                        }
                    }
                    CommonUtilities.writeLog("无订单");
                }
                else
                {
                    string err_code     = doc.GetElementsByTagName("err_code")[0].InnerText;
                    string err_code_des = doc.GetElementsByTagName("err_code_des")[0].InnerText;
                    string out_trade_no = doc.GetElementsByTagName("out_trade_no")[0].InnerText;
                    var    order        = offlineDB.WxPayOrder.SingleOrDefault(m => m.Trade_No == out_trade_no);
                    if (order != null)
                    {
                        // 已成功订单
                        if (order.Trade_Status == WeChatUtilities.TRADE_STATUS_SUCCESS)
                        {
                            string xmldoc = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                            return(Content(xmldoc, "text/plain"));
                        }
                        // 不成功订单
                        else
                        {
                            order.Error_Msg     = err_code;
                            order.Error_Msg_Des = err_code_des;
                            order.Trade_Status  = WeChatUtilities.TRADE_STATUS_CLOSE;
                            offlineDB.SaveChanges();

                            string xmldoc = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
                            return(Content(xmldoc, "text/plain"));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                CommonUtilities.writeLog(e.Message + "," + e.StackTrace + "," + e.Source + "," + e.InnerException);
            }
            string xml = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[未知错误]]></return_msg></xml>";

            return(Content(xml, "text/plain"));
        }