Freeswitch + curl + capture

Retrieving data from html.
Example: Sim card balance on the IP Phone display.

Freeswitch XML Dialplan

Call code number «0007XX» and display sim card balance, where «0007XX» the Sim id in the database.

<extension name="000.a.curl">
    <condition field="destination_number" expression="^(000[7]\d{2})$">
	<action application="set"  data="ignore_display_updates=false"/>
        <action application="curl" data="http://192.168.0.2/ussd_curl.php headers post val=$1"/>
        <action application="info"/>
	<action application="capture" data="bal|${curl_response_data}|(balance:)(.*)"/>
	<param name="send-display-update" value="true"/>
	<action application="set" data="sip_callee_id_name=${bal[2]} "/>
	<action application="Answer"/>
	<action application="sleep" data="50000"/>
    </condition>
</extension>

ussd_curl.php

Get the data from the standard MySQL sms server table GOIP (http://118.142.51.162/update/).

MariaDB [goip]> describe USSD;
+-------------+------------------+------+-----+---------------------+-----------------------------+
| Field       | Type             | Null | Key | Default             | Extra                       |
+-------------+------------------+------+-----+---------------------+-----------------------------+
| id          | int(10) unsigned | NO   | PRI | NULL                | auto_increment              |
| TERMID      | varchar(64)      | NO   |     |                     |                             |
| USSD_MSG    | varchar(255)     | NO   |     |                     |                             |
| USSD_RETURN | varchar(255)     | NO   |     |                     |                             |
| ERROR_MSG   | varchar(64)      | NO   |     |                     |                             |
| INSERTTIME  | timestamp        | NO   |     | 0000-00-00 00:00:00 | on update CURRENT_TIMESTAMP |
| type        | int(11)          | NO   |     | 0                   |                             |
| card        | varchar(64)      | NO   |     | NULL                |                             |
| recharge_ok | tinyint(1)       | NO   |     | NULL                |                             |
+-------------+------------------+------+-----+---------------------+-----------------------------+

<?php
$mysqli = new mysqli("localhost", "goip", "goip", "goip");
$mysqli->set_charset('utf8');
$res = $mysqli->query("select TERMID, USSD_RETURN, max(INSERTTIME) as ltime from USSD where INSERTTIME >= DATE_SUB( NOW(), interval 24 hour) group by TERMID");
foreach( $res as $row) {
if ($row['USSD_RETURN'] == NULL) {
$ussdreturn = "timeout";
} else {
$ussdreturn = preg_replace('/[\s]+/', '_', $row['USSD_RETURN']);
$ussdreturn = preg_replace('/(.*r._|.*_p.|.*_р\.|\dр.).*/i','$1',$ussdreturn);
}
if ($_POST['val'] == $row['TERMID']) {
echo header('balance:'.urlencode($ussdreturn));
  }
}
$mysqli->close();
$res->free();
Только авторизованные участники могут оставлять комментарии.
  • blog/freeswitch_curl_capture.txt
  • Последние изменения: 2018/06/26