Сервисы в voip телефонах

Чтобы начать использовать сервисы в телефонах Cisco нужно в конфиг файл телефона добавить строки:

Для Cisco 7910(7911, 7941)^

1
<servicesurl>http://10.0.1.1/cisco/directory.php</servicesurl>

для 7940:

1
services_url: "http://10.0.1.1/cisco/directory.php"


где 10.0.1.1 – сервер с apache и php

Там я создал пару php скриптов спертых с http://www.voip-info.org/
directory.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?
  header("Content-type: text/xml");
  header("Connection: close");
  header("Expires: -1");
?> 
<CiscoIPPhoneMenu>
<Title>My_Firma</Title>
<Prompt>Kakoe-to privetstvie</Prompt>
<MenuItem>
<Name>Kyiv</Name>
<URL>http://10.0.1.1cisco/kyiv/kyiv.php</URL>
</MenuItem>
<MenuItem>
<Name>Odessa</Name>
<URL>http://10.0.1.1/cisco/odessa/odessa.php</URL>
</MenuItem>
<MenuItem>
<Name>Weather</Name>
<URL>http://10.0.1.1/cisco/weather.php</URL>
</MenuItem>
</CiscoIPPhoneMenu>

это просто для генерации корневого меню в котором можно глянуть номера телефонов двух филий либо посмотреть погоду.
файл с телефонным справочником должен отдавать xml с такой структурой:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?
  header("Content-type: text/xml");
  header("Connection: close");
  header("Expires: -1");
?> 
<CiscoIPPhoneDirectory>       
   <Title>Users</Title>
   <Prompt>People reachable via VoIP in my company</Prompt>                    
   <DirectoryEntry>                                              
      <Name>Aleksey xxxxxx</Name>         
      <Telephone>8050</Telephone>
   </DirectoryEntry>                                      
   <DirectoryEntry>             
      <Name>Nastya xxxxxx</Name>       
      <Telephone>8051</Telephone>                                            
   </DirectoryEntry>      
</CiscoIPPhoneDirectory>

Чтоб не мучатся с составлением списка телефонов – можно распарсить sip.conf
Вот примерно так выглядит парсер:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?
header("Content-type: text/xml");
header("Connection: close");
header("Expires: -1");
 // location of asterisk config files
 $location = "/var/www/"; # либо на ходу из /etc/asterisk/
 $dirname = "Company Directory";
 
  // parse sip.conf
  $sip_array = parse_ini_file($location."sip.conf", true);
  reset($sip_array);
 
 
echo "<CiscoIPPhoneDirectory>\n";
echo "<Title>".$dirname."</Title>\n";
echo "<Prompt>People reachable via VoIP</Prompt>  ";
 
 
    while (list($key, $val) = each($sip_array)) {
  if (isset($val["callerid"]))
	{echo "\n<DirectoryEntry>\n";
	$caller = substr($val["callerid"],0,strpos($val["callerid"],'<',4));
	echo  "<Name>".$caller."</Name>\n".
        "<Telephone>".$key."</Telephone>\n";
        echo "</DirectoryEntry>\n";
        }
    }
 
echo "\n<Prompt>Choose Name and Press Dial</Prompt>\n";
echo "</CiscoIPPhoneDirectory>\n";
?>

так получилось для моего конфига , если не подойдет – можно взять с voip-info пример и его помучать
Так-же можно в сервис всунуть прогноз погоды….
Я пока только тренируюсь, поэтому у меня стоит тестовый парсер погоды с yahoo, выглядит он примерно так:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?
  header("Content-type: text/xml");
    header("Connection: close");
      header("Expires: -1");
      ?>
<?php
 
class YahooWeather {
	// Ветер
	public $wind_chill;
	public $wind_direction;
	public $wind_speed;
 
	// Атмосферные показатели
	public $humidity;
	public $visibility;
	public $pressure;
 
	// Время восхода и заката переводим в формат unix time
	public $sunrise;
	public $sunset;
 
	// Текущая температура воздуха и погода
	public $temp;
	public $condition_text;
	public $condition_code;
 
	// Прогноз погоды на 5 дней
	public $forecast;
 
	public $units;
 
	function __construct($code, $units = 'c', $lang = 'en') {
		$this->units = ($units == 'c')?'c':'f';
 
		$url = 'http://xml.weather.yahoo.com/forecastrss?p='.
			$code.'&u='.$this->units;
 
		$xml_contents = file_get_contents($url);
		if($xml_contents === false) 
			throw new Exception('Error loading '.$url);
 
		$xml = new SimpleXMLElement($xml_contents);
		// Ветер
		$tmp = $xml->xpath('/rss/channel/yweather:wind');
		if($tmp === false) throw new Exception("Error parsing XML.");
		$tmp = $tmp[0];
 
		$this->wind_chill = (int)$tmp['chill'];
		$this->wind_direction = (int)$tmp['direction'];
		$this->wind_speed = (int)$tmp['speed'];
 
		// Атмосферные показатели
		$tmp = $xml->xpath('/rss/channel/yweather:atmosphere');
		if($tmp === false) throw new Exception("Error parsing XML.");
		$tmp = $tmp[0];
 
		$this->humidity = (int)$tmp['humidity'];
		$this->visibility = (int)$tmp['visibility'];
		$this->pressure = (int)$tmp['pressure'];
 
		// Время восхода и заката переводим в формат unix time
		$tmp = $xml->xpath('/rss/channel/yweather:astronomy');
		if($tmp === false) throw new Exception("Error parsing XML.");
		$tmp = $tmp[0];
 
		$this->sunrise = strtotime($tmp['sunrise']);
		$this->sunset = strtotime($tmp['sunset']);
 
		// Текущая температура воздуха и погода
		$tmp = $xml->xpath('/rss/channel/item/yweather:condition');
		if($tmp === false) throw new Exception("Error parsing XML.");
		$tmp = $tmp[0];
 
		$this->temp = (int)$tmp['temp'];
		$this->condition_text = strtolower((string)$tmp['text']);
		$this->condition_code = (int)$tmp['code'];
 
		// Прогноз погоды на 5 дней
		$forecast = array();
		$tmp = $xml->xpath('/rss/channel/item/yweather:forecast');
		if($tmp === false) throw new Exception("Error parsing XML.");
 
		foreach($tmp as $day) {
			$this->forecast[] = array(
				'date' => strtotime((string)$day['date']),
				'low' => (int)$day['low'],
				'high' => (int)$day['high'],
				'text' => (string)$day['text'],
				'code' => (int)$day['code']
			);
		}
	}
 
	public function __toString() {
		$u = "°".(($this->units == 'c')?'C':'F');
		return $this->temp.' '.$u.', '.$this->condition_text;
	}
}
 
?>
 
<?php
 
try {
	$weather = new YahooWeather('UPXX0016');
} catch(Exception $e) {
	echo "Caught exception: ".$e->getMessage();
	exit();
}
 
try {
	$weather1 = new YahooWeather('UPXX0021');
} catch(Exception $e) {
	echo "Caught exception: ".$e->getMessage();
	exit();
}
 
 
echo "
<CiscoIPPhoneText>
  <Title>Kyiv</Title>
    <Prompt>current temperature</Prompt>
      <Text> Now in Kyiv ".$weather->temp."C
      Now in Odessa ".$weather1->temp."C</Text>";
echo "</CiscoIPPhoneText>";
 
?>

В данном случае я показываю температуру для Киева и Одессы… если подправить, то можно получить отсюда погоду на 5 дней… ветер, влажность, облачность и т.д.

  1. No comments yet.

  1. No trackbacks yet.

You must be logged in to post a comment.