最初に言いたいのは、私は PHP の初心者であり、私のコードは控えめに言っても効率的ではありません。
私が現在抱えている問題は、いくつかのフィールド名の値を取得して変数に割り当てる方法で CURL 応答を解析したいということです。変数を取得したら、いくつかのフィールドを顧客に表示し、いくつかのフィールドをデータベースに表示します。PayPal の API を使用しているため、どのフィールドが返されるかはわかっていますが、応答からそれらを「取得」する方法がわかりません。
これが私が現在使用しているスクリプトです。これもあまり効率的ではありませんが、CURL リクエストの後でスタックしています。どんな助けでも大歓迎です!!
<?php
include_once "constants.php";
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$wppro = "$key=$value";
}
$ipaddress = "216.113.168.139";
$creditcardtype = $_POST["creditcardtype"];
$acct = $_POST["acct"];
$expmo = $_POST["expmo"];
$expyear = $_POST["expyear"];
$cvv = $_POST["cvv"];
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$street = $_POST["street"];
$street2 = $_POST["street2"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$countrycode = $_POST["countrycode"];
$amt = $_POST["amt"];
$expdate = $expmo . $expyear;
$method = "DoDirectPayment";
$nvp = "version=$version&method=$method&user=$api_user&pwd=$api_pwd&signature=$api_sig&ipaddress=$ipaddress&$creditcardtype=$creditcardtype&acct=$acct&expdate=$expdate&cvv=$cvv&firstname=$firstname&lastname=$lastname&street=$street&street2=$street2&city=$city&state=$state&zip=$zip&countrycode=$countrycode&amt=$amt";
$ch = curl_init(); // Starts the curl handler
curl_setopt($ch, CURLOPT_URL,$sburl); // Sets the paypal address for curl
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // Returns result to a variable instead of echoing
curl_setopt($ch, CURLOPT_TIMEOUT, 60); // Sets a time limit for curl in seconds (do not set too low)
curl_setopt($ch, CURLOPT_POST, 1); // Set curl to send data using post
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp); // Add the request parameters to the post
$httpResponse = curl_exec($ch); // run the curl process (and return the result to $result
curl_close($ch);
ありがとうございました、
マット