肥皂,打电话给恢复服务

时间:2015-02-10 11:17:03

标签: php web-services soap wsdl salesforce

我是SOAP新手。对于项目,我需要使用“Force.com Toolkit for PHP”。

我第一次打电话打开Salesforce会话并检索会话ID,该会话ID将用于调用客户信息的恢复服务。 (没关系,我有ID会话)

我知道客户信息流是使用第一次通话获得的会话ID调用的,但我不知道如何进行第二次通话!我还有另一个WSDL文件(CallInListCustomer.wsdl.xml)

我也是客户信息流地址(在WSDL中找到)。我不确定,但我必须以“后期”格式打电话......

你可以帮帮我吗?

<?php
session_start();

define("USERNAME", "my_username");
define("PASSWORD", "my_password");
define("SECURITY_TOKEN", "my_token");

require_once ('soapclient/SforcePartnerClient.php');

$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection("Partner.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

// Now we can save the connection info for the next page
$_SESSION['location'] = $mySforceConnection->getLocation();
$_SESSION['sessionId'] = $mySforceConnection->getSessionId();

$sessionId = $_SESSION['sessionId'];

echo $sessionId;

// Here, i don't know how to call the recovery service of customer information with allInListCustomer.wsdl.xml

?>

全部谢谢

2 个答案:

答案 0 :(得分:0)

这是我的代码。

创建单独的文件以存储salesforce组织详细信息。

SFConfig.php

<?php
/*----------------------------------------------------------------
 *    We will define salesforce user anem and password with token.
 *    This file we used / include in every time when we need to 
 *    communicate withy salesforce.  
 * ---------------------------------------------------------------*/

$USERNAME = "Your salesforce user name";
$PASSWORD = "Your password with security token";
?>

从salesforce获取帐户数据

GetAccountData.php

<?php
	// SET SOAP LIB DIRCTORY PATH
	define("SOAP_LIB_FILES_PATH", "/<Put Your file location>/soapclient");
	// Access sf config file
	require_once ('/<Put Your file location>/SFConfig.php');
	
	// Access partner client php lib file
	require_once (SOAP_LIB_FILES_PATH.'/SforcePartnerClient.php');
	
	try {
		echo "\n******** Inside the try *******\n";
		
		// Sf connection using ( SOAP ) partner WSDL
		$mySforceConnection = new SforcePartnerClient();
		$mySforceConnection->createConnection(SOAP_LIB_FILES_PATH.'/YourWSDLName.wsdl.xml');
		$mySforceConnection->login($USERNAME, $PASSWORD);
		
		echo "\n******** Login with salesforce is done *******\n";
		
		
		
		// query for featch Versand data with last run datetime
		$query = "SELECT Id, Name
				  FROM Account;
		
		
		
		
		// Send query to salesforce
		$response = $mySforceConnection->query($query);
		// Store the query result
		$queryResult = new QueryResult($response);
		
		$isError = false ;
		echo "Results of query '$query'<br/><br/>\n";
		// Show result array
		for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {
			$record = $queryResult->current();
			// Id is on the $record, but other fields are accessed via
			// the fields object
			echo "\nVersand value : ".$record->Abmelder__c."\n";
			
		}
		
			
	} catch (Exception $e) {
		$GLOBALS['isTimeEnter'] = true;
		echo "entered catch****\n";
		echo "Exception ".$e->faultstring."<br/><br/>\n";
		
		
	}
?>

此外,如果您想调用其他服务,则只需使用上面的“$ mySforceConnection”变量进行调用。

例如:(创建联系人)

$records = array();

$records[0] = new SObject();
$records[0]->fields = array(
    'FirstName' => 'John',
    'LastName' => 'Smith',
    'Phone' => '(510) 555-5555',
    'BirthDate' => '1957-01-25'
);
$records[0]->type = 'Contact';

$records[1] = new SObject();
$records[1]->fields = array(
    'FirstName' => 'Mary',
    'LastName' => 'Jones',
    'Phone' => '(510) 486-9969',
    'BirthDate' => '1977-01-25'
);
$records[1]->type = 'Contact';

$response = $mySforceConnection->create($records);

$ids = array();
foreach ($response as $i => $result) {
    echo $records[$i]->fields["FirstName"] . " "
            . $records[$i]->fields["LastName"] . " "
            . $records[$i]->fields["Phone"] . " created with id "
            . $result->id . "<br/>\n";
    array_push($ids, $result->id);
}

请查看以下链接了解更多详情: https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Toolkit_for_PHP

答案 1 :(得分:0)

我找到了解决方案,这里是我的代码:

<?php
// salesforce.com Username, Password and TOken
define("USERNAME", "My_username");
define("PASSWORD", "My_password");
define("SECURITY_TOKEN", "My_token");

// from PHP-toolkit ( https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Toolkit_for_PHP )
require_once ('soapclient/SforcePartnerClient.php');

$mySforceConnection = new SforcePartnerClient();
$mySforceConnection->createConnection("Partner.wsdl.xml");
$mySforceConnection->login(USERNAME, PASSWORD.SECURITY_TOKEN);

// I Get the IDSESSION
$sessionId = $mySforceConnection->getSessionId();

// I create a new soapClient with my WSDL
$objClient = new SoapClient("my_service.wsdl.xml", array('trace' => true));

// I create the header
$strHeaderComponent_Session = "<SessionHeader><sessionId>$sessionId</sessionId></SessionHeader>";
$objVar_Session_Inside = new SoapVar($strHeaderComponent_Session, XSD_ANYXML, null, null, null);
$objHeader_Session_Outside = new SoapHeader('https://xxxxx.salesforce.com/services/Soap/class/myservice', 'SessionHeader', $objVar_Session_Inside);
$objClient->__setSoapHeaders(array($objHeader_Session_Outside));

// i call the service
$objResponse = $objClient->getinfo(array ( 'Zone' => "123456"));

// here i get the result in Json
$json = json_encode( (array)$objResponse);
echo $json;
?>