Example #1
0
        public ApiMessage Chongba()
        {
            ApiMessage message = new ApiMessage()
            {
                Status = "OK", Message = "成功执行回调函数"
            };

            try
            {
                this.IniRequest();
                ICharge chargeMgr = new ChongBaCharge();
                List <WebRequestParameters> paramters = new List <WebRequestParameters>();
                paramters.Add(new WebRequestParameters("orderId", request["orderId"], false));
                paramters.Add(new WebRequestParameters("respCode", request["respCode"], false));
                paramters.Add(new WebRequestParameters("respMsg", request["respMsg"], false));
                paramters.Add(new WebRequestParameters("transNo", request["transNo"], false));
                chargeMgr.CallBack(paramters);
            }
            catch (KMBitException e)
            {
                message.Status  = "ERROE";
                message.Message = e.Message;
            }
            catch (Exception ex)
            {
                message.Status  = "ERROE";
                message.Message = ex.Message;
            }

            return(message);
        }
Example #2
0
        public ApiMessage ChargeBack()
        {
            ApiMessage message = new ApiMessage();

            try
            {
                this.IniRequest();
                SortedDictionary <string, string> sArray = GetRequestParameters();
                ChargeBridge bridge = new ChargeBridge();
                ChargeResult result = bridge.ChargeCallBack(sArray);
                message.Message = result.Message;
                message.Status  = "OK";
                if (result.Status != ChargeStatus.SUCCEED)
                {
                    message.Status = "ERROR";
                }
            }
            catch (KMBitException kex)
            {
                message.Status  = "ERROR";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status  = "ERROR";
                message.Message = "未知错误";
            }

            return(message);
        }
Example #3
0
 public ApiMessage SearchDirectChargeTaocans()
 {
     this.IniRequest();
     ApiMessage message = new ApiMessage();
     BaseManagement baseMgt = new BaseManagement(0);
     if (request["scope"] == null || (request["scope"].ToLower() != "global" && request["scope"].ToLower() != "local"))
     {
         message.Status = "ERROR";
         message.Message = "scope must be global or local and in lower case.";
         return message;
     }
     if (request["sp"] == null || string.IsNullOrEmpty(request["sp"]))
     {
         message.Status = "ERROR";
         message.Message = "Unknow mobile phone sp name";
         return message;
     }
     if (request["province"] == null || string.IsNullOrEmpty(request["province"]))
     {
         message.Status = "ERROR";
         message.Message = "Unknow mobile phone province name";
         return message;
     }
     BitScope scope = BitScope.Global;
     if (request["scope"].Trim().ToLower() == "local")
     {
         scope = BitScope.Local;
     }
     List<BResourceTaocan> tcs = baseMgt.SearchResourceTaocans(request["sp"],request["province"], scope);
     message.Status = "OK";
     message.Item = tcs;
     return message;
 }
Example #4
0
        public ApiMessage ChargeBack()
        {
            ApiMessage message = new ApiMessage();
            try
            {
                this.IniRequest();
                SortedDictionary<string, string> sArray = GetRequestParameters();
                ChargeBridge bridge = new ChargeBridge();
                ChargeResult result = bridge.ChargeCallBack(sArray);
                message.Message = result.Message;
                message.Status = "OK";
                if (result.Status!=  ChargeStatus.SUCCEED)
                {
                    message.Status = "ERROR";
                }
            }
            catch (KMBitException kex)
            {
                message.Status = "ERROR";
                message.Message = kex.Message;
            }
            catch (Exception ex)
            {
                message.Status = "ERROR";
                message.Message = "未知错误";
            }

            return message;
        }
Example #5
0
        public ApiMessage Chongba()
        {
            ApiMessage message = new ApiMessage() { Status = "OK", Message = "成功执行回调函数" };
            try
            {
                this.IniRequest();
                ICharge chargeMgr = new ChongBaCharge();
                List<WebRequestParameters> paramters = new List<WebRequestParameters>();
                paramters.Add(new WebRequestParameters("orderId", request["orderId"], false));
                paramters.Add(new WebRequestParameters("respCode", request["respCode"], false));
                paramters.Add(new WebRequestParameters("respMsg", request["respMsg"], false));
                paramters.Add(new WebRequestParameters("transNo", request["transNo"], false));
                chargeMgr.CallBack(paramters);
            }
            catch(KMBitException e)
            {
                message.Status = "ERROE";
                message.Message = e.Message;
            }
            catch (Exception ex)
            {
                message.Status = "ERROE";
                message.Message = ex.Message;
            }

            return message;
        }
Example #6
0
        public ApiMessage GetAgencyResourceTaocans()
        {
            this.IniRequest();
            ApiMessage           message     = new ApiMessage();
            AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name);
            int agencyId   = 0;
            int resourceId = 0;

            int.TryParse(request["agencyId"], out agencyId);
            int.TryParse(request["resourceId"], out resourceId);
            if (agencyId == 0 && resourceId == 0)
            {
                message.Status  = "ERROR";
                message.Item    = null;
                message.Message = "代理商编号和资源编号都不能为空";
                return(message);
            }
            List <BResourceTaocan> taocans = new List <BResourceTaocan>();

            if (resourceId > 0 && agencyId > 0)
            {
                taocans = agentMgtMgr.FindAgencyResourceTaocans(agencyId, resourceId);
            }
            else if (resourceId > 0 && agencyId <= 0)
            {
                ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser);
                taocans = resourceMgr.FindResourceTaocans(resourceId, 0, false);
            }

            message.Status = "OK";
            message.Item   = taocans;
            return(message);
        }
Example #7
0
        public ApiMessage GetResourceTaocans()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage()
            {
                Status = "ERROR", Message = "获取资源套餐数据失败", Item = null
            };

            try
            {
                int resourceId = 0;
                if (this.request["resourceId"] != null)
                {
                    int.TryParse(this.request["resourceId"], out resourceId);
                }

                if (resourceId > 0)
                {
                    KMBit.BL.Admin.ResourceManagement resourceMgt = new BL.Admin.ResourceManagement(User.Identity.Name);
                    int total = 0;
                    List <BResourceTaocan> taocans = resourceMgt.FindResourceTaocans(0, resourceId, 0, out total);
                    message.Status  = "OK";
                    message.Message = "成功获取用户类型数据,请使用JSON Item节点数据";
                    message.Item    = (from t in taocans select new { Id = t.Taocan.Id, Name = t.SP.Name + " " + t.Province.Name + " " + t.Taocan.Quantity + "M" });
                }
                else
                {
                    message.Message = "资源编号必须是大于零的整数";
                }
            }
            catch
            { }

            return(message);
        }
Example #8
0
        public ApiMessage GetAgencyResources()
        {
            this.IniRequest();
            ApiMessage           message     = new ApiMessage();
            AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name);
            int agencyId = 0;

            int.TryParse(request["agencyId"], out agencyId);
            if (agencyId > 0)
            {
                List <BResource> rs = agentMgtMgr.FindAgentResources(agencyId);
                message.Status = "OK";
                message.Item   = rs;
            }
            else
            {
                ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser);
                int total           = 0;
                List <BResource> rs = resourceMgr.FindResources(0, null, 0, out total);
                message.Status = "OK";
                message.Item   = rs;
            }

            return(message);
        }
Example #9
0
        public ApiMessage GetResourceTaocans()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage() { Status = "ERROR", Message = "获取资源套餐数据失败", Item = null };
            try
            {
                int resourceId = 0;
                if (this.request["resourceId"] != null)
                {
                    int.TryParse(this.request["resourceId"], out resourceId);
                }

                if (resourceId > 0)
                {
                    KMBit.BL.Admin.ResourceManagement resourceMgt = new BL.Admin.ResourceManagement(User.Identity.Name);
                    int total = 0;
                    List<BResourceTaocan> taocans = resourceMgt.FindResourceTaocans(0, resourceId, 0, out total);
                    message.Status = "OK";
                    message.Message = "成功获取用户类型数据,请使用JSON Item节点数据";
                    message.Item = (from t in taocans select new { Id = t.Taocan.Id, Name = t.SP.Name + " " + t.Province.Name + " " + t.Taocan.Quantity + "M" });
                }
                else
                {
                    message.Message = "资源编号必须是大于零的整数";
                }

            }
            catch
            { }

            return message;
        }
Example #10
0
        public ApiMessage SearchDirectChargeTaocans()
        {
            this.IniRequest();
            ApiMessage             message = new ApiMessage();
            BaseManagement         baseMgt = new BaseManagement(0);
            List <BResourceTaocan> tcs     = baseMgt.SearchResourceTaocans(request["sp"], request["province"]);

            message.Status = "OK";
            message.Item   = tcs;
            return(message);
        }
Example #11
0
        public ApiMessage SearchDirectChargeTaocans()
        {
            this.IniRequest();
            ApiMessage         message = new ApiMessage();
            AgentManagement    baseMgt = new AgentManagement(User.Identity.Name);
            List <BAgentRoute> tcs     = baseMgt.FindTaocans(0, request["sp"], request["province"], true);

            message.Status = "OK";
            message.Item   = tcs;
            return(message);
        }
Example #12
0
        public ApiMessage GetPayTypes()
        {
            ApiMessage message = new ApiMessage() { Status = "ERROR", Message = "获取支付方式数据失败", Item = null };
            try
            {
                BaseManagement baseMgt = new BL.BaseManagement(User.Identity.Name);
                List<DAL.PayType> sps = baseMgt.GetPayTypes();
                message.Status = "OK";
                message.Message = "成功获取支付方式数据,请使用JSON Item节点数据";
                message.Item = sps;
            }
            catch
            { }

            return message;
        }
Example #13
0
        public ApiMessage GetAreas()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage() { Status="ERROR", Message="",Item=null};
            try
            {
                BaseManagement baseMgt = new BL.BaseManagement(User.Identity.Name);
                int parentId = 0;
                int.TryParse(this.request["parentId"], out parentId);
                List<Area> areas = baseMgt.GetAreas(parentId);
                message.Status = "OK";
                message.Message = "成功获取地区数据,请使用JSON Item节点数据";
                message.Item = areas;
            }catch
            { }

            return message;
        }
Example #14
0
        public ApiMessage GetPayTypes()
        {
            ApiMessage message = new ApiMessage()
            {
                Status = "ERROR", Message = "获取支付方式数据失败", Item = null
            };

            try
            {
                BaseManagement     baseMgt = new BL.BaseManagement(User.Identity.Name);
                List <DAL.PayType> sps     = baseMgt.GetPayTypes();
                message.Status  = "OK";
                message.Message = "成功获取支付方式数据,请使用JSON Item节点数据";
                message.Item    = sps;
            }
            catch
            { }

            return(message);
        }
Example #15
0
        public ApiMessage GetSPs()
        {
            ApiMessage message = new ApiMessage()
            {
                Status = "ERROR", Message = "", Item = null
            };

            try
            {
                BaseManagement baseMgt = new BL.BaseManagement(User.Identity.Name);
                List <Sp>      sps     = baseMgt.GetSps();
                message.Status  = "OK";
                message.Message = "成功获取运营商类型数据,请使用JSON Item节点数据";
                message.Item    = sps;
            }
            catch
            { }

            return(message);
        }
Example #16
0
        public ApiMessage GetCodeIndirect()
        {
            ApiMessage message = new ApiMessage();

            try
            {
                this.IniRequest();
                ActivityManagement activityMgr = new ActivityManagement(0);
                string             spName      = string.Empty;
                string             openId      = string.Empty;
                int agentId    = 0;
                int customerId = 0;
                int activityId = 0;
                spName = request["sp"];
                string url = activityMgr.GetOneRandomMarketOrderQrCodeUrl(spName, openId, agentId, customerId, activityId);
            }catch (KMBitException kex)
            {
                message.Message = kex.Message;
                message.Status  = "ERROR";
            }
            return(message);
        }
Example #17
0
 public ApiMessage GetAgentReports()
 {
     this.IniRequest();
     DateTime sDate = DateTime.MinValue;
     DateTime eDate = DateTime.MinValue;
     if (!string.IsNullOrEmpty(request["startTime"]))
     {
         DateTime.TryParse(request["startTime"], out sDate);
     }
     if (!string.IsNullOrEmpty(request["endTime"]))
     {
         DateTime.TryParse(request["endTime"], out eDate);
     }
     long sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
     long eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
     ApiMessage message = new ApiMessage();
     OrderManagement orderMgt = new OrderManagement(User.Identity.Name);
     List<ReportTemplate> reportList = orderMgt.SearchAgentReport(0, sintDate, eintDate);
     message.Status = "OK";
     message.Item = reportList;
     return message;
 }
Example #18
0
        public ApiMessage GetAreas()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage()
            {
                Status = "ERROR", Message = "", Item = null
            };

            try
            {
                BaseManagement baseMgt  = new BL.BaseManagement(User.Identity.Name);
                int            parentId = 0;
                int.TryParse(this.request["parentId"], out parentId);
                List <Area> areas = baseMgt.GetAreas(parentId);
                message.Status  = "OK";
                message.Message = "成功获取地区数据,请使用JSON Item节点数据";
                message.Item    = areas;
            }catch
            { }

            return(message);
        }
Example #19
0
        public ApiMessage GetEnabledResourceTaocansForAgent()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage()
            {
                Status = "ERROR", Message = "获取资源套餐数据失败", Item = null
            };

            try
            {
                int agencyId   = 0;
                int resourceId = 0;
                if (this.request["resourceId"] != null)
                {
                    int.TryParse(this.request["resourceId"], out resourceId);
                }
                if (this.request["agencyId"] != null)
                {
                    int.TryParse(this.request["agencyId"], out agencyId);
                }

                if (resourceId > 0)
                {
                    KMBit.BL.Admin.ResourceManagement resourceMgt = new BL.Admin.ResourceManagement(User.Identity.Name);
                    List <BResourceTaocan>            taocans     = resourceMgt.FindEnabledResourceTaocansForAgent(resourceId, agencyId);
                    message.Status  = "OK";
                    message.Message = "成功获取用户类型数据,请使用JSON Item节点数据";
                    message.Item    = taocans;
                }
                else
                {
                    message.Message = "资源编号必须是大于零的整数";
                }
            }
            catch
            { }

            return(message);
        }
Example #20
0
        public ApiMessage SearchDirectChargeTaocans()
        {
            this.IniRequest();
            ApiMessage      message = new ApiMessage();
            AgentManagement baseMgt = new AgentManagement(User.Identity.Name);

            if (request["scope"] == null || (request["scope"].ToLower() != "global" && request["scope"].ToLower() != "local"))
            {
                message.Status  = "ERROR";
                message.Message = "scope must be global or local and in lower case.";
                return(message);
            }
            if (request["sp"] == null || string.IsNullOrEmpty(request["sp"]))
            {
                message.Status  = "ERROR";
                message.Message = "Unknow mobile phone sp name";
                return(message);
            }
            if (request["province"] == null || string.IsNullOrEmpty(request["province"]))
            {
                message.Status  = "ERROR";
                message.Message = "Unknow mobile phone province name";
                return(message);
            }
            BitScope scope = BitScope.Global;

            if (request["scope"].Trim().ToLower() == "local")
            {
                scope = BitScope.Local;
            }
            List <BAgentRoute> tcs = baseMgt.FindTaocans(0, request["sp"], request["province"], scope, true);

            message.Status = "OK";
            message.Item   = tcs;
            return(message);
        }
Example #21
0
        public ApiMessage GetEnabledResourceTaocansForAgent()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage() { Status = "ERROR", Message = "获取资源套餐数据失败", Item = null };
            try
            {
                int agencyId = 0;
                int resourceId = 0;
                if (this.request["resourceId"] != null)
                {
                    int.TryParse(this.request["resourceId"], out resourceId);
                }
                if (this.request["agencyId"] != null)
                {
                    int.TryParse(this.request["agencyId"], out agencyId);
                }

                if (resourceId > 0)
                {
                    KMBit.BL.Admin.ResourceManagement resourceMgt = new BL.Admin.ResourceManagement(User.Identity.Name);
                    List<BResourceTaocan> taocans = resourceMgt.FindEnabledResourceTaocansForAgent(resourceId, agencyId);
                    message.Status = "OK";
                    message.Message = "成功获取用户类型数据,请使用JSON Item节点数据";
                    message.Item = taocans;
                }
                else
                {
                    message.Message = "资源编号必须是大于零的整数";
                }

            }
            catch
            { }

            return message;
        }
Example #22
0
        public ApiMessage GetAgentReports()
        {
            this.IniRequest();
            DateTime sDate = DateTime.MinValue;
            DateTime eDate = DateTime.MinValue;

            if (!string.IsNullOrEmpty(request["startTime"]))
            {
                DateTime.TryParse(request["startTime"], out sDate);
            }
            if (!string.IsNullOrEmpty(request["endTime"]))
            {
                DateTime.TryParse(request["endTime"], out eDate);
            }
            long                  sintDate   = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
            long                  eintDate   = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
            ApiMessage            message    = new ApiMessage();
            OrderManagement       orderMgt   = new OrderManagement(User.Identity.Name);
            List <ReportTemplate> reportList = orderMgt.SearchAgentReport(0, sintDate, eintDate);

            message.Status = "OK";
            message.Item   = reportList;
            return(message);
        }
Example #23
0
        public ApiMessage GetSPs()
        {
            ApiMessage message = new ApiMessage() { Status = "ERROR", Message = "", Item = null };
            try
            {
                BaseManagement baseMgt = new BL.BaseManagement(User.Identity.Name);
                List<Sp> sps = baseMgt.GetSps();
                message.Status = "OK";
                message.Message = "成功获取运营商类型数据,请使用JSON Item节点数据";
                message.Item = sps;
            }
            catch
            { }

            return message;
        }
Example #24
0
        public HttpResponseMessage GetCodeDirect()
        {
            this.IniRequest();
            var        resp       = new HttpResponseMessage(HttpStatusCode.OK);
            ApiMessage message    = new ApiMessage();
            string     openId     = string.Empty;
            string     openPublic = string.Empty;
            string     spName     = string.Empty;
            string     signature  = request["signature"];
            string     once       = request["nonce"];
            string     timestamp  = request["timestamp"];
            string     echostr    = request["echostr"];

            if (string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(once) || string.IsNullOrEmpty(timestamp))
            {
                logger.Info("The request was not sent from weixin");
                resp.Content = new StringContent("false", System.Text.Encoding.UTF8, "text/plain");
                return(resp);
            }
            logger.Info(string.Format("signature:{0},nonce:{1},timestamp:{2},echostr:{3}", signature, once, timestamp, echostr));
            SortedSet <string> paras = new SortedSet <string>();

            paras.Add(weixinToken);
            paras.Add(once);
            paras.Add(timestamp);
            string strKey = "";

            logger.Info(string.Format("signature posted by weixin is {0}", signature));
            foreach (string v in paras)
            {
                strKey += v;
            }
            string sign = KMEncoder.SHA1_Hash(strKey);

            logger.Info(string.Format("signature calculated in platform is {0}", sign));
            if (signature != sign)
            {
                logger.Info("two signatures are different, The request was not sent from weixin");
                resp.Content = new StringContent("false", System.Text.Encoding.UTF8, "text/plain");
                return(resp);
            }
            //For weixin URL verification
            if (!string.IsNullOrEmpty(echostr))
            {
                resp.Content = new StringContent(echostr, System.Text.Encoding.UTF8, "text/plain");
                return(resp);
            }
            try
            {
                ActivityManagement activityMgr = new ActivityManagement(0);
                int agentId    = 0;
                int customerId = 0;
                int activityId = 0;
                int.TryParse(request["agentId"], out agentId);
                int.TryParse(request["customerId"], out customerId);
                int.TryParse(request["activityId"], out activityId);
                System.IO.Stream sream  = context.Request.InputStream;
                StreamReader     sr     = new StreamReader(sream);
                string           strXML = sr.ReadToEnd();
                sream.Close();
                //strXML = "<xml><ToUserName><![CDATA[gh_3f1c1268428a]]></ToUserName><FromUserName><![CDATA[oNEHRsogX4seVvYK5v3S-veFUkEk]]></FromUserName><CreateTime>1446455044</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[+联通]]></Content><MsgId>6212477109514836427</MsgId></xml>";
                logger.Info(string.Format("Message pushed by Weichat server:{0}", strXML));
                WeiChatReceivedContentMessage weiChatMessage = WeiChatMessageUtil.ParseWeichatXML(strXML, logger);
                if (weiChatMessage != null)
                {
                    if (weiChatMessage.Content != null)
                    {
                        spName = weiChatMessage.Content.Trim();
                    }
                    if (weiChatMessage.FromUserName != null)
                    {
                        openId = weiChatMessage.FromUserName;
                    }
                    if (weiChatMessage.ToUserName != null)
                    {
                        openPublic = weiChatMessage.ToUserName;
                    }
                }
                if (string.IsNullOrEmpty(spName))
                {
                    resp.Content = new StringContent("success", System.Text.Encoding.UTF8, "text/plain");
                    return(resp);
                }
                if (!spName.Contains("+联通") && !spName.Contains("+移动") && !spName.Contains("+电信"))
                {
                    resp.Content = new StringContent("success", System.Text.Encoding.UTF8, "text/plain");
                    return(resp);
                }
                string url = activityMgr.GetOneRandomMarketOrderQrCodeUrl(spName, openId, agentId, customerId, activityId);
                message.Item    = url;
                message.Status  = "OK";
                message.Message = "成功获取到二维码";
                logger.Info(url);
            }
            catch (KMBitException kex)
            {
                logger.Warn(kex);
                message.Message = kex.Message;
                message.Status  = "ERROR";
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                message.Message = "未知错误";
                message.Status  = "ERROR";
            }

            logger.Info(string.Format("GetOneRandomMarketOrderQrCodeUrl Status:{0}, Message:{1}", message.Status, message.Message));
            string returnXml = "";

            if (message.Status == "OK")
            {
                logger.Info("二维码获取成功,准备推送二维码到微信");
                WeiChatNewsMessage news = new WeiChatNewsMessage();
                news.ToUserName   = openId;
                news.FromUserName = openPublic;
                news.MsgType      = "news";
                List <WeiChatArticle> articles = new List <WeiChatArticle>();
                news.Articles = articles;
                WeiChatArticle article = new WeiChatArticle()
                {
                    Description = "",
                    Title       = "将二维码保存到相册,微信->发现->扫一扫->相册,选择刚刚保存的二维码",
                    PicUrl      = message.Item.ToString(),
                    Url         = message.Item.ToString()
                };
                articles.Add(article);
                returnXml = WeiChatMessageUtil.PrepareWeiChatNewsXml(news);
            }
            else
            {
                logger.Info("二维码获取失败");
                WeiChatContentMessage msg = new WeiChatContentMessage()
                {
                    Content      = message.Message,
                    CreateTime   = 0,
                    FromUserName = openPublic,
                    MsgType      = "text",
                    ToUserName   = openId
                };
                returnXml = WeiChatMessageUtil.PrepareWeiChatXml(msg);
            }
            //logger.Info(returnXml);
            resp.Content = new StringContent(returnXml, System.Text.Encoding.UTF8, "text/plain");
            return(resp);
        }
Example #25
0
        public ApiMessage GetPaySign()
        {
            ApiMessage message = new ApiMessage();

            return(message);
        }
Example #26
0
        public ApiMessage GetAgencyResources()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage();
            AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name);
            int agencyId = 0;
            int.TryParse(request["agencyId"],out agencyId);
            if(agencyId>0)
            {
                List<BResource> rs = agentMgtMgr.FindAgentResources(agencyId);
                message.Status = "OK";
                message.Item = rs;
            }else
            {
                ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser);
                int total = 0;
                List<BResource> rs = resourceMgr.FindResources(0, null, 0, out total);
                message.Status = "OK";
                message.Item = rs;
            }

            return message;
        }
Example #27
0
        public ApiMessage GetPaySign()
        {
            ApiMessage message = new ApiMessage();

            return message;
        }
Example #28
0
        public JsonResult PreCharge(WeChatChargeModel model)
        {
            logger.Info("WeChatController.PreCharge......................................................");
            ApiMessage message = new ApiMessage();
            ChargeOrder order = null;
            if (ModelState.IsValid)
            {
                try
                {
                    if (string.IsNullOrEmpty(model.OpenId))
                    {
                        message.Status = "ERROR";
                        message.Message = "请从公众号菜单打开此页面";
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }
                    //ChargeBridge cb = new ChargeBridge();
                    order = new ChargeOrder()
                    {
                        ChargeType = 0,
                        AgencyId = 0,
                        Id = 0,
                        Province = model.Province,
                        City = model.City,
                        MobileSP = model.SPName,
                        MobileNumber = model.Mobile,
                        OutOrderId = "",
                        ResourceId = 0,
                        ResourceTaocanId = model.ResourceTaocanId,
                        RouteId = 0,
                        CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                        Payed = false,
                        OpenId = model.OpenId,
                        OpenAccountType = 1
                    };
                    //
                    OrderManagement orderMgt = new OrderManagement();
                    ResourceManagement resourceMgr = new ResourceManagement(0);

                    string msg = string.Empty;
                    if (orderMgt.IsThisMonthCharged(order.MobileNumber, order.ResourceTaocanId, out msg))
                    {
                        message.Status = "ERROR";
                        message.Message = msg;
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }

                    order = orderMgt.GenerateOrder(order);
                    int total = 0;
                    List<BResourceTaocan> taocans = resourceMgr.FindResourceTaocans(order.ResourceTaocanId, 0, 0, out total);
                    if (taocans == null || taocans.Count == 0)
                    {
                        message.Message = "当前套餐不可用";
                        message.Status = "ERROR";
                        return Json(message, JsonRequestBehavior.AllowGet);
                    }
                    logger.Info(string.Format("Order is generated, Id - {0}, mobile - {1}", order.Id, order.MobileNumber));
                    BResourceTaocan taocan = taocans[0];
                    message.Status = "OK";
                    message.Message = "预充值订单已经生成";
                    message.Item = null;
                    //
                    string ip = Request.ServerVariables["REMOTE_ADDR"];
                    if (ip != null && ip.IndexOf("::") > -1)
                    {
                        ip = "127.0.0.1";
                    }
                    string prepayId = WeChatPaymentWrapper.GetPrepayId(PersistentValueManager.config, Session["wechat_openid"] != null ? Session["wechat_openid"].ToString() : "", order.PaymentId.ToString(), "TEST WECHATPAY", ip, (int)taocan.Taocan.Sale_price * 100, TradeType.JSAPI);
                    logger.Info(string.Format("Prepay Id - {0}", prepayId));
                    WeChatOrder weOrder = new WeChatOrder();
                    weOrder.Order = new ChargeOrder { Id = order.Id, Payed = order.Payed, PaymentId = order.PaymentId, MobileNumber = order.MobileNumber, MobileSP = order.MobileSP, Province = order.Province };
                    weOrder.PrepayId = prepayId;
                    weOrder.PaySign = "";
                    message.Item = weOrder;

                    AccessToken token = PersistentValueManager.GetWeChatAccessToken();
                    JSAPITicket ticket = PersistentValueManager.GetWeChatJsApiTicket();
                    SortedDictionary<string, string> parameters = new SortedDictionary<string, string>();
                    parameters.Add("appId", PersistentValueManager.config.APPID);
                    parameters.Add("timeStamp", model.timestamp);
                    parameters.Add("nonceStr", model.nancestr);
                    parameters.Add("package", "prepay_id=" + prepayId);
                    parameters.Add("signType", "MD5");

                    logger.Info(string.Format("timeStamp:{0}", model.timestamp));
                    logger.Info(string.Format("nonceStr:{0}", model.nancestr));
                    logger.Info(string.Format("package:{0}", "prepay_id=" + prepayId));

                    string querystr = null;
                    foreach (KeyValuePair<string, string> para in parameters)
                    {
                        if (querystr == null)
                        {
                            querystr = para.Key + "=" + para.Value;
                        }
                        else
                        {
                            querystr += "&" + para.Key + "=" + para.Value;
                        }
                    }
                    querystr += "&key=" + PersistentValueManager.config.ShopSecret;
                    logger.Info(querystr);
                    string sign = UrlSignUtil.GetMD5(querystr);
                    model.paySign = sign.ToUpper();
                    model.prepay_id = prepayId;
                    logger.Info(string.Format("paySign:{0}", sign.ToUpper()));
                    message.Item = model;
                }
                catch (KMBitException kex)
                {
                    logger.Error(kex);
                    message.Message = kex.Message;
                    message.Status = "ERROR";
                }
                catch (Exception ex)
                {
                    message.Message = "未知错误,请联系我们";
                    message.Status = "ERROR";
                    logger.Fatal(ex);
                }
                finally
                {

                }
            }

            logger.Info("Done.");
            return Json(message, JsonRequestBehavior.AllowGet);
        }
Example #29
0
        public ApiMessage GetAgencyResourceTaocans()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage();
            AgentAdminMenagement agentMgtMgr = new AgentAdminMenagement(User.Identity.Name);
            int agencyId = 0;
            int resourceId = 0;
            int.TryParse(request["agencyId"], out agencyId);
            int.TryParse(request["resourceId"], out resourceId);
            if(agencyId==0 && resourceId==0)
            {
                message.Status = "ERROR";
                message.Item = null;
                message.Message = "代理商编号和资源编号都不能为空";
                return message;
            }
            List<BResourceTaocan> taocans = new List<BResourceTaocan>();
            if(resourceId>0 && agencyId>0)
            {
                taocans = agentMgtMgr.FindAgencyResourceTaocans(agencyId, resourceId);
            }else if(resourceId>0 && agencyId<=0)
            {
                ResourceManagement resourceMgr = new ResourceManagement(agentMgtMgr.CurrentLoginUser);
                taocans = resourceMgr.FindResourceTaocans(resourceId, 0, false);
            }

            message.Status = "OK";
            message.Item = taocans;
            return message;
        }
Example #30
0
        public ApiMessage ExportOrders()
        {
            this.IniRequest();
            ApiMessage message = new ApiMessage();
            int orderId = 0;
            int agencyId = 0;
            int resourceId = 0;
            int resourceTaocanId = 0;
            int status = 0;
            string mobileNumber = null;
            DateTime sDate = DateTime.MinValue;
            DateTime eDate = DateTime.MinValue;
            if (request["OrderId"]!=null)
            {
                int.TryParse(request["OrderId"].ToString(),out orderId);
            }
            if (request["AgencyId"] != null)
            {
                int.TryParse(request["AgencyId"].ToString(), out agencyId);
            }
            if(request["Status"]!=null)
            {
                int.TryParse(request["Status"],out status);
            }
            if (request["ResourceId"] != null)
            {
                int.TryParse(request["ResourceId"].ToString(), out resourceId);
            }
            if (request["ResourceTaocanId"] != null)
            {
                int.TryParse(request["ResourceTaocanId"].ToString(), out resourceTaocanId);
            }
            mobileNumber = request["MobileNumber"];
            if (!string.IsNullOrEmpty(request["StartTime"]))
            {
                DateTime.TryParse(request["StartTime"], out sDate);
            }
            if (!string.IsNullOrEmpty(request["EndTime"]))
            {
                DateTime.TryParse(request["EndTime"], out eDate);
            }
            int total = 0;
            long sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
            long eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
            OrderManagement orderMgr = new OrderManagement(User.Identity.Name);
            List<BOrder> orders = orderMgr.FindOrders(orderId,
                                                      agencyId,
                                                      resourceId,
                                                      resourceTaocanId,
                                                      0,
                                                      null, mobileNumber,
                                                      new int[] { status},
                                                      sintDate,
                                                      eintDate,
                                                      out total,
                                                      0,
                                                      0, false);

            message.Status = "OK";

            string path = request.PhysicalApplicationPath;
            string fileName = orderMgr.CurrentLoginUser.User.Id +"_"+ DateTime.Now.ToString("yyyyMMddHHmm")+".csv";
            string fullPath = System.IO.Path.Combine(path+"\\Temp",fileName);
            FileStream fs = null;
            StreamWriter sw = null;
            try
            {
                fs = new FileStream(fullPath, FileMode.Create);
                sw = new StreamWriter(fs,Encoding.UTF8);
                sw.WriteLine("编号,资源,代理商,手机号,省份,城市,平台成本价,平台售价,代理商代理价,代理商售价,时间,状态");
                foreach (BOrder order in orders)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(order.Id.ToString() + ",");
                    builder.Append(order.ReseouceName + ",");
                    builder.Append((order.AgentName != null ? order.AgentName.ToString() : "") + ",");
                    builder.Append(order.MobilePhone + ",");
                    builder.Append((order.MobileProvince != null ? order.MobileProvince : "") + ",");
                    builder.Append((order.MobileCity != null ? order.MobileCity : "") + ",");
                    builder.Append(order.PlatformCostPrice.ToString("0.00") + ",");
                    builder.Append(order.PlatformSalePrice.ToString("0.00") + ",");
                    builder.Append(order.PurchasePrice.ToString("0.00") + ",");
                    builder.Append(order.SalePrice.ToString("0.00") + ",");
                    builder.Append(DateTimeUtil.ConvertToDateTime(order.CreatedTime).ToString("yyyy-MM-dd HH:mm") + ",");
                    builder.Append(order.StatusText != null ? order.StatusText : "");
                    sw.WriteLine(builder.ToString());
                }
            }
            catch(Exception ex)
            {
                logger.Fatal(ex);
            }
            finally
            {
                if(sw!=null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            message.Item = "http://"+request.Url.Authority+"/Temp/"+ fileName;
            return message;
        }
Example #31
0
        public ApiMessage Info()
        {
            ApiMessage message = new ApiMessage();
            base.IniRequest();
            string siganture = string.Empty;
            string accessToken = string.Empty;
            string queryStr = string.Empty;
            base.ParseSigantures(out siganture, out accessToken, out queryStr);
            if(string.IsNullOrEmpty(siganture))
            {
                message.Status = "FAILED";
                message.Message = "签名不能为空";
                return message;
            }
            if (string.IsNullOrEmpty(accessToken))
            {
                message.Status = "FAILED";
                message.Message = "AccessToken不能为空";
                return message;
            }
            if(string.IsNullOrEmpty(queryStr))
            {
                message.Status = "FAILED";
                message.Message = "参数列表不正确";
                return message;
            }
            ApiAccessManagement accessMgt = new ApiAccessManagement();
            BUser user = accessMgt.GetUserByAccesstoken(accessToken);
            if(user==null)
            {
                message.Status = "FAILED";
                message.Message = "AccessToken不正确";
                return message;
            }

            bool verifySign = accessMgt.VerifyApiSignature(user.User.SecurityStamp, queryStr, siganture);
            if (!verifySign)
            {
                message.Status = "FAILED";
                message.Message = "签名不正确";
                return message;
            }
            message.Status = "SUCCEED";
            message.Message = "操作成功";
            user.User.PasswordHash = "";
            user.User.SecurityStamp = "";
            user.User.AccessToken = "";
            message.Item = user.User;
            return message;
        }
Example #32
0
        public HttpResponseMessage GetCodeDirect()
        {
            this.IniRequest();
            var resp = new HttpResponseMessage(HttpStatusCode.OK);
            ApiMessage message = new ApiMessage();
            string openId = string.Empty;
            string openPublic = string.Empty;
            string spName = string.Empty;
            string signature = request["signature"];
            string once= request["nonce"];
            string timestamp = request["timestamp"];
            string echostr = request["echostr"];
            if (string.IsNullOrEmpty(signature) || string.IsNullOrEmpty(once) || string.IsNullOrEmpty(timestamp))
            {
                logger.Info("The request was not sent from weixin");
                resp.Content = new StringContent("false", System.Text.Encoding.UTF8, "text/plain");
                return resp;
            }
            logger.Info(string.Format("signature:{0},nonce:{1},timestamp:{2},echostr:{3}",signature,once,timestamp,echostr));
            SortedSet<string> paras = new SortedSet<string>();
            paras.Add(weixinToken);
            paras.Add(once);
            paras.Add(timestamp);
            string strKey = "";
            logger.Info(string.Format("signature posted by weixin is {0}", signature));
            foreach (string v in paras)
            {
                strKey += v;
            }
            string sign = KMEncoder.SHA1_Hash(strKey);
            logger.Info(string.Format("signature calculated in platform is {0}",sign));
            if(signature!=sign)
            {
                logger.Info("two signatures are different, The request was not sent from weixin");
                resp.Content = new StringContent("false", System.Text.Encoding.UTF8, "text/plain");
                return resp;
            }
            //For weixin URL verification
            if(!string.IsNullOrEmpty(echostr))
            {
                resp.Content = new StringContent(echostr, System.Text.Encoding.UTF8, "text/plain");
                return resp;
            }
            try
            {
                ActivityManagement activityMgr = new ActivityManagement(0);
                int agentId = 0;
                int customerId = 0;
                int activityId = 0;
                int.TryParse(request["agentId"], out agentId);
                int.TryParse(request["customerId"], out customerId);
                int.TryParse(request["activityId"], out activityId);
                System.IO.Stream sream = context.Request.InputStream;
                StreamReader sr = new StreamReader(sream);
                string strXML = sr.ReadToEnd();
                sream.Close();
                //strXML = "<xml><ToUserName><![CDATA[gh_3f1c1268428a]]></ToUserName><FromUserName><![CDATA[oNEHRsogX4seVvYK5v3S-veFUkEk]]></FromUserName><CreateTime>1446455044</CreateTime><MsgType><![CDATA[text]]></MsgType><Content><![CDATA[+联通]]></Content><MsgId>6212477109514836427</MsgId></xml>";
                logger.Info(string.Format("Message pushed by Weichat server:{0}", strXML));
                WeiChatReceivedContentMessage weiChatMessage = WeiChatMessageUtil.ParseWeichatXML(strXML,logger);
                if (weiChatMessage != null)
                {
                    if(weiChatMessage.Content!= null)
                    {
                        spName = weiChatMessage.Content.Trim();
                    }
                    if(weiChatMessage.FromUserName!=null)
                    {
                        openId = weiChatMessage.FromUserName;
                    }
                    if(weiChatMessage.ToUserName!=null)
                    {
                        openPublic = weiChatMessage.ToUserName;
                    }
                }
                if(string.IsNullOrEmpty(spName))
                {
                    resp.Content = new StringContent("success", System.Text.Encoding.UTF8, "text/plain");
                    return resp;
                }
                if (!spName.Contains("+联通") && !spName.Contains("+移动") && !spName.Contains("+电信"))
                {
                    resp.Content = new StringContent("success", System.Text.Encoding.UTF8, "text/plain");
                    return resp;
                }
                string url = activityMgr.GetOneRandomMarketOrderQrCodeUrl(spName, openId, agentId, customerId, activityId);
                message.Item = url;
                message.Status = "OK";
                message.Message = "成功获取到二维码";
                logger.Info(url);
            }
            catch (KMBitException kex)
            {
                logger.Warn(kex);
                message.Message = kex.Message;
                message.Status = "ERROR";
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                message.Message = "未知错误";
                message.Status = "ERROR";
            }

            logger.Info(string.Format("GetOneRandomMarketOrderQrCodeUrl Status:{0}, Message:{1}",message.Status,message.Message));
            string returnXml = "";
            if (message.Status == "OK")
            {
                logger.Info("二维码获取成功,准备推送二维码到微信");
                WeiChatNewsMessage news = new WeiChatNewsMessage();
                news.ToUserName = openId;
                news.FromUserName = openPublic;
                news.MsgType = "news";
                List<WeiChatArticle> articles = new List<WeiChatArticle>();
                news.Articles = articles;
                WeiChatArticle article = new WeiChatArticle()
                {
                    Description = "",
                    Title = "将二维码保存到相册,微信->发现->扫一扫->相册,选择刚刚保存的二维码",
                    PicUrl = message.Item.ToString(),
                    Url = message.Item.ToString()
                };
                articles.Add(article);
                returnXml = WeiChatMessageUtil.PrepareWeiChatNewsXml(news);
            }
            else
            {
                logger.Info("二维码获取失败");
                WeiChatContentMessage msg = new WeiChatContentMessage()
                {
                    Content = message.Message,
                    CreateTime = 0,
                    FromUserName = openPublic,
                    MsgType = "text",
                    ToUserName = openId
                };
                returnXml = WeiChatMessageUtil.PrepareWeiChatXml(msg);
            }
            //logger.Info(returnXml);
            resp.Content = new StringContent(returnXml, System.Text.Encoding.UTF8, "text/plain");
            return resp;
        }
Example #33
0
        public ApiMessage Products()
        {
            ApiMessage message = new ApiMessage();
            base.IniRequest();
            string siganture = string.Empty;
            string accessToken = string.Empty;
            string queryStr = string.Empty;
            base.ParseSigantures(out siganture, out accessToken, out queryStr);
            if (string.IsNullOrEmpty(siganture))
            {
                message.Status = "FAILED";
                message.Message = "签名不能为空";
                return message;
            }
            if (string.IsNullOrEmpty(accessToken))
            {
                message.Status = "FAILED";
                message.Message = "AccessToken不能为空";
                return message;
            }
            if (string.IsNullOrEmpty(queryStr))
            {
                message.Status = "FAILED";
                message.Message = "参数列表不正确";
                return message;
            }

            ApiAccessManagement accessMgt = new ApiAccessManagement();
            BUser user = accessMgt.GetUserByAccesstoken(accessToken);
            if (user == null)
            {
                message.Status = "FAILED";
                message.Message = "AccessToken不正确";
                return message;
            }

            bool verifySign = accessMgt.VerifyApiSignature(user.User.SecurityStamp, queryStr, siganture);
            if (!verifySign)
            {
                message.Status = "FAILED";
                message.Message = "签名不正确";
                return message;
            }

            ProductManagement pdtManager = new ProductManagement();
            List<Beans.API.AgentProduct> products = pdtManager.GetAgentProducts(user.User.Id);
            message.Status = "SUCCEED";
            message.Message = "操作成功";
            message.Item = products;
            return message;
        }
Example #34
0
        public ApiMessage Push()
        {
            ApiMessage message = new ApiMessage();

            return message;
        }
Example #35
0
 public ApiMessage GetCodeIndirect()
 {
     ApiMessage message = new ApiMessage();
     try
     {
         this.IniRequest();
         ActivityManagement activityMgr = new ActivityManagement(0);
         string spName = string.Empty;
         string openId = string.Empty;
         int agentId = 0;
         int customerId = 0;
         int activityId = 0;
         spName = request["sp"];
         string url = activityMgr.GetOneRandomMarketOrderQrCodeUrl(spName, openId, agentId, customerId, activityId);
     }catch(KMBitException kex)
     {
         message.Message = kex.Message;
         message.Status = "ERROR";
     }
     return message;
 }
Example #36
0
        public ApiMessage ExportOrders()
        {
            this.IniRequest();
            ApiMessage message          = new ApiMessage();
            int        orderId          = 0;
            int        agencyId         = 0;
            int        resourceId       = 0;
            int        resourceTaocanId = 0;
            int        status           = 0;
            string     mobileNumber     = null;
            DateTime   sDate            = DateTime.MinValue;
            DateTime   eDate            = DateTime.MinValue;

            if (request["OrderId"] != null)
            {
                int.TryParse(request["OrderId"].ToString(), out orderId);
            }
            if (request["AgencyId"] != null)
            {
                int.TryParse(request["AgencyId"].ToString(), out agencyId);
            }
            if (request["Status"] != null)
            {
                int.TryParse(request["Status"], out status);
            }
            if (request["ResourceId"] != null)
            {
                int.TryParse(request["ResourceId"].ToString(), out resourceId);
            }
            if (request["ResourceTaocanId"] != null)
            {
                int.TryParse(request["ResourceTaocanId"].ToString(), out resourceTaocanId);
            }
            mobileNumber = request["MobileNumber"];
            if (!string.IsNullOrEmpty(request["StartTime"]))
            {
                DateTime.TryParse(request["StartTime"], out sDate);
            }
            if (!string.IsNullOrEmpty(request["EndTime"]))
            {
                DateTime.TryParse(request["EndTime"], out eDate);
            }
            int             total    = 0;
            long            sintDate = sDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(sDate) : 0;
            long            eintDate = eDate != DateTime.MinValue ? DateTimeUtil.ConvertDateTimeToInt(eDate) : 0;
            OrderManagement orderMgr = new OrderManagement(User.Identity.Name);
            List <BOrder>   orders   = orderMgr.FindOrders(orderId,
                                                           agencyId,
                                                           resourceId,
                                                           resourceTaocanId,
                                                           0,
                                                           null, mobileNumber,
                                                           new int[] { status },
                                                           sintDate,
                                                           eintDate,
                                                           out total,
                                                           0,
                                                           0, false);

            message.Status = "OK";

            string       path     = request.PhysicalApplicationPath;
            string       fileName = orderMgr.CurrentLoginUser.User.Id + "_" + DateTime.Now.ToString("yyyyMMddHHmm") + ".csv";
            string       fullPath = System.IO.Path.Combine(path + "\\Temp", fileName);
            FileStream   fs       = null;
            StreamWriter sw       = null;

            try
            {
                fs = new FileStream(fullPath, FileMode.Create);
                sw = new StreamWriter(fs, Encoding.UTF8);
                sw.WriteLine("编号,资源,代理商,手机号,省份,城市,平台成本价,平台售价,代理商代理价,代理商售价,时间,状态");
                foreach (BOrder order in orders)
                {
                    StringBuilder builder = new StringBuilder();
                    builder.Append(order.Id.ToString() + ",");
                    builder.Append(order.ReseouceName + ",");
                    builder.Append((order.AgentName != null ? order.AgentName.ToString() : "") + ",");
                    builder.Append(order.MobilePhone + ",");
                    builder.Append((order.MobileProvince != null ? order.MobileProvince : "") + ",");
                    builder.Append((order.MobileCity != null ? order.MobileCity : "") + ",");
                    builder.Append(order.PlatformCostPrice.ToString("0.00") + ",");
                    builder.Append(order.PlatformSalePrice.ToString("0.00") + ",");
                    builder.Append(order.PurchasePrice.ToString("0.00") + ",");
                    builder.Append(order.SalePrice.ToString("0.00") + ",");
                    builder.Append(DateTimeUtil.ConvertToDateTime(order.CreatedTime).ToString("yyyy-MM-dd HH:mm") + ",");
                    builder.Append(order.StatusText != null ? order.StatusText : "");
                    sw.WriteLine(builder.ToString());
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex);
            }
            finally
            {
                if (sw != null)
                {
                    sw.Close();
                }
                if (fs != null)
                {
                    fs.Close();
                }
            }
            message.Item = "http://" + request.Url.Authority + "/Temp/" + fileName;
            return(message);
        }