让我设置场景:
我是一名PHP开发人员,需要从web表单中获取信息并将其发送到客户端Salesforce。起初,我觉得它就像使用Web2Lead一样简单。然而,客户内部有一名Salesforce开发人员。
内部开发人员已经将partner.wsdl
和CatalystWebservice.wsdl
文件以及登录详细信息发送到他们的沙箱中,以便在上面运行所有这些。内部开发人员基本上说我需要使用Salesforce的SOAP API,一旦连接并登录,我需要调用->makeContact("FormField1", "FormField2", "etc...");
所以,在花了一整天的时间尝试了很多事情,遇到了很多问题之后,我终于遇到了一堵我无法攀登的墙。这是我现在的PHP代码:
<pre>
<?php
define("SOAP_CLIENT_BASEDIR", "../soapclient");
$USERNAME = '******@********' ;
$PASSWORD = '******************************' ;
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceHeaderOptions.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner2.wsdl.xml');
$loginResult = $mySforceConnection->login($USERNAME, $PASSWORD);
$location = $mySforceConnection->getLocation();
$session_ID = $mySforceConnection->getSessionId();
$client = new SoapClient(SOAP_CLIENT_BASEDIR.'/CatalystWebservice.wsdl.xml');
$sforce_header = new SoapHeader("http://soap.sforce.com/schemas/class/CatalystWebservice", "SessionHeader", array( "sessionId" => $session_ID ) );
$client->__setSoapHeaders( array( $sforce_header ) );
$client->makeContact("*****", "*****", "Address1", "Address2", "London", "****", "no-one@****", "0123456789", "07891236456", "New Build Homebuy", "This is my question'n'nAnd an other line", "1", "Test");
} catch (Exception $e) {
print_r($e);
}
?>
</pre>
我在这里标出了敏感信息。当我运行上面的代码时,我得到以下输出:
SoapFault Object
(
[message:protected] => UNKNOWN_EXCEPTION: An unexpected error occurred. Please include this ErrorId if you contact support: ***********-*** (***********)
[string:Exception:private] =>
[code:protected] => 0
[file:protected] => /home/******/public_html/********/test/partner.php
[line:protected] => 23
[trace:Exception:private] => Array
(
[0] => Array
.....
和CatalystWebservices.wsdl.xml文件
内部开发人员在C#中开发了一些东西来测试他的WebService,它运行得很好,所以这一定是我做得不对的地方。我做错了什么?
我找到了解决方案。。。我必须确保我将数据作为一个关联数组发送,如下所示:
$response = $client->makeContact
(
array
(
"sLastName" => (string) $wpcf7_data->posted_data['last-name'],
"sFirstName" => (string) $wpcf7_data->posted_data['first-name'],
"sAddress1" => (string) $wpcf7_data->posted_data['address-one'],
"sAddress2" => (string) $wpcf7_data->posted_data['address-two'],
"sCity" => (string) $wpcf7_data->posted_data['town-city'],
"sPostcode" => (string) $wpcf7_data->posted_data['post-code'],
"sEmail" => (string) $wpcf7_data->posted_data['email-address'],
"sPhone" => (string) $wpcf7_data->posted_data['telephone'],
"sMobile" => (string) "",
"sEnquiries" => (string) $wpcf7_data->posted_data['enquiry'],
"sComment" => (string) $wpcf7_data->posted_data['comments'],
"sPropertyID" => (string) wpcf7_special_mail_tag_for_post_data( "", "_post_id" ),
"sPropertyName" => (string) wpcf7_special_mail_tag_for_post_data( "", "_post_title" ),
)
);