如何检查PayPal电子邮件是否有效?



我卡在这个问题上,我想检查PayPal电子邮件ID是否经过验证,是否存在。我正在使用 laravel 5.2,我从堆栈溢出的这个答案中找到了代码:

是否为有效的PayPal电子邮件地址 (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 . "rn" .
"X-PAYPAL-SECURITY-SIGNATURE:  " . $API_Signature . "rn" .
"X-PAYPAL-SECURITY-PASSWORD:   " . $API_Password . "rn" .
"X-PAYPAL-APPLICATION-ID:      " . $API_AppID . "rn" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "rn" .
"X-PAYPAL-RESPONSE-DATA-FORMAT:" . $API_ResponseFormat . "rn" 
));
$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()."||";
}

尝试使用

$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 . "rn" .
"X-PAYPAL-SECURITY-SIGNATURE:  " . $API_Signature . "rn" .
"X-PAYPAL-SECURITY-PASSWORD:   " . $API_Password . "rn" .
"X-PAYPAL-APPLICATION-ID:      " . $API_AppID . "rn" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "rn" .
"X-PAYPAL-RESPONSE-DATA-FORMAT:" . $API_ResponseFormat . "rn" 
));

对此:

$params = array("http" => array( 
"method" => "POST",
"content" => $body_data,
"header" =>
"X-PAYPAL-SECURIY-USERID:     " . $API_UserName . "rn" .
"X-PAYPAL-SECURITY-SIGNATURE:  " . $API_Signature . "rn" .
"X-PAYPAL-SECURITY-PASSWORD:   " . $API_Password . "rn" .
"X-PAYPAL-APPLICATION-ID:      " . $API_AppID . "rn" .
"X-PAYPAL-REQUEST-DATA-FORMAT: " . $API_RequestFormat . "rn" .
"X-PAYPAL-RESPONSE-DATA-FORMAT:" . $API_ResponseFormat . "rn" .
"Content-type: application/x-www-form-urlencodedrn"
));

相关内容

最新更新