【问题标题】:Local Currency Payment verification fails using curl php使用 curl php 的本地货币支付验证失败
【发布时间】:2013-07-14 17:41:38
【问题描述】:

我正在为画布应用程序实施 Facebook 的新本地货币支付,除了使用 PHP curl 使用服务器端 Facebook Graph 调用验证支付外,一切正常。

我不断收到以下消息:

"error":{
    "message":"An unexpected error has occurred. Please retry your request later.",
    "type":"OAuthException",
    "code":2
}

php代码:

$url  = 'https://graph.facebook.com/'.$payment_id.'/?access_token='.$access_token;
$data = get_url($url);

function get_url($url)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    $tmp = curl_exec($ch);
    curl_close($ch);
    return $tmp;
}

在浏览器中粘贴图形链接时单独工作正常,因此 payment_id 和 access_token 是正确的,但它不适用于 php curl。

不过,其他图形调用使用相同的 curl 函数可以正常工作。

这里有没有人通过服务器验证成功实现本地货币支付?

有什么建议吗?

谢谢。

【问题讨论】:

  • 您的代码实际上向 Facebook 的服务器发出了什么调用?您确定您的代码请求的 URL 与 Facebook SDK 相同吗?访问令牌和支付 ID 是否都正确传递?
  • 我正在阅读第 5a 步中所述的付款信息:developers.facebook.com/docs/tutorials/canvas-games/payments/…,并且我检查了在浏览器中粘贴完整图表链接时相同的访问令牌和付款 ID 是否有效。
  • 您是否在关闭 FB 会话的情况下在浏览器中尝试了相同的 url?因为对我来说,只有当 FB 有会话打开时,url 才有效,如果你关闭会话,url 有时才有效。

标签: php facebook facebook-graph-api curl payment


【解决方案1】:

我可以使用以下代码获取付款 ID 上的退货 ID:

注意:测试购买不会从 api 请求返回。 “我需要 在文档中验证这一点”。

错误错误:在我的情况下,即使使用访问令牌完全访问应用程序,也只有 id 会返回,而 api 会限制其余信息。


<?php
function GetCH($url){
$ch=null;
if(!$ch){
$ch = curl_init();
}
curl_setopt($ch, CURLOPT_URL, "".$url."");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$return=curl_exec($ch);
 if(!curl_errno($ch)){
return $return;
 }else{
$fb_fail=curl_error($ch);
return $fb_fail;
}
curl_close($ch);
unset($ch);
};
$payment_id = '901177xxxxxxxxxxx?fields=id,amount,application,created_time,from,status,updated_time,items';  // notice the request for more than just the id using expansion.
$access_token = '135669679827333|xxxxxxxxxxxxxxx'; // app access token.
$url  = 'https://graph.facebook.com/'.$payment_id.'&access_token='.$access_token;
$returned=GetCH($url);
$locs=json_decode($returned, true);
echo '<pre>';
print_r($locs);
echo '</pre>';
?>

错误报告参考的占位符。

【讨论】:

  • 谢谢肖恩。添加我的 payment_id 和令牌时,我得到以下异常:(#100) Unknown fields: amount,from,status,updated_time 删除这些字段并使用所有或部分这些fields=id,application,actions,refundable_amount,items,country,created_time,fraud_status,payout_foreign_exchange_rate,test 完整的图形链接在显示正确结果的浏览器中工作正常,但您的代码和我的代码的结果id 和 token 仍然是An unexpected error has occurred. Please retry your request later.。我正在使用测试付款的 payment_id。你认为这可能是个问题吗?
  • 我进入了我的个人资料,并从我自己的收据中获取了 ID。
  • 你试过我贴的cURL函数了吗?
  • 是的,我复制了您的代码,只是更改了 payment_id 和应用令牌。除了读取新的本地货币支付信息外,所有图表调用都可以正常工作,因此似乎与此有关。
  • Shawn:你试过的收据是有效的,是从新的本地货币支付系统创建的 payment_id 吗? developers.facebook.com/docs/concepts/payments 你也用了app自带的access_token?我试图缩小为什么这不起作用。感谢您的帮助。
【解决方案2】:

我也有同样的问题。这与您如何将 cUrl 请求发送到图表无关。 这是因为当您没有 facebook 会话时,API 不会相应地响应。

这就是为什么相同的链接在 cURL 中不起作用但在浏览器中起作用(具有活动的 facebook 会话)。

现在,可能有一个解决方案可以做到这一点,但我不会依赖它。 1) 通过 cUrl 登录到 facebook 帐户并将会话保存在文件中。 2) 使用该文件进行会话,从而发出所需的 cURL 请求。

所以,我也有点卡住了。有人找到更好的解决方案吗?

【讨论】:

    【解决方案3】:

    我发现了这里报告的错误:https://developers.facebook.com/bugs/283875851753617

    这里是任何会陷入这种疯狂的人的代码。

    (注意:不可靠,因为随机它不会返回应有的内容,而是返回“发生意外错误。请稍后重试您的请求。”)

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/' . $payment_id . '?access_token=YES_APP_TOKEN_TOKEN');
            curl_setopt($ch, CURLOPT_COOKIE, 'c_user=APP_ID');  //not reliable, because not always working.
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
            curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
            curl_setopt($ch, CURLOPT_TIMEOUT, 20);
            curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
            curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            $result = curl_exec($ch);
    

    【讨论】:

      猜你喜欢
      • 2020-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 2017-08-01
      • 2021-06-08
      • 2015-12-17
      • 2015-07-30
      相关资源
      最近更新 更多