Php 使用wixhiverestapi创建Wix联系人
大家好 我正在为wix.com sitebuilder开发仪表板应用程序 我使用PHP来实现这一点。我尝试使用WixHive和restapi处理wix联系人 以下是有关这方面的文档:Php 使用wixhiverestapi创建Wix联系人,php,rest,velo,Php,Rest,Velo,大家好 我正在为wix.com sitebuilder开发仪表板应用程序 我使用PHP来实现这一点。我尝试使用WixHive和restapi处理wix联系人 以下是有关这方面的文档: http://dev.wix.com/docs/wixhive/contacts http://dev.wix.com/docs/wixhive/using-the-rest-api http://dev.wix.com/docs/wixhive/rest-api 不幸的是,wix没有php SDK。我基于这个非
http://dev.wix.com/docs/wixhive/contacts
http://dev.wix.com/docs/wixhive/using-the-rest-api
http://dev.wix.com/docs/wixhive/rest-api
不幸的是,wix没有php SDK。我基于这个非官方sdk创建了自己的类:
https://github.com/ransom1538/wix_php_sdk
获取单个联系人,联系人列表就像一个符咒
但协调接触不起作用
返回错误:
HTTP/1.1 401 Unauthorized
X-Seen-By: sputnik4.aus_dsp
Date: Tue, 01 Sep 2015 08:15:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Length: 83
Server: sputnik4.aus
{"errorCode":401,"message":"Bad authentication credentials.","wixErrorCode":-23004}
我使用本教程实现了签名:
http://dev.wix.com/docs/wixhive/using-the-rest-api#signature
我用这个工具检查了一下:
http://dev.wix.com/docs/infrastructure/signature-tool
我看到签名匹配
我的要求是:
URI:
https://openapi.wix.com/v1/contacts?version=2.0.0&application-id=13ffc79d-ceb8-df76-74e0-3de5b0f29b2d&instance-id=8c4c0505-370a-451b-bd9b-6667f955c26e×tamp=2015-09-01T12%3A11%3A41.477Z&signature=lkwqWrVFRCAhtpgGjqCn6v3TgUnakiIFKjMog41J-zQ
Method: POST
POST Data: {"emails":{"tag":"work","email":"karen_meep@wix.com","emailStatus":"recurring"}}
资料来源:
https://gist.github.com/antonshell/e92cb9cc57e7c8555d3a
在POST方法中提交json数据时。您应该在post请求中具有内容类型标头。因此,您的curl_请求方法将是
public function curl_request($method, $uri, $data = '')
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
if ($data != '') {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
} else {
curl_setopt($ch, CURLOPT_HEADER, TRUE);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 45);
if ('POST' == $method)
{
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
else if ('PUT' == $method)
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
else if('GET' != $method)
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
}
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$body = substr($response, $header_size);
return $body;
}将请求头
版本=2.0.0
更改为版本=1.0.0