嘿,这个问题很老,但我设法将一个类放在一起,将记录添加到列表中,只需根据需要编辑您的字段名称。它使用 AddRecordtoList();
你可以在这里查看文档
class five9{
//the fields mapped to five9
//initialize and empty array so there are no errors with array_push
private static $listUpdateSettings = array("fieldsMapping" => array());
//maps field to five9 columns
protected function mapField($index, $field, $key = false){
//map the field to five9. Index must start at 1 not 0
//mapping fields this way allows flexibility in which order the parameter has its keys
array_push( self::$listUpdateSettings["fieldsMapping"], array( "columnNumber" => $index + 1, "fieldName" => $field, "key" => $key ));
}
//returns data array after being scrubbed
protected function checkArray( array $lead){
//data sent to five9
$data = array();
//counter
$i = 0;
//five9 requires the $field names outlined below
foreach($lead as $field => $value){
//make sure first_name is 3 characters or more
if( ($field == 'first_name' && strlen($field) > 3)){
//add field to array
$data[$i] = $value;
//map the field in five9
self::mapField($i, $field);
}
//make sure last_name is 3 characters or more
if($field == 'last_name' && strlen($field) > 3 ){
//add field to array
$data[$i] = $value;
//map the field in five9
self::mapField($i, $field);
}
//if the field is a phone number
if( $field == 'number1' ){
//add field to array
$data[$i] = preg_replace("/[^0-9]/", "", $value);
//map the field in five9
//this was they key for my instance
self::mapField($i, $field, true);
}
//if the field is a phone number
if( $field == 'number2' ){
//add field to array
$data[$i] = preg_replace("/[^0-9]/", "", $value);
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure the state is only two characters
if($field == 'state' && strlen($value) <= 2){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure the state is only two characters
if($field == 'zip' && strlen($value) <= 5){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure memberid is an int
if($field == 'member_id' && is_numeric($value)){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//increase the counter
$i++;
}
//return the data array that is constructed
return $data;
}
static function sendToFive9(array $lead ){
//the conctructed array
$data = self::checkArray($lead);
//if the fields sent are all correct both arrays are the same size
if(sizeof($lead) === sizeof($data) ){
// Import the WSDL and authenticate the user.-----------------------------
$wsdl_five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=$username";
//try to authenticate with five9
try{
$soap_options = array( 'login' => '$username',
'password' => '$password',
'trace' => true );
$client_five9 = new SoapClient( $wsdl_five9 , $soap_options );
}//if errors occur add the message to the response array
catch (Exception $e){
$error_message = $e->getMessage();
$response['error'] = $error_message;
}
//settings required by five9
self::$listUpdateSettings["skipHeaderLine"] = false;
self::$listUpdateSettings["cleanListBeforeUpdate"] = false;
self::$listUpdateSettings["crmAddMode"] = 'ADD_NEW';
self::$listUpdateSettings["crmUpdateMode"] = 'UPDATE_SOLE_MATCHES';
self::$listUpdateSettings["listAddMode"] = 'ADD_IF_SOLE_CRM_MATCH';
//the default list for all new leads
$list = "test";
//prepare the query used to add the record to five9
$query = array ( 'listName' => "$list",
'listUpdateSettings' => self::$listUpdateSettings,
'record' => $data );
//get the result from running the query
//this will return an object
$result = $client_five9->AddRecordToList($query);
//get the array of variables within the results object
$variables = get_object_vars($result);
//get the array of varaibles within the return array of objects
$resp = get_object_vars($variables['return']);
//if there was an error adding the record
if($resp['failureMessage'] != ""){
$response['errors'] = $resp['failureMessage'];
}
//if it was successful either adding or updating
if($resp['crmRecordsUpdated'] == 1 || $resp['crmRecordsInserted'] == 1){
$response['success'] = true;
//reset the settings array so this class can be looped without passing the lists back and forth
self::$listUpdateSettings = array("fieldsMapping" => array());
}
}//end if
else{
//return the differences in the arrays usually caused due to improper names
$reponse["errors"] = array_diff($lead, $data);
}
return $response;
}//end function
}