肯蒂科的facebook页面门
我正试图在肯蒂科建立一个页面入口。我应该考虑使用web部件还是模块?我以前玩过这两种工具,因此知道如何使用它们进行基本开发。我以前使用过页面模板。其实很简单。Facebook有一个参数“signed_request”,该参数是base64编码的,它会发回(如果你在Facebook上安装了应用程序)。您需要对其进行解码,并使用json查找“liked”变量,该变量应为true或false 我在页面上有一个2cmSeditableRegion,如果用户喜欢该页面,则有一个,如果用户(尚未)喜欢该页面肯蒂科的facebook页面门,facebook,kentico,Facebook,Kentico,我正试图在肯蒂科建立一个页面入口。我应该考虑使用web部件还是模块?我以前玩过这两种工具,因此知道如何使用它们进行基本开发。我以前使用过页面模板。其实很简单。Facebook有一个参数“signed_request”,该参数是base64编码的,它会发回(如果你在Facebook上安装了应用程序)。您需要对其进行解码,并使用json查找“liked”变量,该变量应为true或false 我在页面上有一个2cmSeditableRegion,如果用户喜欢该页面,则有一个,如果用户(尚未)喜欢该页面
protected CMSEditableRegion likedRegion;
protected CMSEditableRegion notLikedRegion;
protected bool ValidateSignedRequest(string signed_request)
{
try
{
string payload = signed_request.Split('.')[1];
UTF8Encoding encoding = new UTF8Encoding();
var decodedJson = payload.Replace("=", string.Empty).Replace('-', '+').Replace('_', '/');
var base64JsonArray = Convert.FromBase64String(decodedJson.PadRight(decodedJson.Length + (4 - decodedJson.Length % 4) % 4, '='));
var json = encoding.GetString(base64JsonArray);
return json.IndexOf("\"liked\":true") != -1;
}
catch (Exception ex)
{
return false;
}
}
private bool parsePageSignedRequest()
{
if (Request["signed_request"] != null)
{
return ValidateSignedRequest(Request["signed_request"]);
}
return false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (CMS.CMSHelper.CMSContext.ViewMode == CMS.PortalEngine.ViewModeEnum.LiveSite)
{
if (parsePageSignedRequest())
{
notLikedRegion.Visible = false;
likedRegion.Visible = true;
}
else
{
notLikedRegion.Visible = true;
likedRegion.Visible = false;
}
}
}