Last active
November 25, 2016 10:14
-
-
Save tanakahisateru/7524348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Salesforce Workflow Outboud message reciever sample in PHP | |
* | |
* requires: php-soap extension | |
* | |
* At 1st you should download WSDL of the message and put it besides this script. | |
*/ | |
$wsdl = __DIR__ . '/' . 'wfoutbound.xml'; | |
ini_set("soap.wsdl_cache_enabled", "0"); // clean WSDL for develop | |
function log_writeln($log) | |
{ | |
file_put_contents(__DIR__ . '/log/' . @date('Y-m-d') . '.log', $log . "\n", FILE_APPEND); | |
} | |
/** | |
* Salesforce Outbound Response type | |
*/ | |
class Response | |
{ | |
public $Ack; | |
function __construct($success) | |
{ | |
$this->Ack = $success; | |
} | |
public static function success() | |
{ | |
return new static(true); | |
} | |
public static function fail() | |
{ | |
return new static(false); | |
} | |
} | |
/** | |
* Bound request handler | |
*/ | |
function notifications($args=null) | |
{ | |
log_writeln(date('Y-m-d H:i:s')); | |
log_writeln(print_r($args, true)); | |
/* | |
You can get object via $args like below: | |
stdClass Object | |
( | |
[EnterpriseUrl] => https://ap.salesforce.com/services/Soap/c/29.0/00XXXXXXXXXXXX | |
[PartnerUrl] => https://ap.salesforce.com/services/Soap/u/29.0/00XXXXXXXXXXXX | |
[Notification] => stdClass Object | |
( | |
[Id] => 0XXXXXXXXXXXXXXXX (Notification ID) | |
[sObject] => stdClass Object | |
( | |
[Id] => 0XXXXXXXXXXXXXXX (Object ID) | |
... (Fields that you selected) | |
) | |
) | |
) | |
Your object would be in: $args->Notification->sObject; | |
*/ | |
// Success response | |
return Response::success(); | |
} | |
$server = new SOAPServer($wsdl); // Never link to Salesforce's WSDL URL | |
$server->addFunction('notifications'); | |
$req = file_get_contents('php://input'); | |
// log_writeln($req); | |
ob_start(); | |
$server->handle($req); | |
$resp = ob_get_clean(); | |
// log_writeln($resp); | |
echo $resp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I saw some messages sent with multiple Notification sections, so something like: