【问题标题】:empty value from stream_context_create()stream_context_create() 中的空值
【发布时间】:2012-11-29 12:52:19
【问题描述】:

我已使用自适应贝宝付款。使用此代码

$params = array("http" => array( 
    "method" => "POST",
    "content" => $body_data,
    "header" =>  "X-PAYPAL-SECURITY-USERID: " . $API_UserName . "\r\n" .
    "X-PAYPAL-SECURITY-SIGNATURE: " . $API_Signature . "\r\n" .
    "X-PAYPAL-SECURITY-PASSWORD: " . $API_Password . "\r\n" .
    "X-PAYPAL-APPLICATION-ID: " . $API_AppID . "\r\n" .
    "X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "\r\n" .
    "X-PAYPAL-RESPONSE-DATA-FORMAT: " . $API_ResponseFormat . "\r\n" 
));

$ctx = stream_context_create($params);

//open the stream and send request
$fp = @fopen($url, "r", false, $ctx);

//get response
$response = stream_get_contents($fp);

//check to see if stream is open
if ($response === false) {
   throw new Exception("php error message = " . "$php_errormsg");
}

//close the stream
fclose($fp);

但它显示错误消息

消息:||php 错误消息 = stream_get_contents() 期望参数 1 是资源,给定布尔值||

如何删除这个请帮帮我... :)

【问题讨论】:

    标签: php paypal-adaptive-payments


    【解决方案1】:

    发生这种情况是因为:

    $fp = @fopen($url, "r", false, $ctx);
    

    正在返回一个 FALSE 布尔值。删除 @ 运算符 (error control) 并查看您的函数是否抛出任何错误或通知。另外,请检查并确保您的 URL 正确。

    【讨论】:

    • 我已经删除了那个@符号,但它显示了这两条错误消息 1) fopen(): Unable to find the wrapper "https" - 你在配置PHP时忘记启用它了吗? 2)fopen(svcs.sandbox.paypal.com/AdaptivePayments/Pay):打开流失败:参数无效
    • 1) fopen():无法找到包装器“https” - 您在配置 PHP 时是否忘记启用它? 2)fopen(svcs.sandbox.paypal.com/AdaptivePayments/Pay):打开流失败:参数无效-
    【解决方案2】:

    您的 fopen() 呼叫失败(返回 false)。您为什么要使用 @ 抑制错误?

    无法访问$url 中的任何内容。检查资源是否可访问且没有网络问题。

    如果您尝试访问 https 安全链接,则需要安装并启用 OpenSSL。

    来自Manual

    成功时返回文件指针资源,错误时返回 FALSE。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-10
      • 1970-01-01
      • 1970-01-01
      • 2018-06-14
      • 2012-08-07
      • 2018-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多