获取403 Forbidden Error在创建时使用API​​在Bluesnaps上创建购物者实体

时间:2015-08-25 18:18:50

标签: php xml curl bluesnap

我正在尝试使用其API在Bluesnaps上创建一个购物者实体,但我无法做到这一点。

这是网址: http://shimion.com/create-shopper.php?firstName=bob&lastName=Smith&email=bob.Smith@gmail.com&address1=123%20Main%20Street&address2=Apt%20K-9&city=Parkville&state=TN&country=us&phone=411-555-1212&zipcode=37027

这是代码:

 function get_shopper_from_header($ch, $string) {
$firstName = htmlspecialchars($_REQUEST['firstName']);           
$lastName  = htmlspecialchars($_REQUEST['lastName']);             
$email     = htmlspecialchars($_REQUEST['email']);     
$address1  = htmlspecialchars($_REQUEST['address1']);
$address2  = htmlspecialchars($_REQUEST['address2']);
$city      = htmlspecialchars($_REQUEST['city']);
$state     = htmlspecialchars($_REQUEST['state']);
$country   = htmlspecialchars($_REQUEST['country']);
$zipCode   = htmlspecialchars($_REQUEST['zipcode']);
$phone     = htmlspecialchars($_REQUEST['phone']);
$credentials = $username.':'.$password;
$firstName = 'Bob';
$lastName = 'Smith';
$email = "bob.smith@plimus.com";
$address1 = "123 Main Street";
$address2 = "Apt K-9";
$city = "Parkville";
$state = "TN";
$country = "us";
$zipCode = "37027";
$phone = "411-555-1212";
$xmlToSend = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
<shopper xmlns=\"http://ws.plimus.com\">
<shopper-info>
<shopper-contact-info>
<first-name>". $firstName ."</first-name>
<last-name>". $lastName ."</last-name>
<email>". $email ."</email>
<address1>". $address1 ."</address1>
<city>". $city ."</city>
<zip>". $zipCode ."</zip>
<country>". $country ."</country>
<state>". $state ."</state>
<phone>". $phone ."</phone>
</shopper-contact-info>
<locale>en</locale>
</shopper-info>
<web-info>
<ip>62.219.121.253</ip>
<remote-host>bzq-219-121-253.static.bezeqint.net.reinventhosting.com</remote-host>
<user-agent>Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; GTB6.3; .NET CLR 2.0.50727</user-agent>
<accept-language>en-us</accept-language>
</web-info>
</shopper>";
$service = 'https://sandbox.plimus.com/services/2/shoppers';
$contentType = array('Content-type: application/xml');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $service);
curl_setopt($ch, CURLOPT_USERPWD, $credentials);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlToSend);
curl_setopt($ch, CURLOPT_HTTPHEADER, $contentType);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'get_shopper_from_header');
$response = curl_exec($ch);
if ( curl_errno($ch) ) {
echo 'HTTP error code: ' . curl_errno($ch) . '<br>error-message: "' . curl_error($ch) . '"';
return;
}
if (is_numeric($shopper_id)) {
echo '<br>
A new shopper entity was created on our servers with shopper-id: '
. $shopper_id .
'<br><br>';
}
else {
echo '<br><br>
<font color="red"><b>Something went wrong!</b></font>
<br>
Server reponse:
<br><br>
<pre style="display: block; font-family: monospace; white-space: pre; margin: 1em 0px;">'
. $response .
'</pre><br>';
}
?>

1 个答案:

答案 0 :(得分:0)

如果你从localhost使用它而不是它不工作,你也需要ssl,openssl for localhost。
如果您正在使用它,您需要添加IP地址作为您的服务器IP地址,并且您必须在一般设置中在您的bluesnap帐户中添加该IP地址。