我正在尝试帮助客户允许用户将数据从他的网站填充到另一家公司的网站。拥有服务器的网站是 DialMyCalls,他们提供了一个 PHP 类来与他们的服务器通信。我无法使用它与他们进行实际交流,因为我不明白我需要编辑哪些字段。
我有 API 密钥和另一个代码片段来添加联系人,我想知道是否有人可以指导我完成使此代码正常工作需要做的事情。我在哪里放置代码的“添加联系人”部分以实际运行它并查看它是否填充在数据库中。我可以提供您可能需要的任何信息。
以下 PHP 类来自API 提供者。
<?php
class RestRequest
{
protected $url;
protected $verb;
protected $requestBody;
protected $requestLength;
protected $apikey;
protected $acceptType;
var $responseBody;
protected $responseInfo;
public function __construct ($apikey = null) {
$this->url = null;
$this->verb = null;
$this->requestBody = null;
$this->requestLength = 0;
$this->apikey = $apikey;
$this->acceptType = 'application/json';
$this->responseBody = null;
$this->responseInfo = null;
}
public function flush ()
{
$this->requestBody = null;
$this->requestLength = 0;
$this->verb = 'POST';
$this->responseBody = null;
$this->responseInfo = null;
}
public function execute ($url = null, $verb = 'POST', $requestBody = null) {
$ch = curl_init();
$this->url = "https://www.dialmycalls.com/api".$url;
$this->verb = $verb;
$this->requestBody = $requestBody;
try
{
switch (strtoupper($this->verb))
{
case 'POST':
$this->doExecute($ch);
break;
default:
throw new InvalidArgumentException('Current verb (' . $this->verb . ') is an invalid REST verb.');
}
}
catch (InvalidArgumentException $e)
{ curl_close($ch);
throw $e;
}
catch (Exception $e)
{
curl_close($ch);
throw $e;
}
}
protected function doExecute (&$curlHandle) {
curl_setopt($curlHandle, CURLOPT_POST, 1);
$this->requestBody["apikey"] = $this->apikey;
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $this->requestBody);
// curl_setopt($curlHandle, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandle, CURLOPT_URL, $this->url);
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curlHandle, CURLOPT_VERBOSE, 0);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array ('Accept: ' . $this->acceptType,'Expect:'));
$this->responseBody = curl_exec($curlHandle);
$this->responseInfo = curl_getinfo($curlHandle);
curl_close($curlHandle);
}
}
?>
PHP 添加联系人
for($i=1;$i<=5;$i++) {
$nums[] = array(
"phone"=>"832201111".$i,
"firstname"=>"just",
"lastname"=>"testing",
);
}
$request->execute(
"/1-0/AddContact/",'POST',
array("names"=>json_encode($nums))
);