/// <summary>
        ///     获取图片、语音、视频文件列表
        /// </summary>
        /// <returns>JSON</returns>
        public JsonResult GetMediaJsonResult(UploadMediaFileType fileType)
        {
            var accessToken = AccessToken;

            switch (fileType)
            {
            case UploadMediaFileType.news:

                break;

            case UploadMediaFileType.image:
                var images = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 20);
                return(Json(images, JsonRequestBehavior.AllowGet));

                break;

            case UploadMediaFileType.voice:
                var voices = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.voice, 0, 20);
                return(Json(voices, JsonRequestBehavior.AllowGet));

                break;

            case UploadMediaFileType.video:
                var videos = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.video, 0, 20);
                return(Json(videos, JsonRequestBehavior.AllowGet));

                break;
            }
            return(null);
        }
Beispiel #2
0
        public void GetOthersMediaListTest()
        {
            var accessToken = AccessTokenContainer.GetToken(_appId);

            var result = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 3);

            Assert.AreEqual(result.errcode, ReturnCode.请求成功);
            Assert.AreEqual(result.item_count, 3);
        }
        protected void btnSaveImg_Click(object sender, EventArgs e)
        {
            //var longAccessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["LongNameAppId"],
            //                     WebConfigurationManager.AppSettings["LongNameAppSecret"]);

            //var longImgResult = MediaApi.GetOthersMediaList(longAccessToken, UploadMediaFileType.image, 0, 1000);

            var shortAccessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["ShortWeixinAppId"],
                                                                    WebConfigurationManager.AppSettings["ShortWeixinSecret"]);
            var shortImgResult = MediaApi.GetOthersMediaList(shortAccessToken, UploadMediaFileType.image, 0, 1000);

            for (int i = 0; i < 6; i++)
            {
                string     handleNum  = i.ToString();
                FileUpload fileUpload = (FileUpload)Page.FindControl("uploadImgUrl" + handleNum);
                Label      lab        = (Label)Page.FindControl("labImgError" + handleNum);
                if (fileUpload.HasFile)
                {
                    string fileExt = Path.GetExtension(fileUpload.FileName);
                    if (IsAllowableFileType(fileExt))
                    {
                        try
                        {
                            string saveName = "send" + handleNum + ".jpg";
                            string filePath = Server.MapPath("image") + "\\" + saveName;
                            //保存图片
                            fileUpload.SaveAs(filePath);
                            lab.Text         = "本地图片更新OK:〈br>";
                            shortAccessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["ShortWeixinAppId"],
                                                                                WebConfigurationManager.AppSettings["ShortWeixinSecret"]);
                            //上传微信公众号后台
                            UploadImgToWeixin(shortAccessToken, shortImgResult, saveName, filePath);

                            //UploadImgToWeixin(longAccessToken, longImgResult, saveName, filePath);

                            lab.Text += "微信公众号后台图片更新OK";
                        }
                        catch (Exception ex)
                        {
                            lab.Text = "发生错误:" + ex.Message.ToString();
                        }
                    }
                    else
                    {
                        lab.Text = "只允许上传.jpg文件!";
                    }
                }
                else
                {
                    lab.Text = "未上传图片!";
                }
            }
        }
 private void GetImages(int pageIndex, int pageSize, out MediaList_OthersResult data,
                        out IEnumerable <MaterialViewModel> dataList)
 {
     data = MediaApi.GetOthersMediaList(AccessToken, UploadMediaFileType.image, (pageIndex - 1) * pageSize,
                                        pageSize);
     dataList = data.item
                .Select(p =>
                        new MaterialViewModel
     {
         Id         = p.media_id,
         Name       = p.name,
         UpdateTime = p.update_time.ConvertToDateTime(),
         Url        = p.url
     });
 }
Beispiel #5
0
        protected void btnSendAll_Click(object sender, EventArgs e)
        {
            string tempStr = new WeixinHelpService().GetTemp(Server);

            var accessToken = AccessTokenContainer.TryGetToken(WebConfigurationManager.AppSettings["LongNameAppId"],
                                                               WebConfigurationManager.AppSettings["LongNameAppSecret"]);
            OpenIdResultJson json = UserApi.Get(accessToken, "");

            var imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);

            SendImg(accessToken, imgResult);
            imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);

            SendGroupMessage(tempStr, accessToken, imgResult, "服务号");
        }
        public ActionResult Voices(int pageIndex = 1, int pageSize = 18)
        {
            var data     = MediaApi.GetOthersMediaList(AccessToken, UploadMediaFileType.voice, pageIndex, pageSize);
            var dataList = data.item
                           .Select(p =>
                                   new MaterialViewModel
            {
                Id         = p.media_id,
                Name       = p.name,
                UpdateTime = p.update_time.ConvertToDateTime(),
                Url        = p.url
            });
            var pagedList = new PagedList <MaterialViewModel>(dataList, pageIndex, pageSize, data.total_count);

            return(View(pagedList));
        }
        public ActionResult GetVoicesJson(int pageIndex = 1, int pageSize = 20)
        {
            IEnumerable <MaterialViewModel> dataList;
            var data = MediaApi.GetOthersMediaList(AccessToken, UploadMediaFileType.voice, (pageIndex - 1) * pageSize,
                                                   pageSize);

            dataList = data.item
                       .Select(p =>
                               new MaterialViewModel
            {
                Id         = p.media_id,
                Name       = p.name,
                UpdateTime = p.update_time.ConvertToDateTime(),
                Url        = p.url
            });
            var pagedList = new DataPageListViewModel <MaterialViewModel>(dataList, pageIndex, pageSize, data.total_count);

            return(Json(pagedList, JsonRequestBehavior.AllowGet));
        }
        public void PushNews(string accessToken, string webPath, string tempStr)
        {
            OpenIdResultJson json = UserApi.Get(accessToken, "");
            var imgResult         = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);
            var DircetPath        = Environment.CurrentDirectory + "/image/";

            if (!Directory.Exists(DircetPath))
            {
                Directory.CreateDirectory(DircetPath);
            }

            for (int i = 0; i < 6; i++)
            {
                string imgName = string.Format("send{0}.jpg", i);
                if (imgResult.item.Find(p => p.name == imgName) == null)
                {
                    var imgPath  = webPath + "/image/" + imgName;
                    var filePath = DircetPath + "/image/" + imgName;
                    CommonUtility.HttpUtility.DownloadFile(imgPath, filePath);
                    var mediaId = MediaApi.UploadForeverMedia(accessToken, filePath).media_id;
                }
            }
            imgResult = MediaApi.GetOthersMediaList(accessToken, UploadMediaFileType.image, 0, 10000);


            string sendCountTxtUrl = webPath + "/" + "sendcount.txt";
            var    sendCountTxt    = CommonUtility.HttpUtility.Get(sendCountTxtUrl);
            var    sendCount       = int.Parse(sendCountTxt);

            NewsModel[] newsList = new NewsModel[sendCount];

            var dataSevice = new DataAccessSerive();
            var jobList    = dataSevice.GetTopJobInfoList();

            if (jobList.Count > 0)
            {
                List <Article> articles = new List <Article>();
                int            i        = 0;
                string         imgName;
                foreach (var job in jobList)
                {
                    if (i == sendCount)
                    {
                        break;
                    }
                    string domain  = ConfigurationManager.AppSettings.Get("domain");
                    string website = ConfigurationManager.AppSettings.Get("website");
                    imgName = "send" + i.ToString() + ".jpg";
                    string imgUrl    = string.Format("{0}/image/{1}", domain, imgName);
                    var    jobDetail = dataSevice.GetJobDetail(job.JobId);
                    var    news      = new NewsModel()
                    {
                        author  = "",
                        content = tempStr.Replace("[ComName]", job.ComName)
                                  .Replace("[ComBrief]", jobDetail.ComBrief)
                                  .Replace("[DetailPalce]", jobDetail.DetailPalce)
                                  .Replace("[LinkMan]", jobDetail.LinkMan)
                                  .Replace("[Phone]", jobDetail.Phone)
                                  .Replace("[JobName]", jobDetail.JobName)
                                  .Replace("[JobType]", jobDetail.JobType)
                                  .Replace("[LowMoney]", jobDetail.LowMoney)
                                  .Replace("[HrNum]", jobDetail.HrNum)
                                  .Replace("[Edu]", jobDetail.Edu)
                                  .Replace("[RegisterDate]", jobDetail.RegisterDate)
                                  .Replace("[EffectDate]", jobDetail.EffectDate)
                                  .Replace("[Other]", jobDetail.Other)
                                  .Replace("[Sex]", jobDetail.Sex)
                        ,
                        //content_source_url = domain + "/html/detail.html?id=" + job.JobId,
                        content_source_url = website,
                        digest             = job.ComName + "诚聘" + job.JobName,
                        show_cover_pic     = "0",
                        thumb_media_id     = imgResult.item.Find(p => p.name == imgName).media_id,
                        title = job.ComName + "诚聘" + job.JobName
                    };
                    newsList[i] = news;
                    i++;
                }
                UploadForeverMediaResult mediaResult = MediaApi.UploadNews(accessToken, 100000, newsList);
                try
                {
                    if (isDebug != "1")
                    {
                        GroupMessageApi.SendGroupMessageByGroupId(accessToken, "-1", mediaResult.media_id, GroupMessageType.mpnews, true);
                    }
                    Console.WriteLine("素材提交推送  推送成功");
                    logger.Info(DateTime.Now.ToString() + " 素材提交推送  推送成功");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("素材提交推送  推送失败 " + ex.Message);
                    var MailService = new MailSendFunc();
                    MailService.SendMail("*****@*****.**", ex.Message, "素材提交推送异常", mailCfg);
                    logger.ErrorException(DateTime.Now.ToString() + "素材提交推送失败 " + ex.Message, ex);
                }
            }
        }