示例#1
0
        public static bool SendTemplateMessage <T>(string companyId, string accessToken, string openId, string templateId, string topcolor, T data)
        {
            var pdata = new Templete
            {
                template_id = templateId,
                topcolor    = topcolor,
                touser      = openId,
                data        = data
            };
            ResError result = WxHttp.Post(WxUrl.TemplateSend.ToFormat(accessToken), pdata);

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }
            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Post(WxUrl.TemplateSend.ToFormat(newAccessToken), pdata);
                if (newResult.errcode == ResCode.请求成功)
                {
                    return(true);
                }
            }
            TxtLogServices.WriteTxtLogEx("WeiXinBase", "发送模板消息错误!错误代码:{0},说明:{1}", (int)result.errcode, result.errmsg);
            return(false);
        }
示例#2
0
        /// <summary>
        /// 发送语音消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="mediaId"></param>
        /// <returns></returns>
        public static bool SendVoice(string companyId, string accessToken, string openId, string mediaId)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "voice",
                voice   = new
                {
                    media_id = mediaId
                }
            };

            ResError result = WxHttp.Post(WxUrl.SendMsg.ToFormat(accessToken), data);

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }
            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Post(WxUrl.SendMsg.ToFormat(newAccessToken), data);
                if (newResult.errcode == ResCode.请求成功)
                {
                    return(true);
                }
            }
            TxtLogServices.WriteTxtLogEx("WeiXinBase", "发送语音消息错误!错误代码:{0},说明:{1}", (int)result.errcode, result.errmsg);
            return(false);
        }
示例#3
0
        /// <summary>
        /// 移动用户分组
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="toGroupId"></param>
        /// <returns></returns>
        public static bool UpdateUserGroup(string companyId, string accessToken, string openId, int toGroupId)
        {
            var data = new
            {
                openid     = openId,
                to_groupid = toGroupId
            };
            ResError result = WxHttp.Post(WxUrl.UpdateUserGroup.ToFormat(accessToken), data);

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }
            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Post(WxUrl.UpdateUserGroup.ToFormat(newAccessToken), data);
                if (newResult.errcode == ResCode.请求成功)
                {
                    return(true);
                }
            }
            TxtLogServices.WriteTxtLogEx("WeiXinBase", "移动用户分组发生错误!错误代码:{0},说明:{1}", (int)result.errcode, result.errmsg);
            return(false);
        }
示例#4
0
        /// <summary>
        /// 删除群发
        /// 请注意,只有已经发送成功的消息才能删除删除消息只是将消息的图文详情页失效,已经收到的用户,还是能在其本地看到消息卡片。
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="msgId">发送出去的消息ID</param>
        /// <returns></returns>
        public static bool SendAllDelete(string companyId, string accessToken, long msgId)
        {
            var data = new
            {
                msgid = msgId
            };

            ResError result = WxHttp.Post(WxUrl.SendAllDelete.ToFormat(accessToken), data);

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }
            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Post(WxUrl.SendAllDelete.ToFormat(newAccessToken), data);
                if (newResult.errcode == ResCode.请求成功)
                {
                    return(true);
                }
            }
            TxtLogServices.WriteTxtLogEx("WeiXinBase", "删除群发发生错误!错误代码:{0},说明:{1}", (int)result.errcode, result.errmsg);
            return(false);
        }
示例#5
0
 /// <summary>
 /// 临停缴费
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public ActionResult ParkCarPayment(decimal orderId)
 {
     try
     {
         OnlineOrder order = CheckOrder(orderId);
         if (order.OrderType != OnlineOrderType.ParkFee)
         {
             throw new MyException("支付方法不正确");
         }
         if (string.IsNullOrWhiteSpace(order.MWebUrl))
         {
             UnifiedPayModel model = GetUnifiedPayModel(order, string.Format("临停缴费-{0}-{1}", order.PKName, order.PlateNo));
         }
         ViewBag.MaxWaitTime = DateTime.Now.AddMinutes(WXOtherConfigServices.GetTempParkingWeiXinPayTimeOut(order.CompanyID)).ToString("yyyy-MM-dd HH:mm:ss");
         ViewBag.MWeb_Url    = order.MWebUrl;
         return(View(order));
     }
     catch (MyException ex) {
         return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/H5ParkingPayment/Index" }));
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("H5WeiXinPayment_Error", string.Format("Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace), LogFrom.WeiXin);
         return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/H5ParkingPayment/Index" }));
     }
 }
示例#6
0
        /// <summary>
        /// 发送音乐消息
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="openId"></param>
        /// <param name="title">音乐标题(非必须)</param>
        /// <param name="description">音乐描述(非必须)</param>
        /// <param name="musicUrl">音乐链接</param>
        /// <param name="hqMusicUrl">高品质音乐链接,wifi环境优先使用该链接播放音乐</param>
        /// <param name="thumbMediaId">视频缩略图的媒体ID</param>
        /// <returns></returns>
        public static bool SendMusic(string companyId, string accessToken, string openId, string title, string description, string musicUrl, string hqMusicUrl, string thumbMediaId)
        {
            var data = new
            {
                touser  = openId,
                msgtype = "music",
                music   = new
                {
                    title          = title,
                    description    = description,
                    musicurl       = musicUrl,
                    hqmusicurl     = hqMusicUrl,
                    thumb_media_id = thumbMediaId
                }
            };
            ResError result = WxHttp.Post(WxUrl.SendMsg.ToFormat(accessToken), data);

            if (result.errcode == ResCode.请求成功)
            {
                return(true);
            }

            if (result.errcode == ResCode.获取accessToken时AppSecret错误或者accessToken无效)
            {
                WX_ApiConfig config         = WXApiConfigServices.QueryWXApiConfig(companyId);
                var          newAccessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, true);
                ResError     newResult      = WxHttp.Post(WxUrl.SendMsg.ToFormat(newAccessToken), data);
                if (newResult.errcode == ResCode.请求成功)
                {
                    return(true);
                }
            }
            TxtLogServices.WriteTxtLogEx("WeiXinBase", "发送音乐消息错误!错误代码:{0},说明:{1}", (int)result.errcode, result.errmsg);
            return(false);
        }
示例#7
0
 public void Process()
 {
     try
     {
         List <BaseParkinfo> parkings = GetParkingBySupportAutoRefund();
         if (parkings.Count > 0)
         {
             List <OnlineOrder> models = OnlineOrderServices.QueryWaitRefund(parkings.Select(p => p.PKID).ToList(), DateTime.Now.Date);
             foreach (var item in models)
             {
                 if (item.SyncResultTimes < 3)
                 {
                     continue;
                 }
                 try
                 {
                     OnlineOrderServices.AutoRefund(item.OrderID, BackgroundWorkerManager.EnvironmentPath);
                 }
                 catch (Exception ex) {
                     TxtLogServices.WriteTxtLogEx("Background", "自动退款失败:orderId:{0},Message:{1},StackTrace:{2}", item.OrderID, ex.Message, ex.StackTrace);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptionToDbAndTxt("Background", "后台工作线程处理退款异常", ex, LogFrom.WeiXin);
     }
 }
示例#8
0
        /// <summary>
        /// 订单自动退款处理
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="certpath"></param>
        /// <returns></returns>
        public static bool AutoRefund(decimal orderId, string certpath)
        {
            TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "方法名:{0},操作类型:{1},订单编号:{2},备注:{3}", "AutoRefund", "订单退款处理", orderId, "开始订单退款处理");

            bool refundResult = false;

            lock (order_lock)
            {
                TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "进入lock,orderId:{0}", orderId);

                try
                {
                    IOnlineOrder factory = OnlineOrderFactory.GetFactory();
                    OnlineOrder  order   = factory.QueryByOrderId(orderId);
                    if (order.Status == OnlineOrderStatus.SyncPayResultFail && order.SyncResultTimes >= 3)
                    {
                        refundResult = Refund(order, certpath);
                    }
                }
                catch (Exception ex) {
                    TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "方法名:{0},操作类型:{1},订单编号:{2},Message:{3},StackTrace:{4}", "AutoRefund", "订单退款处理失败", orderId, ex.Message, ex.StackTrace);
                }
                TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "执行完成lock,orderId:{0}", orderId);
            }

            return(refundResult);
        }
示例#9
0
        string GetPic(string imagepath)
        {
            string imagedata = "";

            if (System.IO.File.Exists(imagepath))
            {
                Stream s = System.IO.File.Open(imagepath, FileMode.Open);
                try
                {
                    byte[] bt = new byte[s.Length];
                    s.Read(bt, 0, (int)s.Length);
                    imagedata = Convert.ToBase64String(bt);
                }
                catch (Exception ex)
                {
                    Common.Services.TxtLogServices.WriteTxtLog("获取图片异常 图片路径:{0} 异常信息:{1}", imagepath, ex.Message);
                }
                finally
                {
                    s.Close();
                }
            }
            else
            {
                TxtLogServices.WriteTxtLog("图片文件路径不存在", imagepath);
            }
            return(imagedata);
        }
示例#10
0
 public JsonResult PublishMenu(string companyId)
 {
     try
     {
         WX_ApiConfig config = WXApiConfigServices.QueryWXApiConfig(companyId);
         if (config == null || string.IsNullOrWhiteSpace(config.AppId) || string.IsNullOrWhiteSpace(config.AppSecret) ||
             string.IsNullOrWhiteSpace(config.SystemName))
         {
             throw new MyException("获取微信基础信息失败,请确认微信基础信息已配置");
         }
         var accessToken = AccessTokenContainer.TryGetToken(config.AppId, config.AppSecret, false);
         var buttonGroup = ToButtonGroup(WXMenuServices.GetMenus(companyId));
         TxtLogServices.WriteTxtLogEx("PublishMenu", JsonHelper.GetJsonString(buttonGroup));
         var result = WxApi.CreateMenu(companyId, accessToken, buttonGroup);
         if (!result)
         {
             throw new MyException("发布菜单失败");
         }
         return(Json(MyResult.Success()));
     }
     catch (MyException ex)
     {
         return(Json(MyResult.Error(ex.Message)));
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "发布菜单失败");
         return(Json(MyResult.Error("发布菜单失败")));
     }
 }
示例#11
0
 public static string DownloadHeadImg(string openId, string url, string companyId)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(url))
         {
             return(url);
         }
         using (var wc = new WebClient())
         {
             var directorypath = "/Uploads/WeiXinHeadImg/" + companyId + "/";
             var realpath      = HttpContext.Current.Server.MapPath(directorypath);
             if (!Directory.Exists(realpath))
             {
                 Directory.CreateDirectory(realpath);
             }
             var filepath = string.Format("{0}{1}.png", directorypath, openId);
             if (File.Exists(filepath))
             {
                 File.Delete(filepath);
             }
             string path = HttpContext.Current.Server.MapPath(filepath);
             wc.DownloadFile(url, path);
             return(filepath);
         }
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("DownloadHeadImg", ex);
         return(string.Empty);
     }
 }
示例#12
0
        /// <summary>
        /// 通知APP端
        /// </summary>
        /// <param name="sOrderID">订单ID</param>
        /// <param name="sAmount">金额</param>
        /// <returns></returns>
        public static int BalanceRechargeNotify(string sOrderID, string sUserName, decimal dAmount)
        {
            string sTime   = "";
            string sAmount = ((int)(dAmount * 100)).ToString();

            //请求时间
            string sTUrl = "http://spsapp.spsing.com/api/Home/GetSysTime";

            string sResult = GetHttpResponse(sTUrl);
            //
            string sCode = GetRegexString("(?<=\"Status\":)[\\d]+(?=,)", sResult, 0);

            sTime = GetRegexString("(?<=\"Result\":)[\\d]+(?=})", sResult, 0);
            //是否正确
            if (sCode != "1")
            {
                TxtLogServices.WriteTxtLogEx("SPSError", "Time Result=" + sResult);
                return(0);
            }

            string t    = sTime + sAmount + sUserName;
            string sUrl = "http://spsapp.spsing.com/api/User/WxNotice?t=" + t;

            string sNotifyResult = GetHttpResponse(sUrl);

            sCode = GetRegexString("(?<=\"Status\":)[\\d]+(?=,)", sNotifyResult, 0);
            //是否正确
            if (sCode != "1")
            {
                TxtLogServices.WriteTxtLogEx("SPSError", "Notify Result=" + sNotifyResult);
                return(0);
            }

            return(1);
        }
示例#13
0
        /// <summary>
        /// <returns></returns>
        /// </summary>
        /// <param name="parkingId">车场编号</param>
        /// <param name="GateID"></param>
        /// <param name="AccountID"></param>
        /// <param name="OrderSource"></param>
        /// <returns></returns>
        public static TempParkingFeeResult WXScanCodeTempParkingFeeByParkGateID(string parkingId, string GateID, string AccountID, OrderSource OrderSource)
        {
            TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("WXScanCodeTempParkingFeeByParkGateID,GateID:{0},AccountID:{1},OrderSource:{2},parkingId:{3}", GateID, AccountID, (int)OrderSource, parkingId));

            if (parkingId == SystemDefaultConfig.SFMPKID)
            {
                string[] sPData = GateID.Split('$');
                if (sPData.Length == 2)
                {
                    return(SFMTempParkingFeeResult(sPData[0], sPData[1]));
                }
                else
                {
                    TempParkingFeeResult r = new TempParkingFeeResult();
                    r.Result = APPResult.OtherException;
                    return(r);
                }
            }
            if (parkingId == SystemDefaultConfig.BWPKID)
            {
                return(BWYTempParkingFeeResult(GateID));
            }
            WXServiceClient client = ServiceUtil <WXServiceClient> .GetServiceClient("WXService");

            string result = client.WXScanCodeTempParkingFeeByGateID(GateID, AccountID, (int)OrderSource);

            client.Close();
            client.Abort();
            return(JsonHelper.GetJson <TempParkingFeeResult>(result));
        }
示例#14
0
 public override void OnAuthorization(AuthorizationContext filterContext)
 {
     try
     {
         var moduleid = filterContext.RequestContext.HttpContext.Request["moduleid"];
         var openid   = filterContext.RequestContext.HttpContext.Request["openId"];
         if (string.IsNullOrWhiteSpace(openid))
         {
             var cookie = filterContext.RequestContext.HttpContext.Request.Cookies["SmartSystem_WeiXinOpenId"];
             if (cookie != null && !string.IsNullOrWhiteSpace(cookie.Value))
             {
                 openid = cookie.Value;
             }
         }
         if (!string.IsNullOrWhiteSpace(moduleid) && !string.IsNullOrWhiteSpace(openid))
         {
             WX_MenuAccessRecord model = new WX_MenuAccessRecord();
             model.OpenID   = openid;
             model.MenuName = ((WeiXinModule)int.Parse(moduleid)).GetDescription();
             WXMenuAccessRecordServices.Create(model);
         }
     }
     catch (Exception ex)
     {
         ExceptionsServices.AddExceptions(ex, "记录页面访问记录失败", LogFrom.WeiXin);
         TxtLogServices.WriteTxtLogEx("PageBrowseRecord", ex);
     }
 }
示例#15
0
        /// <summary>
        /// 车牌获取停车费用
        /// </summary>
        /// <param name="plateNumber">车牌号</param>
        /// <returns></returns>
        public static PlateQueryResult GetCarPrice(string plateNumber)
        {
            try
            {
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("GetCarPrice方法,plateNumber:{0}", plateNumber));

                if (string.IsNullOrWhiteSpace(SFMSecretKey))
                {
                    throw new MyException("获取密钥失败");
                }
                if (string.IsNullOrWhiteSpace(SFMInterfaceUrl))
                {
                    throw new MyException("获取请求地址失败");
                }

                string result = HttpHelper.RequestUrl(string.Format("{0}ApiPlatform/GetCarPrice", SFMInterfaceUrl),
                                                      new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("SecretKey", SFMSecretKey),
                    new KeyValuePair <string, string>("carNo", plateNumber)
                }, HttpMethod.GET);
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("GetCarPrice result:{0}", result));
                return(JsonHelper.GetJson <PlateQueryResult>(result));
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("GetCarPrice方法,异常:{0},StackTrace:{1}", ex.Message, ex.StackTrace));
                return(null);
            }
        }
示例#16
0
        /// <summary>
        /// 手动退款(退款失败是调用)
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="certpath"></param>
        /// <returns></returns>
        public static bool ManualRefund(decimal orderId, string certpath)
        {
            TxtLogServices.WriteTxtLogEx("OnlineOrderServices", "方法名:{0},操作类型:{1},订单编号:{2},备注:{3}", "ManualRefund", "订单退款处理", orderId, "开始订单退款处理");

            bool refundResult = false;

            lock (order_lock)
            {
                try
                {
                    IOnlineOrder factory = OnlineOrderFactory.GetFactory();
                    OnlineOrder  order   = factory.QueryByOrderId(orderId);
                    if (order.Status == OnlineOrderStatus.RefundFail)
                    {
                        refundResult = Refund(order, certpath);
                    }
                    if (refundResult)
                    {
                        OperateLogServices.AddOperateLog(OperateType.Other, string.Format("手动执行退款操作,退款订单号:{0}", orderId));
                    }
                }
                catch (Exception ex)
                {
                    ExceptionsServices.AddExceptionToDbAndTxt("OnlineOrderServices", "手动执行退款操作失败", ex, LogFrom.WeiXin);
                }
            }
            return(refundResult);
        }
示例#17
0
        /// <summary>
        /// 创建支付订单
        /// </summary>
        /// <param name="orderNo">停车订单号码</param>
        /// <returns></returns>
        public static SFMResult CarOrderPay(string orderNo)
        {
            try
            {
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("CarOrderPay方法,orderNo:{0}", orderNo));

                if (string.IsNullOrWhiteSpace(SFMSecretKey))
                {
                    throw new MyException("获取密钥失败");
                }
                string result = HttpHelper.RequestUrl(string.Format("{0}/ApiPlatform/CarOrderPay", SFMInterfaceUrl),
                                                      new List <KeyValuePair <string, string> >
                {
                    new KeyValuePair <string, string>("SecretKey", SFMSecretKey),
                    new KeyValuePair <string, string>("orderNo", orderNo)
                }, HttpMethod.GET);
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("CarOrderPay result:{0}", result));

                return(JsonHelper.GetJson <SFMResult>(result));
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("SFMError", string.Format("CarOrderPay方法,异常:{0},StackTrace:{1}", ex.Message, ex.StackTrace));
                return(null);
            }
        }
示例#18
0
        /// <summary>
        /// 商家充值
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult SellerRechargePayment(decimal orderId)
        {
            try
            {
                OnlineOrder order = CheckOrder(orderId);
                if (order.OrderType != OnlineOrderType.SellerRecharge)
                {
                    throw new MyException("支付方法不正确");
                }

                if (string.IsNullOrWhiteSpace(order.MWebUrl))
                {
                    UnifiedPayModel model = GetUnifiedPayModel(order, string.Format("商家充值-{0}", order.PKName));
                }
                ViewBag.MWeb_Url = order.MWebUrl;
                return(View(order));
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("H5WeiXinPayment_Error", "支付失败 orderId:{0};", orderId, ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/H5Seller/Index" }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("H5WeiXinPayment_Error", string.Format("商家充值支付失败 orderId:{0};", orderId), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/H5Seller/Index" }));
            }
        }
示例#19
0
 private void InitData()
 {
     try
     {
         SystemDefaultConfig.WriteConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
         SystemDefaultConfig.ReadConnectionString  = ConfigurationManager.ConnectionStrings["ReadConnectionString"].ToString();
         SystemDefaultConfig.BWPKID  = ConfigurationManager.AppSettings["BWPKID"] ?? "";
         SystemDefaultConfig.SFMPKID = ConfigurationManager.AppSettings["SFMPKID"] ?? "";
         //Session["SmartSystem_LogFrom"] = LogFrom.UnKnown;
         SystemDefaultConfig.DatabaseProvider = "Sql";
         SystemDefaultConfig.DataUpdateFlag   = 3;
         SystemDefaultConfig.SystemDomain     = ConfigurationManager.AppSettings["SystemDomain"] ?? "";
         SystemDefaultConfig.CreateImageUploadFile();
         SystemDefaultConfig.Secretkey           = ConfigurationManager.AppSettings["Secretkey"] ?? "";
         BackgroundWorkerManager.EnvironmentPath = Server.MapPath("~");
         CompanyServices.InitSystemDefaultCompany();
         string startBackground = ConfigurationManager.AppSettings["BackgroundWorkeStart"] ?? "0";
         if (startBackground == "1")
         {
             BackgroundWorkerManager.Start();
         }
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("Application_Start", ex);
     }
 }
示例#20
0
        /// <summary>
        /// 证书验证的 post请求
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="url">请求Url</param>
        /// <param name="postData">post数据</param>
        /// <param name="certPath">证书路径</param>
        /// <param name="certPwd">证书密码</param>
        /// <returns></returns>
        private static T PostXmlResponse <T>(string url, string postData, string certPath, string certPwd) where T : class, new()
        {
            TxtLogServices.WriteTxtLogEx("WeiXin_Request_Refund", string.Format("postData:{0};", postData));
            HttpWebRequest hp = (HttpWebRequest)WebRequest.Create(url);

            ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
            var cer = new X509Certificate2(certPath, certPwd, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet);

            hp.ClientCertificates.Add(cer);
            var encoding = System.Text.Encoding.UTF8;

            byte[] data = encoding.GetBytes(postData);
            hp.Method        = "POST";
            hp.ContentType   = "application/x-www-form-urlencoded";
            hp.ContentLength = data.Length;
            using (Stream ws = hp.GetRequestStream())
            {
                // 发送数据
                ws.Write(data, 0, data.Length);
                ws.Close();

                using (HttpWebResponse wr = (HttpWebResponse)hp.GetResponse())
                {
                    using (StreamReader sr = new StreamReader(wr.GetResponseStream(), encoding))
                    {
                        return(XmlHelper.Deserialize <T>(sr.ReadToEnd()));
                    }
                }
            }
        }
示例#21
0
        /// <summary>
        /// APP充值
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public ActionResult BalancePayment(decimal orderId)
        {
            try
            {
                OnlineOrder order = CheckOrder(orderId);
                if (order.OrderType != OnlineOrderType.APPRecharge)
                {
                    throw new MyException("支付方法不正确");
                }

                UnifiedPayModel    model    = GetUnifiedPayModel(order, string.Format("{0}-APP充值", order.PlateNo));
                WeiXinPaySignModel payModel = GetWeiXinPaySign(order, model);
                ViewBag.PayModel = payModel;
                return(View(order));
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("WeiXinPayment_Error", "支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId, ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message, returnUrl = "/PurseData/Index" }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPayment_Error", string.Format("APP充值支付失败 orderId:{0};openId:{1}", orderId, WeiXinOpenId), ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "支付失败,请重新支付", returnUrl = "/PurseData/Index" }));
            }
        }
示例#22
0
 /// <summary>
 /// 统一收单交易关闭接口
 /// 用于交易创建后,用户在一定时间内未进行支付,可调用该接口直接将未付款的交易进行关闭。
 /// </summary>
 /// <param name="out_trade_no"></param>
 /// <param name="trade_no"></param>
 /// <param name="operator_id"></param>
 /// <returns></returns>
 public static bool CloseOrder(string companyId, string out_trade_no, string trade_no, string operator_id = "")
 {
     try
     {
         AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
         request.BizContent = "{" +
                              "\"trade_no\":\"" + trade_no + "\"," +
                              "\"out_trade_no\":\"" + out_trade_no + "\"," +
                              "\"operator_id\":\"" + operator_id + "\"" +
                              "}";
         AlipayTradeCloseResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一收单交易关闭接口失败:{0}", response.Body));
             throw new MyException("关闭订单失败");
         }
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一收单交易关闭接口结果:{0}", response.Body));
         return(response.Code == "10000");
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一收单交易关闭接口失败:{0}", ex.Message));
         return(false);
     }
 }
示例#23
0
        public static string MakePreAliPayOrder(string companyId, PreAliPayOrderModel model)
        {
            try
            {
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(companyId);
                if (config == null)
                {
                    throw new MyException("获取支付宝配置失败");
                }

                string aliPayNotifyUrl = string.Format("{0}/AliPayNotify", config.SystemDomain);
                AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
                request.BizContent = JsonHelper.GetJsonString(model);
                request.SetNotifyUrl(aliPayNotifyUrl);
                AlipayTradePrecreateResponse response = GetDefaultAopClient(companyId).Execute(request);
                if (response.IsError)
                {
                    TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("预下单失败:{0}", response.Body));
                    return("");
                }
                return(response.QrCode);
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("预下单失败:{0}", ex.Message));
            }
            return("");
        }
示例#24
0
 /// <summary>
 /// 退款请求
 /// </summary>
 /// <param name="out_trade_no">订单编号</param>
 /// <param name="trade_no">交易单好</param>
 /// <param name="refund_amount">退款金额(元)</param>
 /// <param name="refund_reason">原因</param>
 /// <param name="out_request_no">退款订单号</param>
 /// <returns></returns>
 public static bool RefundRequest(string companyId, string out_trade_no, string trade_no, string refund_amount, string refund_reason, string out_request_no)
 {
     try
     {
         AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
         request.BizContent = "{" +
                              "\"out_trade_no\":\"" + out_trade_no + "\"," +
                              "\"trade_no\":\"" + trade_no + "\"," +
                              "\"refund_amount\":" + refund_amount + "," +
                              "\"refund_reason\":\"" + refund_reason + "\"," +
                              "\"out_request_no\":\"" + out_request_no + "\"" +
                              "}";
         AlipayTradeRefundResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求失败:{0}", response.Body));
             return(false);
         }
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求结果:{0}", response.Body));
         return(response.Code == "10000");
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("退款请求失败:{0}", ex.Message));
         return(false);
     }
 }
示例#25
0
 /// <summary>
 /// 统一收单交易退款查询
 /// </summary>
 /// <param name="trade_no">支付宝订单号</param>
 /// <param name="out_trade_no">平台订单号</param>
 /// <param name="out_request_no">退款申请单号</param>
 /// <returns></returns>
 public static AlipayTradeFastpayRefundQueryResponse QueryRefundOrder(string companyId, string trade_no, string out_trade_no, string out_request_no)
 {
     try
     {
         AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest();
         request.BizContent = "{" +
                              "\"trade_no\":\"" + trade_no + "\"," +
                              "\"out_trade_no\":\"" + out_trade_no + "\"," +
                              "\"out_request_no\":\"" + out_request_no + "\"" +
                              "}";
         AlipayTradeFastpayRefundQueryResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一收单交易退款查询失败:{0}", response.Body));
             throw new MyException("交易退款查询失败");
         }
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("交易退款查询结果:{0}", response.Body));
         return(response);
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("统一收单交易退款查询失败:{0}", ex.Message));
         throw new MyException("交易退款查询失败");
     }
 }
示例#26
0
 public static bool QueryPayResult(string companyId, string out_trade_no, string trade_no, out DateTime payTime)
 {
     payTime = DateTime.Now;
     try
     {
         AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
         request.BizContent = "{" +
                              "\"out_trade_no\":\"" + out_trade_no + "\"," +
                              "\"trade_no\":\"" + trade_no + "\"" +
                              "}";
         AlipayTradeQueryResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("查询支付宝交易状态失败:{0}", response.Body));
             return(false);
         }
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("查询支付状态结果:{0}", response.Body));
         if (response.TradeStatus == "TRADE_SUCCESS" || response.TradeStatus == "TRADE_FINISHED")
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("查询支付状态结果 支付时间:{0}", response.SendPayDate));
             DateTime.TryParse(response.SendPayDate, out payTime);
             return(true);
         }
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("查询支付宝交易状态失败:{0}", ex.Message));
     }
     return(false);
 }
示例#27
0
 public static string LoginAccess(string companyId, string scopes, string state, string returnUrl)
 {
     try
     {
         AlipayUserInfoAuthRequest request = new AlipayUserInfoAuthRequest();
         request.SetReturnUrl(returnUrl);
         request.BizContent = "{" +
                              "\"scopes\":[" +
                              "\"auth_base\"" +
                              "]," +
                              "\"state\":\"init\"," +
                              "\"is_mobile\":\"true\"" +
                              "}";
         AlipayUserInfoAuthResponse response = GetDefaultAopClient(companyId).Execute(request);
         if (response.IsError)
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("LoginAccess()用户登录授权失败" + ":{0}", response.Body));
         }
         else
         {
             TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("LoginAccess()用户登录授权成功" + ":{0}", response.Body));
             return("");
         }
     }
     catch (Exception ex)
     {
         TxtLogServices.WriteTxtLogEx("AliPayApiServices", string.Format("LoginAccess()用户登录授权失败,Message:{0},StackTrace:{1}", ex.Message, ex.StackTrace));
     }
     return("");
 }
示例#28
0
        /// <summary>
        /// 支付通知
        /// </summary>
        /// <param name="amount">金额(分)</param>
        /// <param name="parkingId">车场编号</param>
        /// <param name="orderId">订单编号</param>
        /// <returns></returns>
        public static BWYOrderPaymentResult PayNotice(int amount, string parkingId, string orderId)
        {
            try
            {
                TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("PayNotice方法,BWYInterfaceUrl:{0},BWYSessionID:{1}", BWYInterfaceUrl, BWYSessionID));

                if (string.IsNullOrWhiteSpace(BWYInterfaceUrl) || string.IsNullOrWhiteSpace(BWYSessionID))
                {
                    return(null);
                }

                TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("PayNotice方法,amount:{0},parkingId:{1},orderId:{2}", amount, parkingId, orderId));
                BWYOrderPaymentModel model = new BWYOrderPaymentModel();
                model.FeeOfPayable = amount;
                model.FeeOfPaid    = amount;
                model.CodeType     = 1;
                model.PayState     = 3;

                string content    = JsonHelper.GetJsonString(model);
                string webPageUrl = string.Format("{0}/ParkingCloud/Rest/OpenApi/Bill/{1}/{2}", BWYInterfaceUrl.TrimEnd('/'), parkingId, orderId);
                string strResult  = BWYHttpHelper.RequestUrl(webPageUrl, BWYSessionID, content, "PUT");
                TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("PayNotice方法,strResult:{0}", strResult));
                BWYOrderPaymentResult result = JsonHelper.GetJson <BWYOrderPaymentResult>(strResult);
                TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("PayNotice方法,转换模型:{0}", result == null ? "is null" : "not null"));
                return(result);
            }
            catch (Exception ex)
            {
                TxtLogServices.WriteTxtLogEx("BWYInterfaceProcess", string.Format("PayNotice方法,异常:{0}"), ex.Message);
                return(null);
            }
        }
示例#29
0
        public ActionResult Index()
        {
            //ParkCarDerateServices.QueryBySellerIdAndIORecordId("46f54c5e-ada9-4efe-9552-a8560130a960", "6fe28c13-716a-48d1-b1ba-a8ee00061572");
            //string geng = Server.MapPath("~/TempFile/20180526");
            //string savepath = Server.MapPath("~/TempFile/201805263.zip");
            //ZipHelper.ZipFiles(geng, savepath);

            Stopwatch watch = Stopwatch.StartNew();//创建一个监听器

            for (var i = 0; i <= 100; i++)
            {
                TxtLogServices.WriteTxtLogEx("Test", "开始");
                var user = WeiXinAccountService.QueryWXByOpenId("oussCwE6unIvKaG-1wec-B7n3J0Q");
                //DateTime ts2 = DateTime.Now;
                //TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                TxtLogServices.WriteTxtLogEx("Test", "结束");
                Thread.Sleep(10000);

                //DateTime ts1 = DateTime.Now;

                //var user = WeiXinAccountService.QueryWXByOpenId("oussCwE6unIvKaG-1wec-B7n3J0Q");
                ////DateTime ts2 = DateTime.Now;
                ////TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                //TxtLogServices.WriteTxtLogEx("Test", watch.ElapsedMilliseconds.ToString());
                //Thread.Sleep(10000);
            }
            watch.Stop();

            var    redirectUrl    = "http://park.xinfu.info/r/ParkingPayment_Index_moduleid=2^cid=f50a5dee-d098-4100-a370-a7ca017ab4cf";
            string strRedirectUrl = HttpUtility.UrlEncode(redirectUrl);
            //WXApiConfigServices.QueryWXApiConfig
            //WX_ApiConfig confing = WXApiConfigServices.QueryWXApiConfig("83495fa0-611f-497a-9e10-a78c009f66cd");
            string s = string.Empty;

            //cd1e590c-e91e-45f7-b7d6-a75300e652a9^pn=ÔÁB88765
            //byte[] result = WXQRCodeServices.GenerateByteQRCode("http://ykt.bsgoal.net.cn", "cd1e590c-e91e-45f7-b7d6-a75300e652a9", "粤B88765", 430, "");
            //System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
            //System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

            //string filePath = string.Format("/Uploads/QRCode/{0}.{1}", "test111111111", "jpg");
            //string absolutePath = System.Web.HttpContext.Current.Server.MapPath(filePath);
            //img.Save(absolutePath, ImageFormat.Jpeg);

            //DateTime t1 = DateTime.Now.AddMinutes(-10).AddSeconds(-2);
            //DateTime t2 = DateTime.Now;
            //string s = t1.GetParkingDuration(t2);
            //string s = "1   2 34  5566".PlateNumberToUpper();
            //JsonObject obj = new JsonObject();

            //PlatformOrderBLL.ManualRefund(123123, "");
            //string v = XmlConfig.GetValue("PromptAttentionPage");
            //string openid = "odvkywSnlKr8anm3ddoIcredwvN0";
            //string url = "http://wx.qlogo.cn/mmopen/gKlic31XKbJ7BOJyEvicpgpW0ym5rfqGS0ibBSWLVOlDaSm4QZ1vCqEAxKohVtuj3fEn1vHfia6Y4fXEN9zXhxrhuRmMgoELyBll/0";
            //WeiXinBaseInfo.DownloadHeadImg(openid, url);
            //RoutematrixService.GetRoutematrix("113.977295", "22.731472", "113.687295", "22.761472");
            //List<BaseParkinfo> parks = QueryParkingService.QueryParkinfo("22.735069".ToDouble(), "113.988769".ToDouble(), 4000);
            //WX_ApiConfig config = GetApiConfig("moduleid=2^cid=0642cbb1-d55d-4629-855d-a73c0100397b");
            return(View());
        }
示例#30
0
        public ActionResult Index(string id, string state)
        {
            try
            {
                if (SourceClient != RequestSourceClient.AliPay)
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "请用支付宝页面打开" }));
                }
                ClearQRCodeCookie();
                TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("state:{0}", state));
                if (!string.IsNullOrWhiteSpace(state) && string.IsNullOrWhiteSpace(id))
                {
                    id = state;
                }
                Dictionary <string, string> dicParams = GetRequestParams(id);
                if (!dicParams.ContainsKey("COMPANYID"))
                {
                    throw new MyException("获取单位信息失败");
                }
                AliPayApiConfig config = AliPayApiConfigServices.QueryAliPayConfig(dicParams["COMPANYID"]);
                if (config == null)
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝配置失败" }));
                }
                if (!config.Status)
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "已暂停支付宝支付,稍后再试!" }));
                }
                Session["CurrLoginAliPayApiConfig"] = config;
                if (string.IsNullOrWhiteSpace(Request["auth_code"]))
                {
                    TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("autState:{0}", id));

                    string publicAppAuthorizeUrl = AliPayApiServices.GetPublicAppAuthorizeUrl(id, config);
                    TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("PublicAppAuthorizeUrl:{0}", publicAppAuthorizeUrl));
                    return(Redirect(publicAppAuthorizeUrl));
                }
                string auth_code = Request["auth_code"];
                TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("auth_code:{0}", auth_code));
                string userId         = "";
                string aliAccessToken = AliPayApiServices.GetAccessToken(dicParams["COMPANYID"], auth_code, ref userId);
                if (string.IsNullOrWhiteSpace(aliAccessToken) || string.IsNullOrWhiteSpace(aliAccessToken) || string.IsNullOrWhiteSpace(userId))
                {
                    throw new MyException("获取支付宝用户授权信息失败");
                }
                TxtLogServices.WriteTxtLogEx("AliPayAuthorize", string.Format("userId:{0}", userId));
                Response.Cookies.Add(new HttpCookie("SmartSystem_AliPay_UserId", userId));
                return(Redir(id, userId));
            }
            catch (MyException ex)
            {
                TxtLogServices.WriteTxtLogEx("AliPayAuthorize", ex);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message }));
            }
            catch (Exception ex) {
                TxtLogServices.WriteTxtLogEx("AliPayAuthorize", ex);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取支付宝授权失败" }));
            }
        }