Exemple #1
0
        /// <summary>
        /// 分享信息
        /// </summary>
        /// <param name="userData">用户消息</param>
        /// <returns>返回信息</returns>
        private Hashtable[] funcShare(Hashtable userData)
        {
            string userMsg = userData["@body"].ToString().Replace(":", ":");
            string tag = userMsg.Split(':')[0];
            string body = userMsg.Substring(tag.Length + 1);
            Information.group myGroup = new Information.group();
            if (body.Length > 2)
            {
                myGroup.topicNewByWeixin(tag, body.Substring(0, (body.Length > 25 ? 25 : body.Length)), -1, getWeiUserId(userData["@FromUserName"].ToString()), body);
            }
            User.Functions myFunction = new User.Functions();

            if (tag == "秘密")
            {
                myFunction.userPointChange(getWeiUserId(userData["@FromUserName"].ToString()), -3, "发秘密消耗积分", 1);
            }
            else if (tag == "无标签")
            {

            }
            else
            {
                myFunction.givePostPoint(getWeiUserId(userData["@FromUserName"].ToString()), "发帖积分", 1);
            }

            if (HttpContext.Current.Cache["weixinRobotGroupPostKeywords"] != null)
            {
                Hashtable[] keyWords = (Hashtable[])HttpContext.Current.Cache["weixinRobotGroupPostKeywords"];
                bool hasThisTag = false;
                foreach (Hashtable keyWord in keyWords)
                {
                    if (keyWord["tag"].ToString().IndexOf(tag) > -1)
                    {
                        hasThisTag = true;
                    }
                }
                if (!hasThisTag)
                {
                    HttpContext.Current.Cache.Remove("weixinRobotGroupPostKeywords");
                }
            }
            return getRequestItem(userData);
        }
Exemple #2
0
        private Hashtable[] getImageRequestItems(Hashtable userData)
        {
            Hashtable[] rt = new Hashtable[1];
            rt[0] = new Hashtable();
            rt[0]["id"] = 0;
            rt[0]["messageType"] = 1;
            rt[0]["title"] = "图片上传失败";
            rt[0]["body"] = "啊噢,图片上传失败了。。。\n" +
                "失败的具体原因是:";
            rt[0]["picSmall"] = getPicUrl(false);
            rt[0]["picBig"] = getPicUrl(true);
            rt[0]["url"] = "http://www.ai0932.com/mobile/robot-group-kewWordsShow.aspx?type=group&tag=-1";
            rt[0]["orders"] = 0;
            WebClient wc = new WebClient();
            HttpWebResponse res;
            string folderPath=System.DateTime.Now.Year + "/" + System.DateTime.Now.Month + "/" + System.DateTime.Now.Day + "/";
            string savePath = HttpContext.Current.Server.MapPath("~/upload/userImages/" + folderPath);
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }
            res = (HttpWebResponse)WebRequest.Create(userData["@PicUrl"].ToString()).GetResponse();
            if (res.StatusCode != HttpStatusCode.OK)
            {
                //链接不正常
                rt[0]["body"] = rt[0]["body"] + "服务器连接失败";
                return rt;
            }
            string contentType=res.ContentType.ToLower();
            if (contentType.IndexOf("image") == -1)
            {
                //不是图片
                rt[0]["body"] = rt[0]["body"] + "你上传的好像不是图片";
                return rt;
            }
            string fileName="";
            if (contentType.IndexOf("png") > -1)
            {
                fileName = ".png";
            }
            else if (contentType.IndexOf(".gif") > -1)
            {
                fileName = ".gif";
            }
            else if (contentType.IndexOf("jpeg") > -1 || contentType.IndexOf("jpg") > -1)
            {
                fileName = ".jpg";
            }
            if (fileName.Length == 0)
            {
                //未知图片格式
                rt[0]["body"] = rt[0]["body"] + "不支持的图片格式";
                return rt;
            }

            fileName = System.Guid.NewGuid().ToString("N") + fileName;
            wc.DownloadFile(userData["@PicUrl"].ToString(), savePath + fileName);

            string fileNameThumbnail ="s_"+ System.Guid.NewGuid().ToString("N") + fileName;
            moyu.Images myImg = new Images();
            moyu.Images.MakeThumbnail(savePath+fileName,savePath+fileNameThumbnail,300,0,"W");

            int uid=getWeiUserId(userData["@FromUserName"].ToString());
            string imgUrl = "http://www.ai0932.com/upload/userImages/" + folderPath + fileNameThumbnail;
            Information.group myGroup = new Information.group();
            int tid = myGroup.topicNewByWeixin("爆照", ("我在" + System.DateTime.Now.ToShortTimeString() + "在左邻分享了一张照片"), -1, uid, "<img src=\"" + imgUrl + "\"/>");
            moyu.User.Functions myUser=new User.Functions();
            int pid = myUser.upLoadImg(uid, savePath+ fileName, tid.ToString(), imgUrl);
            Hashtable[] rtSuccess = new Hashtable[1];
            rtSuccess[0] = new Hashtable();
            rtSuccess[0]["id"] = 0;
            rtSuccess[0]["messageType"] = 2;
            rtSuccess[0]["body"] = "图片分享成功";
            rtSuccess[0]["title"] = "成功分享了一张图片@" + System.DateTime.Now.ToShortTimeString() + "\n" +
                " 点这里为图片添加文字说明并查看分享的图片";
            rtSuccess[0]["picSmall"] = getPicUrl(false);
            rtSuccess[0]["picBig"] = imgUrl;
            rtSuccess[0]["url"] = "http://www.ai0932.com/mobile/addPicIntroduce.aspx?tid=" + tid + "&pid=" + pid;
            rtSuccess[0]["orders"] = 10;

            //rtSuccess[1] = new Hashtable();
            //rtSuccess[1]["id"] = 0;
            //rtSuccess[1]["messageType"] = 2;
            //rtSuccess[1]["title"] = "为图片添加文字说明?点击这里去给图片添加文字说明";
            //rtSuccess[1]["body"] = "为图片添加文字说明?点击这里去给图片添加文字说明";
            //rtSuccess[1]["picSmall"] = getPicUrl(false);
            //rtSuccess[1]["picBig"] = getPicUrl(true);
            //rtSuccess[1]["url"] = "http://www.ai0932.com/mobile/addPicIntroduce.aspx?tid="+tid+"&pid="+pid;
            //rtSuccess[1]["orders"] = 6;
            User.Functions myFunction = new User.Functions();
            myFunction.givePostPoint(uid, "发图积分", 1);
            return rtSuccess;
        }