2012-10-12 59 views

回答

0

將以下代碼修改爲您的要求。它使用SugarCRM的SOAP API。

$user_name  = 'admin'; 
$user_password = 'admin'; 
$sugarcrm_url = 'http://example.com/' 
$options = array(
    "uri" => $sugarcrm_url, 
    "trace" => true 
); 

$offset = 0; 
$limit = 100; 

try { 
    $client = new SoapClient($sugarcrm_url.'service/v4_1/soap.php?wsdl', $options); 

    $response = $client->__soapCall('login',array(
    'user_auth'=>array(
     'user_name'=>$user_name, 
     'password'=>md5($user_password), 
     'version'=>'.01' 
    ), 
    'application_name'=>'SoapTest' 
)); 
    $session_id = $response->id; 

    $response = $client->__soapCall('get_entry_list',array(
    'session'=>$session_id, 
    'module_name'=>'Contacts', 
    'query'=>'', 
    'order_by'=>'contacts.last_name asc', 
    'offset'=>$offset, 
    'select_fields'=>array(), 
    'max_results'=>$limit) 
); 
    print_r($response); 

    $response = $client->__soapCall('get_entry_list',array(
    'session'=>$session_id, 
    'module_name'=>'Accounts', 
    'query'=>'', 
    'order_by'=>'accounts.name asc', 
    'offset'=>$offset, 
    'select_fields'=>array('id', 'name', 'email1'), 
    'max_results'=>$limit) 
); 
    print_r($response); 

    $response = $client->__soapCall('logout',array('session'=>$session_id)); 

} catch (Exception $ex) { 
    echo $ex->getMessage(); 
}