这是基础知识,哈哈,还需要其他功能解码
function updateItemPP($buttoncode, $amount, $item_name)
{
$API_USERNAME ="yourname";
$API_PASSWORD = "yourpassY";
$API_SIGNATURE = "yoursig";
$API_ENDPOINT = 'https://api-3t.paypal.com/nvp';
$VERSION = '60.0';
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL,$API_ENDPOINT);
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);
curl_setopt($ch, CURLOPT_POST, 1);
$nvpreq="USER=".urlencode($API_USERNAME)."&PWD=".urlencode($API_PASSWORD)."&SIGNATURE=".urlencode($API_SIGNATURE)."&VERSION=".urlencode($VERSION)."&METHOD=BMCreateButton&HOSTEDBUTTONID=".urlencode($buttoncode)."&BUTTONTYPE=BUYNOW&L_BUTTONVAR1=amount=".urlencode($amount)."&L_BUTTONVAR2=item_name=".urlencode($item_name);
echo "here is the request string:\n".$nvpreq;
curl_setopt($ch,CURLOPT_POSTFIELDS,$nvpreq);
$response = curl_exec($ch);
$response = urldecode($response);
echo "this is update response".$response;
$nvpResArray=$this->deformat($response);
$ack = ($nvpResArray["ACK"]);
$HostedButtonID=($nvpResArray["HOSTED_BUTTON_ID"]);
if ($ack=="FAILOR")
return "failor";
else
return $HostedButtonID;
}
这个函数不是我写的,而是另一个用户写的
static function deformat( $str )
{
$result = array();
while ( strlen( $str ) ) {
// postion of key
$keyPos = strpos( $str, '=' );
// position of value
$valPos = strpos( $str, '&' ) ? strpos( $str, '&' ): strlen( $str );
/*getting the Key and Value values and storing in a Associative Array*/
$key = substr( $str, 0, $keyPos );
$val = substr( $str, $keyPos + 1, $valPos - $keyPos - 1 );
//decoding the respose
$result[ strtoupper( urldecode( $key ) ) ] = urldecode( $val );
$str = substr( $str, $valPos + 1, strlen( $str ) );
//echo substr( $str, $valPos + 1, strlen( $str ) );
}
return $result;
}
这应该会有所帮助,但它也会返回一个新的按钮代码,因此请务必将其包含在页面上的按钮调用中