Facebook“签名请求”使用纯经典 ASP

发布于 2024-11-27 06:34:30 字数 182 浏览 0 评论 0原文

我想在我的 Facebook 应用程序中获取 signed_request 的内容,但仅使用带有 VBScript 的经典 ASP。

Facebook 的网站有一个 PHP 解码示例,但我找不到 ASP 的任何内容。

我想我需要解码 base64url,然后读取 JSON,但我不知道如何。

I would like to get the contents of the signed_request in my fb app, but using only Classic ASP with VBScript.

Facebook's site has an example in PHP of decoding this but I can't find anything for ASP.

I think I need to decode the base64url, then read the JSON, but I don't know how.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

删除→记忆 2024-12-04 06:34:30

我和你在同一条船上。所有提供创建门的代码的站点都是用 PHP 编写的。使用 ChiliPepperDesign 的 “Reveal / Fan-Gate / Like-Gate Facebook iFrame Tab” 作为起点,我将 PHP 转换为 ASP/VBScript,并找到了base64 解码和 JSON 解码(显然 PHP 本身就是这样做的)。

我从 GitHub 获取的 JSON.decode 脚本。是的,它是 Javascript,但是如果您在页面上的代码前面加上以下内容,则可以在 ASP/VBScript 站点上运行它:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<script language="JSCRIPT" runat="server">

将所有下载的 Javascript 放入,然后使用通常的 关闭。 标签。将此文件另存为 json_decode.asp

Base64 解码有点困难(我最初下载的那个可以工作,但不能工作)。我在免费 VBCode 上找到了更好的版本。下载该文件并将其放入另一个文件base64_encode-decode.asp中。

最后,将所有内容组合在一起的代码是:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<!-- #INCLUDE FILE="json_decode.asp" -->

<%
Dim encoded_sig, payload, sig, data, myArray

Function parsePageSignedRequest()
    If Request("signed_request") <> "" THEN

        myArray = Split(Request("signed_request"), ".")
        encoded_sig = myArray(0)
        payload = myArray(1)

        sig = base64_decode(Replace(encoded_sig, "-_", "+/"))
        set data = JSON.parse(base64_decode(Replace(payload, "-_", "+/")))

        parsePageSignedRequest = data

        If data.page.liked Then %>
        <p>Thank you for liking us!</p>
        <% Else %>
        <p>Please click the "like" button to continue.</p>
        <% End If
    Else
        parsePageSignedRequest = ""
    End If
End Function

'' -- run the function
parsePageSignedRequest()
%>

将其另存为 facebook-likeGate.asp ,在您的网站上与两个包含文件相同的位置,并将 Facebook 指向此页面。

华泰

JF

I was in the same boat you are. All of the sites which provide code to create a gate are written in PHP. Using the code on ChiliPepperDesign's "Reveal / Fan-Gate / Like-Gate Facebook iFrame Tab" as a starting point, I converted the PHP to ASP/VBScript, and found sources for the base64 decode and JSON decode (which PHP apparently does natively).

The JSON.decode script I got from GitHub. Yes, it is Javascript, but you can run it on an ASP/VBScript site if you preface the code on the page with this:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<script language="JSCRIPT" runat="server">

Put all of the downloaded Javascript in, and then close with the usual </script> tag. Save this file as json_decode.asp.

The base64 decode was a little harder (the one I initially downloaded sorta worked and sorta did NOT work). I found a better version on Free VBCode. Downlaod that and put it into another file, base64_encode-decode.asp.

Finally, the code to bring it all together is:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<!-- #INCLUDE FILE="json_decode.asp" -->

<%
Dim encoded_sig, payload, sig, data, myArray

Function parsePageSignedRequest()
    If Request("signed_request") <> "" THEN

        myArray = Split(Request("signed_request"), ".")
        encoded_sig = myArray(0)
        payload = myArray(1)

        sig = base64_decode(Replace(encoded_sig, "-_", "+/"))
        set data = JSON.parse(base64_decode(Replace(payload, "-_", "+/")))

        parsePageSignedRequest = data

        If data.page.liked Then %>
        <p>Thank you for liking us!</p>
        <% Else %>
        <p>Please click the "like" button to continue.</p>
        <% End If
    Else
        parsePageSignedRequest = ""
    End If
End Function

'' -- run the function
parsePageSignedRequest()
%>

Save this as facebook-likeGate.asp on your site in the same location as the two include files, and point Facebook to this page.

HTH

JF

衣神在巴黎 2024-12-04 06:34:30

这是未使用 json_decode.asp 的代码

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<% 
Dim encoded_sig, payload, sig, data, myArray

Function parsePageSignedRequest()
    If Request("signed_request") <> "" THEN
        myArray = Split(Request("signed_request"), ".")
        payload     = myArray(1)
        payload = base64_decode(payload)

        If instr(payload,"liked"":true,") Then %>
        <p>Thank you for liking us!</p>
        <% Else %>
        <p>Please click the "like" button to continue.</p>
        <% End If
    Else
        parsePageSignedRequest = ""
    End If
End Function
parsePageSignedRequest()
%>

Here is the code without the use of json_decode.asp

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE FILE="base64_encode-decode.asp" -->
<% 
Dim encoded_sig, payload, sig, data, myArray

Function parsePageSignedRequest()
    If Request("signed_request") <> "" THEN
        myArray = Split(Request("signed_request"), ".")
        payload     = myArray(1)
        payload = base64_decode(payload)

        If instr(payload,"liked"":true,") Then %>
        <p>Thank you for liking us!</p>
        <% Else %>
        <p>Please click the "like" button to continue.</p>
        <% End If
    Else
        parsePageSignedRequest = ""
    End If
End Function
parsePageSignedRequest()
%>
酷遇一生 2024-12-04 06:34:30

您可以使用新的 JS SDK。这是我编码和使用的示例。帖子方法效果很好。

<head> 
     <SCRIPT language="JavaScript"> 
  setInterval('SubMe()',1500);
function SubMe() 
{ 
  if(document.getElementById('fbmail').value != ''){ 

document.form.submit();

}

} 


</SCRIPT>

  </head> 

<body> 

<div id="fb-root"></div>
<h2></h2><br />
<div id="user-info"></div>
<p><fb:login-button scope="email,publish_stream,user_about_me,user_location,user_birthday" on-login="top.location = '';" autologoutlink="true"></fb:login-button></p>


<script>
window.fbAsyncInit = function() {
  FB.init({ appId: 'APP ID', 
        status: true, 
        cookie: true,
        xfbml: true,
        oauth: true});

  function updateButton(response) {
    var button = document.getElementById('fb-auth');

    if (response.authResponse) {
      //user is already logged in and connected
      var userInfo = document.getElementById('user-info');
      FB.api('/me', function(response) {
         userInfo.innerHTML='Redirecting...If doesnt work click <a href="">here</a>';
          document.getElementById('fbmail').value = response.email;
        document.getElementById('fbid').value = response.id;
         document.getElementById('fbname').value = response.name;
          document.getElementById('fbbirthday').value = response.birthday;
           document.getElementById('fbhometown').value = response.hometown.name;
        button.innerHTML = 'Logout';

      });
      button.onclick = function() {
        FB.logout(function(response) {
          var userInfo = document.getElementById('user-info');
          userInfo.innerHTML="";
    });
      };
    } else {
      //user is not connected to your app or logged out
      button.innerHTML = 'Logout';
      button.onclick = function() {
        FB.login(function(response) {
      if (response.authResponse) {
            FB.api('/me', function(response) {
          var userInfo = document.getElementById('user-info');
         userInfo.innerHTML='Redirecting...If doesnt work click <a href="">here</a>';
          document.getElementById('fbmail').value = response.email;
        document.getElementById('fbid').value = response.id;
         document.getElementById('fbname').value = response.name;
          document.getElementById('fbbirthday').value = response.birthday;
           document.getElementById('fbhometown').value = response.hometown.name;
        });    
          } else {
            //user cancelled login or did not grant authorization
          }
        }, {scope:'email'});    
      }
    }
  }

  // run once with current status and whenever the status changes
  FB.getLoginStatus(updateButton);
  FB.Event.subscribe('auth.statusChange', updateButton);    
};

(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol 
    + '//connect.facebook.net/en_US/all.js';
  document.getElementById('fb-root').appendChild(e);
}());

</script>
<form method="post" name="form" id="form" action="go_little_caeser.asp">
<input name="fbmail" id="fbmail" type="hidden">

<input name="fbid" id="fbid" type="hidden">
<input name="fbname" id="fbname" type="hidden">
<input name="fbbirthday" id="fbbirthday" type="hidden">
<input name="fbhometown" id="fbhometown" type="hidden">
</form>
</body> 

You can use new JS SDK. Here is a sample which I have coded and used. Post method works good.

<head> 
     <SCRIPT language="JavaScript"> 
  setInterval('SubMe()',1500);
function SubMe() 
{ 
  if(document.getElementById('fbmail').value != ''){ 

document.form.submit();

}

} 


</SCRIPT>

  </head> 

<body> 

<div id="fb-root"></div>
<h2></h2><br />
<div id="user-info"></div>
<p><fb:login-button scope="email,publish_stream,user_about_me,user_location,user_birthday" on-login="top.location = '';" autologoutlink="true"></fb:login-button></p>


<script>
window.fbAsyncInit = function() {
  FB.init({ appId: 'APP ID', 
        status: true, 
        cookie: true,
        xfbml: true,
        oauth: true});

  function updateButton(response) {
    var button = document.getElementById('fb-auth');

    if (response.authResponse) {
      //user is already logged in and connected
      var userInfo = document.getElementById('user-info');
      FB.api('/me', function(response) {
         userInfo.innerHTML='Redirecting...If doesnt work click <a href="">here</a>';
          document.getElementById('fbmail').value = response.email;
        document.getElementById('fbid').value = response.id;
         document.getElementById('fbname').value = response.name;
          document.getElementById('fbbirthday').value = response.birthday;
           document.getElementById('fbhometown').value = response.hometown.name;
        button.innerHTML = 'Logout';

      });
      button.onclick = function() {
        FB.logout(function(response) {
          var userInfo = document.getElementById('user-info');
          userInfo.innerHTML="";
    });
      };
    } else {
      //user is not connected to your app or logged out
      button.innerHTML = 'Logout';
      button.onclick = function() {
        FB.login(function(response) {
      if (response.authResponse) {
            FB.api('/me', function(response) {
          var userInfo = document.getElementById('user-info');
         userInfo.innerHTML='Redirecting...If doesnt work click <a href="">here</a>';
          document.getElementById('fbmail').value = response.email;
        document.getElementById('fbid').value = response.id;
         document.getElementById('fbname').value = response.name;
          document.getElementById('fbbirthday').value = response.birthday;
           document.getElementById('fbhometown').value = response.hometown.name;
        });    
          } else {
            //user cancelled login or did not grant authorization
          }
        }, {scope:'email'});    
      }
    }
  }

  // run once with current status and whenever the status changes
  FB.getLoginStatus(updateButton);
  FB.Event.subscribe('auth.statusChange', updateButton);    
};

(function() {
  var e = document.createElement('script'); e.async = true;
  e.src = document.location.protocol 
    + '//connect.facebook.net/en_US/all.js';
  document.getElementById('fb-root').appendChild(e);
}());

</script>
<form method="post" name="form" id="form" action="go_little_caeser.asp">
<input name="fbmail" id="fbmail" type="hidden">

<input name="fbid" id="fbid" type="hidden">
<input name="fbname" id="fbname" type="hidden">
<input name="fbbirthday" id="fbbirthday" type="hidden">
<input name="fbhometown" id="fbhometown" type="hidden">
</form>
</body> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文