public function actionCall2() { try { $api = new PhpSIP(); // IP we will bind to $api->setUsername('118338'); // authentication username $api->setPassword('55XI8N'); // authentication password $api->setProxy('202.153.128.34'); $api->addHeader('Event: resync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:118338@voiprakyat.or.id'); $api->setUri('sip:118339@voiprakyat.or.id'); $res = $api->send(); echo "res1: {$res}\n"; } catch (Exception $e) { echo $e->getMessage() . "\n"; } }
<?php require_once 'PhpSIP.class.php'; /* Sends NOTIFY to reset Linksys phone */ try { $api = new PhpSIP(); $api->setUsername('10000'); // authentication username $api->setPassword('secret'); // authentication password // $api->setProxy('some_ip_here'); $api->addHeader('Event: resync'); $api->setMethod('NOTIFY'); $api->setFrom('sip:10000@sip.domain.com'); $api->setUri('sip:10000@sip.domain.com'); $res = $api->send(); echo "response: {$res}\n"; } catch (Exception $e) { echo $e; }
function _call($params) { $user = $params['user']; $mysip = self::get_sip_info($user->id); $user_to = PresenceController::_userstr($params['callee']); if ($user_to) { // They want to call another user, so grab SIP data for target user. $sip = self::get_sip_info($user_to->id); $to = 'sip:' . $sip->ext . '@' . $sip->domain; } elseif (preg_match('/^[-0-9]+$/', $params['callee'])) { // Valid dial string. $to = 'sip:' . $params['callee'] . '@' . $mysip->domain; } else { // Invalid! self::notify($user, 'You can call a chat user or a phone number (only numbers or dashes).'); } if (isset($to)) { // MAKE THE CALL! try { include 'php-sip/PhpSIP.class.php'; $from = "sip:{$mysip->ext}@{$mysip->domain}"; $api = new PhpSIP(); $agent = "sip:{$mysip->user}@{$mysip->domain}"; $api->setUsername($mysip->user); $api->setPassword($mysip->pass); // First get the initiator on the line. self::notify($user, "Calling you first..."); $api->setMethod('INVITE'); $api->setFrom($agent); $api->setUri($from); switch ($api->send()) { case 200: // Initiator answered, so now we ring the other guy. if ($user_to) { self::notify($user_to, ($user->nickname ? $user->nickname : $user->name) . ' is calling you!'); } $api->setMethod('REFER'); $api->addHeader("Refer-to: {$to}"); $api->addHeader("Referred-By: {$agent}"); $api->send(); // Let those guys talk, get out of dodge. $api->setMethod('BYE'); $api->send(); $api->listen('NOTIFY'); $api->reply(481, 'Call Leg/Transaction Does Not Exist'); break; default: self::notify($user, "You didn't answer!"); } } catch (Exception $e) { try { $api->setMethod('CANCEL'); $api->send(); self::notify($user, 'Error placing call!'); } catch (Exception $e) { self::notify($user, 'Error placing call, and another error cleaning up!'); } } } return true; }