def push_notification_by_call(voice, worker_phone_num):
"""
语音提醒
:param voice: 音频文件
:param worker_phone_num: 用户电话
:return:
"""
phone_num = str(worker_phone_num)
shap3 = ctypes.cdll.LoadLibrary("C:\Windows\SHP_A3.dll") # 加载动态链接库
shap3.SsmStartCti(path.join(src, 'ShCti\ShConfig.ini\0'),
path.join(src, 'ShCti\ShIndex.ini\0')) # 初始化驱动
ch = shap3.SsmSearchIdleCallOutCh(1, 0) # 搜索空闲通道
ret_1 = shap3.SsmAddToFileList(ch, voice, -1, 0, -1) # 向驱动程序提交一个需要播放的语音文件
ret_2 = shap3.SsmSetPlayVolume(ch, 3) # 设置播放语音文件的声音大小
ret_3 = shap3.SsmPickup(ch) # 通道摘机
# shap3.SsmSetCalleeHookDetectP(ch, 6, 48) # 增强的远端摘机检测器参数设置
# shap3.SsmStartPickupAnalyze(ch) # 启动“增强的远端摘机检测器”
ret_4 = shap3.SsmSetWaitAutoDialAnswerTimeEx(ch, 25) # 设置一个通道等待被叫用户摘机的最大等待时间
ret_5 = shap3.SsmAutoDial(ch, phone_num) # 拨打电话
start_time = time.time()
while True: # 实时查询当前通道状态(时间间隔0.1秒)
time.sleep(0.1)
# if shap3.SsmGetPickup(ch) == 1: # 判断被叫用户是否摘机
ret_7 = shap3.SsmGetChState(ch)
if shap3.SsmGetChState(ch) == 3:
shap3.SsmPlayFileList(ch) # 播放已添加的语音文件
if shap3.SsmGetChState(ch) == 7:
ret_6 = shap3.SsmGetPendingReason(ch)
if ret_6 == 0:
print "未检测到拨号音, 请检查是否插电话线"
# elif ret_6 == 4:
# print "通道在“连接”状态时检测到对端用户挂机"
shap3.SsmStopPlayFileList(ch) # 停止播放语音文件
break
end_time = time.time()
max_time = end_time - start_time
if max_time >= 120: # 设置通话最大时长
break
shap3.SsmHangup(ch) # 通道挂断
shap3.SsmClearFileList(ch) # 关闭并清除已提交给驱动程序的全部语音文件
shap3.SsmCloseCti() # 关闭驱动程序