我对此感到困惑我想检查paypal电子邮件ID是否已经过验证,是否存在。我正在使用laravel 5.2,我从stackoverflow找到了这个答案的代码:
Is a valid paypal email address or not (PHP)
但是我收到了这个错误: -
stream_get_contents()期望参数1是资源,布尔值 给定
我不知道答案如何被接受请帮帮我。如何解决这个问题。我想检查paypal电子邮件是否经过验证
这是我的PHP代码
$url = trim("https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus"); //set PayPal Endpoint to sandbox
$API_UserName = "XXXXXXXXXXXXXXXXXXX";
$API_Password = "XXXXXXXXXXXXXXXXXXX";
$API_Signature = "XXXXXXXXXXXXXXXXXX";
$API_AppID = "APP-80W284485P519543T";
$API_RequestFormat = "NV";
$API_ResponseFormat = "NV";
$bodyparams = array ("requestEnvelope.errorLanguage" => "en_US",
"emailAddress" =>"myemail@gmail.com",
"firstName" =>"Kunal",
"lastName" =>"Mahajan",
"matchCriteria" => "NAME"
);
$body_data = http_build_query($bodyparams, "", chr(38));
try{
$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); //create stream context
$fp = @fopen($url, "r", false, $ctx); //open the stream and send request
$response = stream_get_contents($fp); //get response
if ($response === false){
throw new Exception("php error message = " . "$php_errormsg");
}
fclose($fp); //close the stream
//parse the ap key from the response
$keyArray = explode("&", $response);
foreach ($keyArray as $rVal){
list($qKey, $qVal) = explode ("=", $rVal);
$kArray[$qKey] = $qVal;
}
echo "Header info:" . "<br>";
print_r($params['http']['header']);
echo "<br><br>" . "Request Info:" . "<br>";
print_r(urldecode($params['http']['content']));
echo "<br><br>" . "Response:" . "<br>";
if ( $kArray["responseEnvelope.ack"] == "Success"){
foreach ($kArray as $key =>$value) {
echo $key . ": " .$value . "<br/>";
}
}
else {
foreach ($kArray as $key =>$value){
echo $key . ": " .$value . "<br/>";
}
}
}catch(Exception $e)
{
echo "Message: ||" .$e->getMessage()."||";
}
答案 0 :(得分:0)
尝试使用
$response = file_get_contents($url, false, $ctx);
而不是
$fp = @fopen($url, "r", false, $ctx); //open the stream and send request
$response = stream_get_contents($fp); //get response
并改变这一点:
$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"
));
到此:
$params = array("http" => array(
"method" => "POST",
"content" => $body_data,
"header" =>
"X-PAYPAL-SECURIY-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" .
"Content-type: application/x-www-form-urlencoded\r\n"
));