Commit 75792329 authored by 吴春's avatar 吴春

获取公众号成功发布的文章

parent d619a18d
......@@ -340,6 +340,90 @@ namespace Edu.WebApi.Controllers.LearningGarden
}
return list;
}
/// <summary>
/// 获取成功发布列表
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <returns></returns>
static List<WeChatLearningGardenItem> GetFreePublishList(int pageIndex, int pageSize)
{
string tokenKey = Cache.CacheKey.DATA_WeChatAccountToken + Common.Config.WeChatAccountAppId;
string token = Cache.WeChat.WeChatReidsCache2.GetToken(tokenKey);
if (Common.Config.IsLocal == 1)
{
token = "53_yZLlrwCr1CVh5TjyS1FkarF5M15NfYEmMFvtJKVA0C_R5tzOE20CZlFvWOWQRoezFQDweQPwkcenlISyEXoFkOpljNvyt-0_uXvtqQW41T7HfJnFGUWBGNIDkUQuFkKQWTpdXvdZhbWWeE_kMTTcAEAPWW";
}
if (string.IsNullOrEmpty(token))
{
token = Common.Plugin.WeChatHelper.GetAccessToken(Common.Config.WeChatAccountAppId, Common.Config.WeChatAccountAppSecret);
Cache.WeChat.WeChatReidsCache2.Set(tokenKey, token);
}
string newImaApi = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token=" + token;
List<WeChatLearningGardenItem> list = new List<WeChatLearningGardenItem>();
var resultInfo = new
{
count = pageSize,
offset = (pageIndex - 1) * pageSize,
no_content = pageSize
};
string jsonData = HttpHelper.HttpPost(newImaApi, JsonHelper.Serialize(resultInfo), "");
if (jsonData != null && !string.IsNullOrEmpty(jsonData))
{
Common.Plugin.LogHelper.WriteInfo("GetVoiceData: " + jsonData);
JObject jObj = JObject.Parse(jsonData);
var item = jObj.GetStringValue("item");
if (!string.IsNullOrEmpty(item))
{
JArray jArray = JArray.Parse(item);
if (jArray != null && jArray.Count > 0)
{
foreach (var jItem in jArray)
{
JObject sObj = JObject.Parse(jItem.ToString());
JObject dObj = JObject.Parse(sObj.GetStringValue("content"));
var newsItem = new List<WeChatLearningGardenNewsItem>();
JArray subArray = JArray.Parse(dObj.GetStringValue("news_item"));
if (subArray != null && subArray.Count > 0)
{
foreach (var sItem in subArray)
{
var contentObj = JObject.Parse(sItem.ToString());
newsItem.Add(new WeChatLearningGardenNewsItem()
{
title = contentObj.GetStringValue("title"),
author = contentObj.GetStringValue("author"),
digest = contentObj.GetStringValue("digest"),
content = contentObj.GetStringValue("content"),
show_cover_pic = contentObj.GetInt("show_cover_pic"),
url = contentObj.GetStringValue("url"),
thumb_url = contentObj.GetStringValue("thumb_url"),
});
}
}
var content = new WeChatLearningGardenContent()
{
news_item = newsItem,
create_time = dObj.GetLong("create_time"),
update_time = dObj.GetLong("update_time"),
};
WeChatLearningGardenItem model = new WeChatLearningGardenItem()
{
media_id = sObj.GetStringValue("article_id"),
update_time = sObj.GetStringValue("update_time"),
content = content
};
list.Add(model);
}
}
}
}
return list;
}
#endregion
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment