我正在尝试获取用户对 TinyPass 资源的访问详细信息。
我刚刚开始尝试集成它并使用示例代码。
$params = array();
$params["rid"] = $rid;
$params["user_ref"] = $username;
$result = TinyPass::fetchAccessDetails($params, 1, 200);
echo $result->getTotal();
但是我在上面的行中收到了一个未捕获的异常 API 错误 ($result=...)
有没有人可以给我一些帮助?
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();