Esempio n. 1
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;
 }
Esempio n. 2
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;
        }
Esempio n. 3
0
 public ActionResult GetActivityCode(int activityId, int customerId)
 {
     AppSettings settings = AppSettings.GetAppSettings();
     ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
     try
     {
         string webroot = settings.WebURL;
         string codePath = activityMgr.GenerateActivityQRCode(User.Identity.GetUserId<int>(), customerId, activityId);
         //string fullCodeUrl = webroot + "/QRCode/" + codePath;
         ViewBag.CodePath = settings.QRFolder+"/" + codePath;
         return Redirect(webroot+ "/"+settings.QRFolder+"/" + codePath);
         //return View();
     }
     catch (KMBitException ex)
     {
         ViewBag.Message = ex.Message;
         return View("Error");
     }
 }
Esempio n. 4
0
        public ActionResult DoSaoMa()
        {
            string p = Request["p"];
            string number = Request["mobile_number"];
            string spName = Request["SPName"];
            string province= Request["Province"];
            string city = Request["City"];

            if (string.IsNullOrEmpty(p))
            {
                ViewBag.Message = "参数错误,请正确扫码,输入手机号码点充值";
            }
            else
            {
                int agentId = 0;
                int customerId = 0;
                int activityId = 0;
                int activityOrderId = 0;
                string parameters = KMEncoder.Decode(p);
                if(!string.IsNullOrEmpty(parameters))
                {
                    string signature = string.Empty;
                    SortedDictionary<string, string> pvs = parseParameters(parameters,out signature);
                    if (string.IsNullOrEmpty(signature))
                    {
                        ViewBag.Message = "URL参数不正确,请重新扫码";
                        return View("SaoMa");
                    }
                    System.Text.StringBuilder pBuilder = new System.Text.StringBuilder();
                    if(pvs.Count>0)
                    {
                        int count = 1;
                        foreach(KeyValuePair<string,string> pair in pvs)
                        {
                            pBuilder.Append(pair.Key);
                            pBuilder.Append("=");
                            pBuilder.Append(pair.Value);
                            if(count<pvs.Count)
                            {
                                pBuilder.Append("&");
                            }
                            count++;
                            switch (pair.Key)
                            {
                                case "agentId":
                                    int.TryParse(pair.Value,out agentId);
                                    break;
                                case "customerId":
                                    int.TryParse(pair.Value, out customerId);
                                    break;
                                case "activityId":
                                    int.TryParse(pair.Value, out activityId);
                                    break;
                                case "activityOrderId":
                                    int.TryParse(pair.Value, out activityOrderId);
                                    break;
                            }
                        }
                        CustomerManagement customerMgr = new CustomerManagement(0);
                        int total;
                        List<BCustomer> customers = customerMgr.FindCustomers(0, customerId, out total);
                        if(total<=0 || total>1)
                        {
                            ViewBag.Message = "URL参数不正确,请重新扫码";
                            return View("SaoMa");
                        }
                        pBuilder.Append("&key=");
                        pBuilder.Append(customers[0].Token);
                        string sign = UrlSignUtil.GetMD5(pBuilder.ToString());
                        if(sign!=signature)
                        {
                            ViewBag.Message = "URL参数不正确,请重新扫码";
                            return View("SaoMa");
                        }
                        ActivityManagement activityMgr = new ActivityManagement(0);
                        BMarketOrderCharge order = new BMarketOrderCharge()
                        {
                            ActivityId = activityId,
                            ActivityOrderId = activityOrderId,
                            AgentId = agentId,
                            CustomerId = customerId,
                            City = city,
                            Province = province,
                            OpenId = "",
                            Phone = number,
                            SPName = spName
                        };
                        KMBit.BL.Charge.ChargeResult result = activityMgr.MarketingCharge(order);
                        ViewBag.Message = result.Message;
                        //if(result.Status == ChargeStatus.FAILED)
                        //{
                        //    ViewBag.Paras = pvs;
                        //    //paras.Add("p", p);
                        //}
                    }
                }else
                {
                    ViewBag.Message = "不能重复扫码,或者修改扫码后的URL地址";
                }
            }

            return View("SaoMa");
        }
Esempio n. 5
0
 public ActionResult ActivityOrders(int activityId, int customerId)
 {
     ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
     try
     {
         List<BActivityOrder> mOrders = activityMgr.FindMarketingOrders(User.Identity.GetUserId<int>(), customerId,activityId,0 ,out total);
         PageItemsResult<BActivityOrder> result = new PageItemsResult<BActivityOrder>() { CurrentPage = 1, EnablePaging = true, Items = mOrders, PageSize = mOrders.Count, TotalRecords = mOrders.Count };
         KMBit.Grids.KMGrid<BActivityOrder> grid = new Grids.KMGrid<BActivityOrder>(result);
         return View(grid);
     }
     catch (KMBitException ex)
     {
         ViewBag.Message = ex.Message;
         return View("Error");
     }
 }
Esempio n. 6
0
        public ActionResult CreateActivityTaocan(ActivityTaocanModel model)
        {
            ActivityManagement activityMgr = null;
            if (ModelState.IsValid)
            {
               
                try
                {
                    activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
                    Marketing_Activity_Taocan taocan = new Marketing_Activity_Taocan() { ActivityId=model.ActivityId, Price=model.Price, Quantity=model.Quantity, RouteId=model.RouteId};
                    activityMgr.CreateActivityTaocan(taocan);
                    return Redirect("/Agent/CustomerAcivities?customerId="+model.CustomerId);
                }
                catch (KMBitException ex)
                {
                    ViewBag.Message = ex.Message;
                }

                finally { }
            }

            List<BAgentRoute> routes = activityMgr.FindAvailableAgentRoutes(User.Identity.GetUserId<int>(), model.CustomerId, model.ActivityId);
            ViewBag.Routes = new SelectList((from r in routes select new { Id = r.Route.Id, Name = r.Taocan.Taocan2.Name + " - 代理价格" + (r.Taocan.Taocan.Sale_price*r.Route.Discount).ToString("0.00") + "元" }), "Id", "Name");
            return View(model);
        }
Esempio n. 7
0
 public ActionResult ActivityTaocans(int activityId, int customerId)
 {
     ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
     try
     {
         List<BActivityTaocan> taocans = activityMgr.FindActivityTaocans(activityId, customerId, User.Identity.GetUserId<int>());
         PageItemsResult<BActivityTaocan> result = new PageItemsResult<BActivityTaocan>() { CurrentPage=1, EnablePaging=true, Items=taocans, PageSize=taocans.Count, TotalRecords=taocans.Count };
         KMBit.Grids.KMGrid<BActivityTaocan> grid = new Grids.KMGrid<BActivityTaocan>(result);
         return View(grid);
     }catch(KMBitException ex)
     {
         ViewBag.Message = ex.Message;
         return View("Error");
     }
 }
Esempio n. 8
0
        public ActionResult CreateActivityTaocan(int activityId,int customerId)
        {
            ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
            List<BActivity> activities = activityMgr.FindActivities(activityId, User.Identity.GetUserId<int>(), 0, out total);
            if(activities==null || activities.Count==0)
            {
                ViewBag.Message = string.Format("编号为{0}的活动不是你的客户的活动",activityId);
                return View("Error");
            }

            List<BAgentRoute> routes = activityMgr.FindAvailableAgentRoutes(User.Identity.GetUserId<int>(),customerId, activityId);
            ViewBag.Routes = new SelectList((from r in routes select new { Id = r.Route.Id, Name = r.Taocan.Taocan2.Name + " - 代理价格" + (r.Taocan.Taocan.Sale_price*r.Route.Discount).ToString("0.00") + "元" }), "Id", "Name");
            ActivityTaocanModel model = new ActivityTaocanModel() { ActivityId= activityId,CustomerId= customerId };
            return View(model);
        }
Esempio n. 9
0
        public ActionResult EditCustomerActivity(int activityId, int customerId)
        {
            ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
            List<BActivity> activities = activityMgr.FindActivities(activityId, User.Identity.GetUserId<int>(), customerId, out total, true, 1, 1);
            CustomerActivityModel model = new CustomerActivityModel();
            if (activities.Count == 1)
            {                
                BActivity activity = activities[0];
                model.Id = activity.Activity.Id;
                model.CustomerId = customerId;
                model.Description = activity.Activity.Description;
                model.Enable = activity.Activity.Enabled;
                model.ExpiredTime = activity.Activity.ExpiredTime > 0 ? DateTimeUtil.ConvertToDateTime(activity.Activity.ExpiredTime).ToString("yyyy-M-dd") : "";
                model.Name = activity.Activity.Name;
                model.ScanType = activity.Activity.ScanType;
                model.StartTime = activity.Activity.ExpiredTime > 0 ? DateTimeUtil.ConvertToDateTime(activity.Activity.StartedTime).ToString("yyyy-M-dd") : "";
            }
            else
            {
                ViewBag.Message = "不能修改不属于自己客户的活动";
                return View("Error");
            }

            List<DictionaryTemplate> scanTypes = StaticDictionary.GetScanTypeList();
            ViewBag.ScanTypes = new SelectList(from st in scanTypes select new { Id = st.Id, Name = st.Value }, "Id", "Name");
            return View("CreateCustomerActivity",model);
        }
Esempio n. 10
0
        public ActionResult CreateCustomerActivity(CustomerActivityModel model)
        {            
            if(ModelState.IsValid)
            {
                ActivityManagement activityMgr = new ActivityManagement(User.Identity.GetUserId<int>());
                Marketing_Activities activity = new Marketing_Activities()
                {
                    AgentId = User.Identity.GetUserId<int>(),
                    CreatedTime = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now),
                    CustomerId = model.CustomerId,
                    Description = model.Description,
                    ScanType = model.ScanType,
                    Enabled = model.Enable,
                    Name = model.Name,
                    Id=model.Id
                };

                if (model.Id==0)
                {                   
                    activity = activityMgr.CreateNewActivity(activity);
                    if (activity.Id > 0)
                    {
                        return Redirect("/Agent/CustomerAcivities?customerId=" + model.CustomerId);
                    }
                }else
                {
                    activityMgr.UpdateActivity(activity);
                    return Redirect("/Agent/CustomerAcivities?customerId=" + model.CustomerId);
                } 
            }
            List<DictionaryTemplate> scanTypes = StaticDictionary.GetScanTypeList();
            ViewBag.ScanTypes = new SelectList(from st in scanTypes select new { Id = st.Id, Name = st.Value }, "Id", "Name");
            return View(model);
        }       
Esempio n. 11
0
 public ActionResult CustomerAcivities(int customerId)
 {
     CustomerManagement customerMgr = new CustomerManagement(User.Identity.GetUserId<int>());
     List<BCustomer> customers = customerMgr.FindCustomers(User.Identity.GetUserId<int>(), customerId, out total);
     if(customers.Count==0)
     {
         ViewBag.Message = string.Format("编号为:{0}的客户不是你的客户", customerId);
         return View("Error");
     }
     BCustomer customer = customers[0];
     ActivityManagement activityMgr = new ActivityManagement(customerMgr.CurrentLoginUser);
     int page = 1;
     int pageSize = 20;
     int.TryParse(Request["page"], out page);
     page = page > 0 ? page : 1;
     List<BActivity> activities = activityMgr.FindActivities(0,User.Identity.GetUserId<int>(), customerId, out total, true, page, pageSize);
     PageItemsResult<BActivity> result = new PageItemsResult<BActivity>() { CurrentPage = page, EnablePaging = true, Items = activities, PageSize = pageSize, TotalRecords = total };
     KMBit.Grids.KMGrid<BActivity> grid = new Grids.KMGrid<BActivity>(result);
     ViewBag.Customer = customer;
     return View("CustomerAcivities",grid);
 }