*本文仅供记录、存档备案用。
用途:某电话转接系统,需要每天修改配置文件、并重启服务端程序
原理:WEB用于展示修改界面,提交、保存配置文件的相关数据
VB端用于定时轮训WEB上保存的数据,发现和本地不一致时则进行同步,并反馈日志到WEB端。
扩展:VB端可以用Python、Shell等进行改写,以适应多平台环境。
WEB端主要代码:
<?php //--------------写预配置文件,记录日志-------------- function ty1921($phonenum,$date){ $open=fopen("E:\WAMP\WWWROOT\XXXXXXXXX_callout.txt","w" ); $open2=fopen("E:\WAMP\WWWROOT\XXXXXXXXX_callout_log.txt","a" ); $open3=fopen("E:\WAMP\WWWROOT\XXXXXXXXX_callout_date.txt","w" ); if(fwrite($open,$phonenum)){//预配置文件 if(fwrite($open2,$phonenum." ".date("Y-m-d H:i:s")."\r\n")){//写入日志 if(!fwrite($open3,$date)){ echo "ok"; }else{ $err="XXXXXXXXX_callout_date更新失败:".$date; } }else{ $err="写入日志失败"; }; }else{ $err="打开XXXXXXXXX_callout.txt失败"; }; fclose($open); } //--------------函数结束-------------- $phonenum=trim($_REQUEST['phonenum']); //程序、网页 修改配置 if(!empty($_REQUEST['type']) and !empty($_REQUEST['phonenum'])){ if(strlen($phonenum) == "11") { //上面部分判断长度是不是11位 $n = preg_match_all("/13[0-9]{1}\d{8}|15[0-9]\d{8}|18[0-9]\d{8}/",$phonenum,$array); ty1921($_REQUEST['phonenum'],$_REQUEST['date']); $err="设置成功!请查看日志"; }else { $err="手机号码格式错误:".$_REQUEST['phonenum']; } } ?> <form method="post" action="?type=web&date=<?=date("Y-m-d")?>"> <table align="center"><tr><td align="left"> <div style="width:500px;height:500px;background-color:eeeeee;text-align:left"> <h2>XXXXXXXXX 手机呼叫转移 设置系统</h2> 请输入转接号码:<input id="phonenum" name="phonenum" maxlength="11" onkeyup="value=value.replace('0','0').replace('1','1').replace('2','2').replace('3', '3').replace('4','4').replace('5','5').replace('6','6').replace('7', '7').replace('8','8').replace('9','9');" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace('0','0').replace('1','1').replace('2','2').replace('3', '3').replace('4','4').replace('5','5').replace('6','6').replace('7', '7').replace('8','8').replace('9','9'))" /> <br><font size="2" color="555555">*修改后,生效时间为<b>2</b>分钟,请2分钟以后再进行测试</font> <br><br> <input type="submit" value=" 修 改 " > <? $file_name="E:\WAMP\WWWROOT\XXXXXXXXX_callout.txt"; $file_name2="E:\WAMP\WWWROOT\XXXXXXXXX_callout_log.txt"; $fp=fopen($file_name,'r'); if(!feof($fp)){ $buffer=fgets($fp,32); echo "<hr>系统时间: ".date("Y-m-d H:i:s")." 预转移号码:【 XXXXXXXXX → <font color='red'>".$buffer."</font> 】<hr>"; $file2=file($file_name2); $start=count($file2)-1; $end=count($file2)-16; for ($i=$start;$i>$end;$i--) { //$arr[]=fgets($file2);//读出100~200行 if(!empty($file2[$i])){ echo $file2[$i]."<br>"; } } } fclose($fp); echo "</div>"; echo "<hr>".date("Y-m-d H:i:s")." →".$err."<hr>"; ?> </td></tr></table> </form>
VB端FRM代码,另存为form1.frm即可:
VERSION 5.00 Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX" Begin VB.Form Form1 Caption = "XXXXXXXXX来电转接监听" ClientHeight = 7035 ClientLeft = 60 ClientTop = 345 ClientWidth = 6705 LinkTopic = "Form1" ScaleHeight = 7035 ScaleWidth = 6705 StartUpPosition = 1 '所有者中心 Begin VB.CommandButton Command3 Caption = " 退 出 " BeginProperty Font Name = "新宋体" Size = 12 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 5400 TabIndex = 11 Top = 6600 Width = 1215 End Begin VB.Timer Timer1 Interval = 1000 Left = 4440 Top = 6480 End Begin InetCtlsObjects.Inet Inet1 Left = 3720 Top = 6360 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 End Begin VB.Frame Frame2 Caption = "变更记录 " Height = 4575 Left = 120 TabIndex = 1 Top = 1920 Width = 6495 Begin VB.TextBox Text1 BorderStyle = 0 'None Height = 4215 Left = 120 Locked = -1 'True MultiLine = -1 'True TabIndex = 2 Text = "Form1.frx":0000 Top = 240 Width = 6255 End End Begin VB.Frame Frame1 Caption = "呼叫转移设置(http://192.168.*.*/XXXXXXXXX_callout.php)" Height = 1695 Left = 120 TabIndex = 0 Top = 120 Width = 6495 Begin VB.CommandButton Command1 Caption = "立即更新" BeginProperty Font Name = "宋体-PUA" Size = 12 Charset = 134 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 4800 TabIndex = 9 Top = 960 Width = 1455 End Begin VB.CommandButton Command2 Caption = "手动检测" BeginProperty Font Name = "宋体-PUA" Size = 12 Charset = 134 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 2880 TabIndex = 10 Top = 960 Width = 1935 End Begin VB.CheckBox Check1 Caption = "自动轮换" BeginProperty Font Name = "宋体" Size = 12 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 360 TabIndex = 8 Top = 960 Value = 1 'Checked Width = 1695 End Begin VB.Label Label2 BeginProperty Font Name = "宋体" Size = 10.5 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 255 Left = 1440 TabIndex = 4 Top = 360 Width = 4455 End Begin VB.Label Label4 BeginProperty Font Name = "宋体" Size = 10.5 Charset = 134 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00C00000& Height = 255 Left = 1440 TabIndex = 6 Top = 600 Width = 4935 End Begin VB.Label Label3 Caption = "程序设置:" BeginProperty Font Name = "宋体" Size = 10.5 Charset = 134 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000011& Height = 255 Left = 360 TabIndex = 5 Top = 600 Width = 1455 End Begin VB.Label Label1 Caption = "预订设置:" BeginProperty Font Name = "宋体" Size = 10.5 Charset = 134 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H00808080& Height = 255 Left = 360 TabIndex = 3 Top = 360 Width = 1335 End End Begin VB.Label Label5 Caption = "Copyright(c) 2013 ty1921 " Height = 255 Left = 120 TabIndex = 7 Top = 6600 Width = 3015 End End Attribute VB_Name = "Form1" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileStringByKeyName& Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lplFileName As String) Public I As Integer Public Callout_date Private Sub Command2_Click() Call Ty1921 End Sub Private Sub Command3_Click() End End Sub Private Sub Form_Load() Call Ty1921 I = 60 End Sub Private Sub Command1_Click() '立即更新 I = 3 End Sub Private Sub Timer1_Timer() I = I - 1 If I <= 0 Then Call Ty1921 If Left(Label2.Caption, 11) <> Left(Label4.Caption, 11) Then '检测预配置,不一致则马上更改 Call ReBoot(Left(Trim(Label2.Caption), 11)) End If '自动轮换检查 If Check1.Value = 1 And Time <= "00:06:00" Then '日期检查 Callout_date = Inet1.OpenURL("http://192.168.*.*/XXXXXXXXX_callout_date.txt") If Date <> Callout_date Then '更换号码 If Left(Label2.Caption, 11) = "181XXXXXXXX" Then Call ReBoot("181XXXXXXXX") ElseIf Left(Label2.Caption, 11) = "189XXXXXXXX" Then Call ReBoot("181XXXXXXXX") Else Call ReBoot("XXXXXXXX")'应急号码 End If End If End If '延时 I = 120 Else Command2.Caption = "手动检测 (" & I & ")" End If End Sub Sub Ty1921() Dim CallOut As String * 32 GetPrivateProfileString "DATABASE", "callout", "错误,未得到值", CallOut, 255, "d:\zhai\IvrConfig.ini" Label4.Caption = Trim(Str(CallOut)) & " | " & Now Label2.Caption = Inet1.OpenURL("http://192.168.*.*/XXXXXXXXX_callout.txt") & " | " & Now Text1.Text = Inet1.OpenURL("http://192.168.*.*/XXXXXXXXX_callout_log.txt") End Sub Sub ReBoot(ByVal PhoneNum As String) Dim Result_i WritePrivateProfileStringByKeyName& "DATABASE", "callout", PhoneNum, "d:\zhai\IvrConfig.ini" '同步网络配置 Result_i = Inet1.OpenURL("http://192.168.*.*/XXXXXXXXX_callout.php?type=vb&date=" & Date & "&phonenum=" & PhoneNum) If Result_i = "ok" Then Call Ty1921 End If '关闭程序 Shell ("cmd /c taskkill /f /im demo.exe"), vbHide '开启程序 Shell ("D:\zhai\demo.exe"), vbNormalFocus End Sub