1

大家。

我正在为 wix.com 网站构建器开发仪表板应用程序。

我为此使用 PHP。我尝试使用 WixHive 和 Rest API 处理 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。我基于这个非官方的 sdk 创建了自己的类:

https://github.com/ransom1538/wix_php_sdk

获取单个联系人和联系人列表就像一个魅力。

但是 reconcileContact 不起作用。

返回这样的错误:

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&timestamp=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
4

2 回答 2

1

将请求标头更改version=2.0.0version=1.0.0

于 2016-07-11T22:56:23.983 回答
0

当您在 POST 方法中提交 json 数据时。您应该在发布请求中有内容类型标头。所以你的 curl_request 方法将是

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;

}

于 2015-10-24T05:41:55.663 回答