java实现语⾳外呼,基于freeswitch⾃动外呼系统实现(⼀)_呼
叫中⼼_⼈⼯智能_。。。
15年基于freewitch做的⾃动呼系统,主要由监听模块,任务外呼模块,及FIFO实现。
1、mod_cctask.c#include
mutex error#include
#define zstr(x) _zstr(x)
SWITCH_MODULE_LOAD_FUNCTION(mod_cctask_load);
SWITCH_MODULE_RUNTIME_FUNCTION(mod_cctask_runtime);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cctask_shutdown);
SWITCH_MODULE_DEFINITION(mod_cctask, mod_cctask_load, mod_cctask_shutdown, mod_cctask_runtime);
switch_api_interface_t *api_interface;
static struct {
switch_hash_t *caller_orig_hash;
switch_hash_t *consumer_orig_hash;
switch_hash_t *bridge_hash;
switch_hash_t *use_hash;
switch_mutex_t *use_mutex;
switch_mutex_t *caller_orig_mutex;
switch_mutex_t *consumer_orig_mutex;
switch_mutex_t *bridge_mutex;
switch_hash_t *fifo_hash;
switch_mutex_t *mutex;
switch_mutex_t *sql_mutex;
switch_memory_pool_t *pool;
int running;
switch_event_node_t *node;
char hostname[256];
char *dbname;
char odbc_dsn[1024];
int node_thread_running;
switch_odbc_handle_t *master_odbc;
int threads;
switch_thread_t *node_thread;
int debug;
struct fifo_node *nodes;
char *pre_trans_execute;
char *post_trans_execute;
char *inner_pre_trans_execute;
char *inner_post_trans_execute;
switch_sql_queue_manager_t *qm;
int allow_transcoding;
switch_bool_t delete_all_members_on_startup;
} globals;
struct callback {
char *buf;
size_t len;
int matches;
};
typedef struct callback callback_t;
struct cc_cctask_call_obj {
char task_id[32];
char gateway[64]; //⽹关
char exten[64];//分机
char context[64];//context区分
char cid_name[64];//主叫
char cid_num[64];//主叫号码
char fifo_name[64];
};
typedef struct cc_cctask_call_obj cctask_call_obj; switch_cache_db_handle_t *cctask_get_db_handle(void) {
switch_cache_db_handle_t *dbh = NULL;
char *dsn;
if (!zstr(globals.odbc_dsn)) {
dsn = globals.odbc_dsn;
} else {
dsn = globals.dbname;
}
if (switch_cache_db_get_db_handle_dsn(&dbh, dsn) != SWITCH_STATUS_SUCCESS) {
dbh = NULL;
}
return dbh;
}
static switch_bool_t cctask_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, vo
{
switch_bool_t ret = SWITCH_FALSE;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = cctask_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
if (globals.debug > 1) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "sql: %s\n", sql);
switch_cache_db_execute_sql_callback(dbh, sql, callback, pdata, &errmsg);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
free(errmsg);
}
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return ret;
}
char *cc_execute_sql2str(switch_mutex_t *mutex, char *sql, char *resbuf, size_t len)
{
char *ret = NULL;
char *errmsg = NULL;
switch_cache_db_handle_t *dbh = NULL;
if (mutex) {
switch_mutex_unlock(mutex);
}
if (!(dbh = cctask_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
if (errmsg) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg); free(errmsg);
}
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return ret;
}
static switch_status_t cc_execute_sql(char *sql, switch_mutex_t *mutex)
{
switch_cache_db_handle_t *dbh = NULL;
switch_status_t status = SWITCH_STATUS_FALSE;
if (mutex) {
switch_mutex_lock(mutex);
}
if (!(dbh = cctask_get_db_handle())) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
goto end;
}
status = switch_cache_db_execute_sql(dbh, sql, NULL);
end:
switch_cache_db_release_db_handle(&dbh);
if (mutex) {
switch_mutex_unlock(mutex);
}
return status;
}
//从⼦表获取外呼数据
static int sql2str_callback_run_tables(void *pArg, int argc, char **argv, char **columnNames)
{
struct cc_cctask_call_obj *in = pArg;
char *sql;
char *sql_update;
sql = switch_mprintf("insert into `uncall_task`.`phone_memory` (`cid_num`, `exten`, `context`, `task_tabke_id`, `task_table`, `
in->cid_num,
in->exten,
in->context,
argv[0],
in->task_id,
in->gateway,
in->fifo_name,
argv[1],
in->cid_name
);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "-----> %s \n",sql);
cc_execute_sql(sql,globals.sql_mutex);
switch_safe_free(sql);
sql_update = switch_mprintf("update `uncall_task`.`ccpaas_run_%s` set `call_time`='%ld' where `id`='%s'  ",
in->task_id,
(long) switch_epoch_time_now(NULL),
argv[0]
);
cc_execute_sql(sql_update, globals.sql_mutex);
switch_safe_free(sql_update);
if(in){

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。