Exemplo n.º 1
0
 public static MaterialList <MaterialNews> BatchGetNews(string access_token, int offset, int count) =>
 ApiPost <MaterialList <MaterialNews> >(JsonCreate.BatchGetNews(offset, count), "/cgi-bin/material/batchget_material?access_token={0}", access_token);
            public void WeChatApiMediaTest()
            {
                //Api.Media.Upload(Api.GetAccessToken(Config), MediaType.Image, @"C:\Users\Vic\Desktop\topbar_logo.png");

                Assert.AreEqual(Api.Media.GetUrl("test", MediaType.Image, "demoMediaId"), "https://api.weixin.qq.com/cgi-bin/media/get?access_token=test&media_id=demoMediaId");
                Assert.AreEqual(Api.Media.SpeexDownloadUrl("test", "demoMediaId"), "https://api.weixin.qq.com/cgi-bin/media/get/jssdk?access_token=test&media_id=demoMediaId");

                Assert.AreEqual(Api.Material.MiniProgramContentXml("wx123123123", "pages/index/index", "小程序示例", "http://mmbizqbic.cn/demo.jpg"), "<mp-miniprogram data-miniprogram-appid=\"wx123123123\" data-miniprogram-path=\"pages/index/index\" data-miniprogram-title=\"小程序示例\" data-progarm-imageurl=\"http://mmbizqbic.cn/demo.jpg\"></mp-miniprogram>");

                Assert.AreEqual(JsonCreate.AddNews(new List <Model.Article>()
                {
                    new Model.Article()
                    {
                        title              = "TITLE",
                        thumb_media_id     = "THUMB_MEDIA_ID",
                        author             = "AUTHOR",
                        digest             = "DIGEST",
                        show_cover_pic     = false,
                        content            = "CONTENT",
                        content_source_url = "CONTENT_SOURCE_URL"
                    }
                }), "{\"articles\":[{\"title\":\"TITLE\",\"thumb_media_id\":\"THUMB_MEDIA_ID\",\"author\":\"AUTHOR\",\"digest\":\"DIGEST\",\"show_cover_pic\":0,\"content\":\"CONTENT\",\"content_source_url\":\"CONTENT_SOURCE_URL\"}]}");
                Assert.AreEqual(JsonCreate.Add("VIDEO_TITLE", "INTRODUCTION"), "{\"title\":\"VIDEO_TITLE\",\"introduction\":\"INTRODUCTION\"}");

                var getRequest = "{\"media_id\":\"MEDIA_ID\"}";

                Assert.AreEqual(JsonCreate.GetVideoInfo("MEDIA_ID"), getRequest);
                Assert.AreEqual(JsonCreate.GetNews("MEDIA_ID"), getRequest);
                Assert.AreEqual(JsonCreate.Delete("MEDIA_ID"), getRequest);

                Assert.AreEqual(JsonCreate.UpdateNews("MEDIA_ID", 1, new Model.Article()
                {
                    title              = "TITLE",
                    thumb_media_id     = "THUMB_MEDIA_ID",
                    author             = "AUTHOR",
                    digest             = "DIGEST",
                    show_cover_pic     = true,
                    content            = "CONTENT",
                    content_source_url = "CONTENT_SOURCE_URL"
                }), "{\"media_id\":\"MEDIA_ID\",\"index\":1,\"articles\":{\"title\":\"TITLE\",\"thumb_media_id\":\"THUMB_MEDIA_ID\",\"author\":\"AUTHOR\",\"digest\":\"DIGEST\",\"show_cover_pic\":1,\"content\":\"CONTENT\",\"content_source_url\":\"CONTENT_SOURCE_URL\"}}");

                Assert.AreEqual(JsonCreate.BatchGet("image", 0, 20), "{\"type\":\"image\",\"offset\":0,\"count\":20}");
                Assert.AreEqual(JsonCreate.BatchGetNews(0, 20), "{\"type\":\"news\",\"offset\":0,\"count\":20}");

                //var data = Api.Material.Add(Api.GetAccessToken(Config), MediaType.Image, @"C:\Users\Vic\Desktop\topbar_logo.png");
                //var url = Api.Material.UploadImage(Api.GetAccessToken(Config), @"C:\Users\Vic\Desktop\topbar_logo.png");
                //var newsMediaId = Api.Material.AddNews(Api.GetAccessToken(Config),
                //     new Model.MaterialNew()
                //     {
                //         title = "接口测试",
                //         thumb_media_id = data.media_id,
                //         author = "测试",
                //         digest = "测试信息",
                //         show_cover_pic = true,
                //         content = "测试呀",
                //         content_source_url = "http://www.qq.com/"
                //     }, new Model.MaterialNew()
                //     {
                //         title = "接口测试",
                //         thumb_media_id = data.media_id,
                //         author = "测试",
                //         digest = "测试信息",
                //         show_cover_pic = true,
                //         content = "测试呀",
                //         content_source_url = "http://www.qq.com/"
                //     }
                //     );
                //Api.Material.Get(Api.GetAccessToken(Config), MediaType.Image, data.media_id);
                //var newsData = Api.Material.GetNews(Api.GetAccessToken(Config), newsMediaId);
                //Api.Material.UpdateNews(Api.GetAccessToken(Config), newsMediaId, 1, new Model.MaterialNew()
                //{
                //    title = "接口测试" + DateTime.Now.ToTimeString(),
                //    thumb_media_id = data.media_id,
                //    author = "测试",
                //    digest = "测试信息",
                //    show_cover_pic = true,
                //    content = "测试呀",
                //    content_source_url = "http://www.qq.com/"
                //});

                //Api.Material.Delete(Api.GetAccessToken(Config), data.media_id);
                //Api.Material.Delete(Api.GetAccessToken(Config), newsMediaId);

                //var count = Api.Material.Count(Api.GetAccessToken(Config));
                //var batch = Api.Material.BatchGet(Api.GetAccessToken(Config), MediaType.Image, 0, 10);
                //var news = Api.Material.BatchGetNews(Api.GetAccessToken(Config), 0, 10);
            }