我们正在尝试使用PHP与Xero集成。看来我们一直在尝试使用以下代码添加简单的联系人:
到目前为止我们还没有做什么:
到目前为止,以下代码已用于此post函数。如果任何人都可以在第一步中帮助我们,那将是非常有帮助的。
$url_xero = 'https://api.xero.com/api.xro/2.0/Contacts';
$data = "{ \r\n Name: HFG Limited \r\n }";
$data_json = json_encode($data);
$consumer = new OAuthConsumer($xero_consumer_key, $xero_consumer_secret);
$access_token2 = new OAuthToken($oauth_token_final, $oauth_token_secret_final);
$request = OAuthRequest::from_consumer_and_token($consumer,
$access_token2,'POST', $url_xero, array('Content-Type: application/json','Content-Length: ' . strlen($data_json)));
$request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $access_token2);
$headers = array($request->to_header());
$ch = curl_init();
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url_xero);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$rsp = curl_exec($ch);
$info = curl_getinfo($ch);
$results = json_decode($rsp);
if ($rsp === false) {
throw new Exception(curl_error($ch), curl_errno($ch));
}