Zoho 响应返回 false

Zoho response returning false

我创建这个 class 是为了让使用 zoho 更容易,据我所知一切都是正确的

<?
    class ZohoWebAPI {
        private $credentials = array(
            "authtoken" => ''
        );

        private $URLS = array(
            "Base" => "https://crm.zoho.com/crm/private/xml/",
            "Contacts" => "Contacts/",
            "Leads" => "Leads/"
        );

        private $methods = array(
            "Insert" => "insertRecords",
            "Update" => "updateRecords",
            "Get" => "getRecords"
        );

        function GetNewAuthToken($loginInfo){
            $url = "https://accounts.zoho.com/apiauthtoken/nb/create?SCOPE=ZohoCRM/crmapi&EMAIL_ID=".$loginInfo['Email']."&PASSWORD=".$loginInfo['Password']."&DISPLAY_NAME=" . $loginInfo['Display_Name'];
            $ch = curl_init($url);
            # Setting our options
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            # Get the response
            $response = curl_exec($ch);
            curl_close($ch);
            $returnArray = explode(" ",$response);
            $res = explode("=",$returnArray[5]);
            $stripToken = str_replace("RESULT","",$res[1]);
            return array(
                "AuthToken" => $stripToken,
                "Result" => $res[2]
            );
        }

        function SetAuthToken($token){
            $this->credentials["authtoken"] = $token;
        }

        function GenerateXML($path,$dataArray){
            $path = strtolower($path);

            $xmlData = '';

            switch($path){
                case "contacts":
                    $xmlData .= "<Contacts>";
                    break;
                case "leads":
                    $xmlData .= "<Leads>";
                    break;
            }

            $xmlData .= "<row no='1'>";

            for($i = 0; $i < count($dataArray);$i++){
                $xmlData .= "<FL val='".$dataArray[$i][0]."'>".$dataArray[$i][1]."</FL>";
            }

            $xmlData .= "</row>";

            switch($path){
                case "contacts":
                    $xmlData .= "</Contacts>";
                    break;
                case "leads":
                    $xmlData .= "</Leads>";
                    break;
            }

            return $xmlData;
        }

        function CreateNewContact($xmlData){
            $apiUrl = $URLS["Base"] . $URLS["Contacts"] . $methods["Insert"];
            $postData = "authtoken" . $credentials["authtoken"] . "&scope=crmapi&xmldata=" . $xmlData;

            return $this->SendDataToZoho($apiUrl,$postData);
        }

        function SendDataToZoho($apiUrl,$postData){
            $ch = curl_init($apiUrl);
            # Setting our options
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            # Get the response
            $response = curl_exec($ch);
            curl_close($ch);

            return $response;
        }
    }
?>

使用这个新的 class 我有另一个看起来像这样的文件

<?
    require_once("zohoapiwrapper.php");

    $zoho = new ZohoWebAPI();

    $zoho->SetAuthToken("a9xxxxxxxxxxxxxxxxxxxxxxxxxxx");

    $dataArray = array(
        array("FirstName","Joseph"),
        array("Last Name","Williamson"),
        array("Email","Testemail@gamilll.com")
    );

    $xml = $zoho->GenerateXML("contacts",$dataArray);

    $result = $zoho->CreateNewContact($xml);

    $responseData = simplexml_load_string($result);

    var_dump($responseData);
?>

当 运行ning 代码时,它说 (bool)false 根据我的理解,通过将联系人添加到 crm url [=39 的方法,这没有意义=] 一个 xml 文档,它将存储在 class SendDataToZoho()

中的 $response

所以在行 return $this->SendDataToZoho($apiUrl,$postData); 上,我期待一个 xml 响应,然后可以对其进行解析以查看数据是否已成功插入 zoho。但是我不明白 (bool)flase 是从哪里来的,因为如果我将 url 放在浏览器中并将生成的 XML 运行 放入其中,我会收到来自浏览器的 xml 响应

我很困惑,不知道为什么它会以这种方式运行

编辑:

正在将我的 SendToZoho 函数更改为此

function SendDataToZoho($apiUrl,$postData){
            $ch = curl_init($apiUrl);
            # Setting our options
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            # Get the response
            $response = curl_exec($ch);
            $oh1 = curl_error($ch);
            $oh2 = curl_errno($ch);
            curl_close($ch);

            var_dump($oh1 . " " . $oh2);

            return $response;
        }

这是输出 string(17) " malformed 3" bool(false)

尝试替换下一个函数:

function CreateNewContact($xmlData){
    $apiUrl = $URLS["Base"] . $URLS["Contacts"] . $methods["Insert"];
    $postData = "authtoken" . $credentials["authtoken"] . "&scope=crmapi&xmldata=" . $xmlData;

    return $this->SendDataToZoho($apiUrl,$postData);
}

有了这个:

function CreateNewContact($xmlData){
    $apiUrl = $this->URLS["Base"] . $this->URLS["Contacts"] . $this->methods["Insert"];
    $postData = "authtoken" . $this->credentials["authtoken"] . "&scope=crmapi&xmldata=" . $xmlData;

    return $this->SendDataToZoho($apiUrl,$postData);
}

问题是如果你想引用一个对象的 属性 - 你应该使用 $this - 对你的对象的引用。