2014-10-01 113 views
4

我使用貝寶自適應付款,我需要驗證商店/賣家給出的貝寶api的電子郵件地址,以便付款可以直接給客戶存儲。是否有效的貝寶電子郵件地址(PHP)

我想檢查一下,如果商店的電子郵件是一個有效的貝寶電子郵件地址,並且他/她已經註冊貝寶或不。

告訴我PayPal是否支持並允許應用程序訪問。

,也給我的示例代碼,請在PHP

+0

我認爲這些郵寄與DKIM簽名的,只是確認簽名 – rekire 2014-10-01 05:17:10

+0

發現了這個。 http://stackoverflow.com/questions/3640475/how-do-i-check-if-an-email-address-is-associated-with-a-paypal-account – blitzen12 2014-10-01 05:21:56

回答

6

是貝寶通過使用GetVerifiedStatus的」支持此功能「API你必須輸入電子郵件地址,名字和姓氏作爲所需的參數,它將返回如下響應:

Response: 
responseEnvelope.timestamp: 2014-10-01T01%3A17%3A10.081-07%3A00 
responseEnvelope.ack: Success 
responseEnvelope.correlationId: ce5a28138ca78 
responseEnvelope.build: 13068405 
accountStatus: VERIFIED 
userInfo.emailAddress: XXXXXXX 
userInfo.accountType: BUSINESS 
userInfo.accountId: XXXXXXXX 
userInfo.name.salutation: 
userInfo.name.firstName: Eshan+Business+Test 
userInfo.name.middleName: 
userInfo.name.lastName: Account 
userInfo.name.suffix: 
userInfo.businessName: Eshan+New+Business+Name 

您可以使用下面的PHP代碼此:

<?php 

    $url = trim("https://svcs.sandbox.paypal.com/AdaptiveAccounts/GetVerifiedStatus"); //set PayPal Endpoint to sandbox 
//$url = trim("https://svcs.paypal.com/AdaptiveAccounts/GetVerifiedStatus");   //set PayPal Endpoint to Live 

$API_UserName = "XXXXXXXXXXXXXXXXXXX";        //PayPal Test API Credentials, Replace it with live if in live mode 
$API_Password = "XXXXXXXXXXXXXXXXXXX"; 
$API_Signature = "XXXXXXXXXXXXXXXXXX"; 
$API_AppID = "APP-80W284485P519543T";          //Default App ID for Sandbox, replace it with live id if in live mode 
$API_RequestFormat = "NV"; 
$API_ResponseFormat = "NV"; 

//Create request payload 
$bodyparams = array ( "requestEnvelope.errorLanguage" => "en_US", 
         "emailAddress" =>"put email address to check ", 
         "firstName" =>"XXXXX", 
         "lastName" =>"XXXXXX", 
         "matchCriteria" => "NAME" 
        ); 

// convert payload array into url encoded query string 
$body_data = http_build_query($bodyparams, "", chr(38)); 

try 
{ 
    //create request and add headers 
    $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 

    //check to see if stream is open 
    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; 
    } 

//print the request to screen for testing purposes 
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>"; 

//print the response to screen for testing purposes 
    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()."||"; 
} 

echo "<br>"; 
?> 
+0

非常感謝親愛的,你已經解決了我的問題,再次感謝......... :) – 2014-10-02 13:28:52

+0

@eshan我得到這個錯誤 stream_get_contents()期望參數1是資源,布爾給定 – kunal 2017-08-22 11:26:33

+0

@Eshan你能解決我的問題嗎? – kunal 2017-08-23 07:19:44