【问题标题】:Tinypass Fetching access detailsTinypass 获取访问详细信息
【发布时间】:2013-11-27 23:23:04
【问题描述】:

我正在尝试获取用户对 TinyPass 资源的访问详细信息。

我刚刚开始尝试集成它并使用示例代码。

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();

但我在上面的行 ($result=...) 上收到未捕获的异常 API 错误

请问有谁可以帮帮我吗?

PS:我正在尝试将我的自定义 PHP 站点的用户名发送到 tinypass,稍后我想获取该用户的数据。

这是我的代码

$rid = "PW_74296909";
$store = new TPAccessTokenStore();
$store->loadTokensFromCookie($_COOKIE);
$token = $store->getAccessToken($rid);
if($token->isAccessGranted()) {
    //Access granted! Display requested resource to the user
    echo 'WEELCOOOE';
} else {
    //Access denied! Proceed with the next steps and display a Tinypass button...

    $resource = new TPResource($rid, "Site wide premium content access");

    $po1 = new TPPriceOption(".50", "24 hours");
    $po2 = new TPPriceOption(".99", "1 week");
    $offer = new TPOffer($resource, array($po1, $po2));

    /*$request = new TPPurchaseRequest($offer);
    $buttonHTML = $request->setCallback("myFunction")->generateTag();

    //output button HTML in the place where Tinypass button is supposed to be rendered
    echo $buttonHTML;
    */

    //set user reference (username in this case)
    $username='member';


    $purchaseRequest = new TPPurchaseRequest($offer);
    $purchaseRequest->setUserRef($username);
    $link = $purchaseRequest->generateLink("http://localhost/Tinypass/index.php?action=success", "http://localhost/Tinypass/index.php?action=success");
    $buttonHTML= '<a href="'.$link.'" style="color:white; font-size:20px;">BUY IT</a>';

    //$buttonHTML = $purchaseRequest->setCallback("myFunction")->generateTag();
    echo $buttonHTML;

    $params = array();
    $params["rid"] =  $rid;
    $params["user_ref"] = $username;
    $result = TinyPass::fetchAccessDetails($params, 1, 200);
    echo $result->getTotal();

【问题讨论】:

    标签: php html payment


    【解决方案1】:

    也许您应该为此使用单数函数:

    $result = Tinypass:fetchaccessDetail(array('rid'=>$rid,'user_ref'=>$userref));
    if ($result) {echo "<!-- "; print_r($result); echo " -->";}
    

    如果您确实使用了复数函数,请尝试 getTotal 以外的其他方法:

    $results = TinyPass::fetchAccessDetails($params, 1, 200);
    if (count($results['data') > 0) {
        foreach ($results['data'] as $record) {
            echo "<!-- "; print_r($record); echo " -->";
        }
    }
    

    它看起来更像是您需要的单数函数,它比复数函数提供的信息略多。 http://developer.tinypass.com/main/restapi

    如果一切正常,您应该返回一个数组,其中列出的值作为数组键。 注意:fetchAccessDetails 仍然返回 'user_email' 而不是 API 页面建议的'email'。

    如果您仍然遇到麻烦(就像我一样),您可以做的另一件事是编辑文件 TinyPassGateway.php,这些函数所在的位置以及之前行中的每个函数:

    throw $e;
    

    添加:

    return $e->getMessage;
    

    因为您可以通过这种方式获得更直接的调试信息...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-23
      • 2020-07-15
      • 1970-01-01
      • 2012-06-02
      • 2020-10-08
      • 2018-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多