예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string text    = this.txtTitle.Text.Trim();
            string text2   = this.txtSubtitle.Text.Trim();
            string text3   = this.txtURL.Text.Trim();
            string text4   = this.txtRemark.Text.Trim();
            string text5   = string.Empty;
            string empty   = string.Empty;
            string iconUrl = string.Empty;

            if (!string.IsNullOrEmpty(this.hidUploadLogo.Value))
            {
                text5 = this.hidUploadLogo.Value.Replace("//", "/");
            }
            if (string.IsNullOrEmpty(text) || text.Length > 100)
            {
                this.ShowMsg("主标题不能为空,长度必须小于或等于100个字符", false);
            }
            else if (string.IsNullOrEmpty(text2) || text2.Length > 100)
            {
                this.ShowMsg("副标题不能为空,长度必须小于或等于100个字符", false);
            }
            else if (string.IsNullOrEmpty(text3) || text3.Length > 300)
            {
                this.ShowMsg("跳转URL不能为空,长度必须小于或等于300个字符", false);
            }
            else if (string.IsNullOrEmpty(text4) || text4.Length > 100)
            {
                this.ShowMsg("备注不能为空,长度必须小于或等于100个字符", false);
            }
            else if (string.IsNullOrEmpty(text5))
            {
                this.ShowMsg("请上传缩略图", false);
            }
            else
            {
                System.Drawing.Image image = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath(this.hidUploadLogo.Value));
                if (!image.Width.Equals(image.Height) || image.Height == 0 || image.Width == 0)
                {
                    this.ShowMsg("图片大小建议120px*120 px,限制不超过200 px *200 px,图片需为正方形。", false);
                }
                else
                {
                    image.Dispose();
                    empty = Globals.SaveFile("images", text5, "/Storage/master/store/", true, true, "");
                    UploadImageResultJson uploadImageResultJson = WXStoreHelper.UploadImageToWXShakeAShake(empty);
                    if (uploadImageResultJson.errcode.Equals(ReturnCode.请求成功))
                    {
                        iconUrl = uploadImageResultJson.data.pic_url;
                    }
                    AddPageResultJson addPageResultJson = WXStoreHelper.AddPage(text, text2, text3, iconUrl, text4);
                    if (addPageResultJson.errcode == ReturnCode.请求成功)
                    {
                        base.Response.Redirect("IbeaconPageList.aspx");
                    }
                }
            }
        }
예제 #2
0
        public string UploadImage(string filePath)
        {
            UploadImageResultJson uploadImageResultJson = Senparc.Weixin.MP.AdvancedAPIs.PoiApi.UploadImage(_accessToken, filePath, 10000);

            if (uploadImageResultJson.errcode != ReturnCode.请求成功)
            {
                throw new Exception(uploadImageResultJson.errmsg);
            }
            return(uploadImageResultJson.url);
        }
예제 #3
0
        public string UploadImage(string file)
        {
            UploadImageResultJson uploadImageResultJson = ShakeAroundApi.UploadImage(_accessToken, file, 10000);

            if (uploadImageResultJson.errcode != ReturnCode.请求成功)
            {
                throw new Exception(uploadImageResultJson.errmsg);
            }
            return(uploadImageResultJson.data.pic_url);
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[ZhouBianInfo]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //JObject pp = (JObject)p;
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.Pic.IsNullOrEmpty())//未上传头象
            {
                DataObj.OutError("2041");
                return;
            }
            if (baseUsers.NeekName.IsNullOrEmpty())
            {
                baseUsers.NeekName = baseUsers.TrueName;
                Entity.SaveChanges();
            }

            string wxtoken = GetToken();

            YYDevice YYDevice = Entity.YYDevice.FirstOrDefault(n => n.UId == baseUsers.Id && n.State == 2);//已绑定页面

            if (YYDevice == null)
            {
                //获取设备
                YYDevice = Entity.YYDevice.FirstOrDefault(n => n.UId == 0 && n.State == 1);//未绑定
                if (YYDevice == null)
                {
                    //没有可用的设备
                    YYDevice = GetYYDevice(wxtoken);
                }
                if (YYDevice != null)
                {
                    YYDevice.UId   = baseUsers.Id;
                    YYDevice.State = 2;
                    Entity.SaveChanges();
                }
            }
            if (YYDevice.PageId.IsNullOrEmpty())
            {
                //未绑定页面
                YYPage YYPage = Entity.YYPage.FirstOrDefault(n => n.UId == baseUsers.Id && n.State == 1);
                if (YYPage == null)
                {
                    //生成页面
                    string title       = GetNeekName(baseUsers.NeekName);//从商户名称中获取6位
                    string description = "点击去付款";
                    string URL         = string.Format(SysPath + "/mobile/shop/index-{0}.html", baseUsers.Id, baseUsers.UserName);
                    //string Icon = Utils.ImageUrl("UsersPic", baseUsers.Pic);
                    string Icon                = Utils.ImageUrl("UsersPic", baseUsers.Pic, 120, 120, "Cut");
                    string IconPath            = HttpContext.Current.Server.MapPath(Icon);
                    UploadImageResultJson Img  = WXAPI.UploadImage(wxtoken, IconPath);
                    string            wxpicurl = Img.data.pic_url;
                    AddPageResultJson Page     = WXAPI.AddPage(wxtoken, title, description, URL, wxpicurl);
                    if (Page.errcode == ReturnCode.请求成功)
                    {
                        YYPage          = new YYPage();
                        YYPage.Title    = title;
                        YYPage.UId      = baseUsers.Id;
                        YYPage.SubTitle = description;
                        YYPage.Url      = URL;
                        YYPage.Icon     = Icon;
                        YYPage.WXIcon   = wxpicurl;
                        YYPage.AddTime  = DateTime.Now;
                        YYPage.State    = 1;
                        YYPage.PageId   = Page.data.page_id.ToString();
                        Entity.YYPage.AddObject(YYPage);
                        Entity.SaveChanges();
                    }
                }
                //绑定页面
                long         DevId  = long.Parse(YYDevice.DevId);
                long         PageId = long.Parse(YYPage.PageId);
                WxJsonResult WJR    = WXAPI.BindPage(wxtoken, DevId, PageId);
                if (WJR.errcode == ReturnCode.请求成功)
                {
                    YYDevice.PageId       = YYPage.PageId;
                    baseUsers.YYOpenState = 1;//标识用户已经开通
                    Entity.SaveChanges();
                }
            }

            YYDaily YYDaily = Entity.YYDaily.Where(n => n.UId == baseUsers.Id && n.DevId == YYDevice.DevId && n.OutDate < DateTime.Now).OrderByDescending(n => n.OutDate).FirstOrDefault();

            if (YYDaily == null)
            {
                YYDevice.ClickPV = 0;
                YYDevice.ClickUV = 0;
                YYDevice.ShakePV = 0;
                YYDevice.ShakeUV = 0;
            }
            else
            {
                YYDevice.ClickPV = YYDaily.ClickPV;
                YYDevice.ClickUV = YYDaily.ClickUV;
                YYDevice.ShakePV = YYDaily.ShakePV;
                YYDevice.ShakeUV = YYDaily.ShakeUV;
            }
            DataObj.Data = YYDevice.OutJson();
            DataObj.Code = "0000";
            DataObj.OutString();
        }
        public void Post()
        {
            string Data = DataObj.GetData();

            if (Data.IsNullOrEmpty())
            {
                DataObj.OutError("1000");
                return;
            }
            JObject json = new JObject();

            try
            {
                json = (JObject)JsonConvert.DeserializeObject(Data);
            }
            catch (Exception Ex)
            {
                Log.Write("[ZhouBianUpdate]:", "【Data】" + Data, Ex);
            }
            if (json == null)
            {
                DataObj.OutError("1000");
                return;
            }
            //JObject pp = (JObject)p;
            Users Users = new Users();

            Users = JsonToObject.ConvertJsonToModel(Users, json);
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.Token == Users.Token);

            if (baseUsers == null)//用户令牌不存在
            {
                DataObj.OutError("2004");
                return;
            }
            if (baseUsers.State != 1)//用户被锁定
            {
                DataObj.OutError("2003");
                return;
            }
            if (baseUsers.CardStae != 2)//未实名认证
            {
                DataObj.OutError("2006");
                return;
            }
            if (baseUsers.Pic.IsNullOrEmpty())//未上传头象
            {
                DataObj.OutError("2041");
                return;
            }

            string wxtoken = GetToken();

            YYDevice YYDevice = Entity.YYDevice.FirstOrDefault(n => n.UId == baseUsers.Id && n.State == 2);//已绑定页面
            YYPage   YYPage   = Entity.YYPage.FirstOrDefault(n => n.UId == baseUsers.Id && n.State == 1);

            string title       = GetNeekName(baseUsers.NeekName);//从商户名称中获取6位
            string description = "点击去付款";
            string URL         = string.Format(SysPath + "/mobile/shop/index-{0}.html", baseUsers.Id, baseUsers.UserName);
            string Icon        = Utils.ImageUrl("UsersPic", baseUsers.Pic, 120, 120, "Cut");

            if (Icon != YYPage.Icon || title != YYPage.Title)
            {
                string wxpicurl = YYPage.WXIcon;
                if (Icon != YYPage.Icon)//修改了头象则需要重新上传头象
                {
                    string IconPath           = HttpContext.Current.Server.MapPath(Icon);
                    UploadImageResultJson Img = WXAPI.UploadImage(wxtoken, IconPath);
                    wxpicurl = Img.data.pic_url;
                    long page_id = Int64.Parse(YYPage.PageId);
                    UpdatePageResultJson Page = WXAPI.EditPage(wxtoken, page_id, title, description, URL, wxpicurl);
                    if (Page.errcode == ReturnCode.请求成功)
                    {
                        YYPage.Title  = title;
                        YYPage.Icon   = Icon;
                        YYPage.WXIcon = wxpicurl;
                        Entity.SaveChanges();
                    }
                }
            }
            DataObj.Data = "";
            DataObj.Code = "0000";
            DataObj.OutString();
        }