GetChooseFile(ParseLink:=1){ ;可选参数 1解析lnk 其他不解析 默认解析 ClipSave := ClipboardAll ;转存当前剪切板 Send, ^c Sleep, 100 Paths := Clipboard Clipboard := ClipSave Paths2 = Loop, Parse, Paths, `n, `r ;解析获取的字符串 { if (ParseLink=1 && RegExMatch(A_LoopField,"\.lnk$")) { FileGetShortcut, % A_LoopField, t Paths2 .= t "`n" } else Paths2 .= A_LoopField "`n" } return Paths2 }
#移除原文件 rm /etc/motd #重新创建 按i插入, Esc退出编辑模式,输入:wq保存退出 vi /etc/motd #设置只读 chmod 444 /etc/motd #不允许删除 chattr +ia /etc/motd reboot
Gui, Add, Button, x0 y0 w100 h20 ga, 粘贴数据A(少) Gui, Add, Button, x100 y0 w100 h20 gb, 粘贴数据B(多) Gui, Add, Button, x200 y0 w100 h20 gc, 提交 Gui, Add, text, x0 y20 w300 h20, 选择筛选关键字段 Gui, Add, DDL, x0 y40 w300 vkey, Gui, Add, text, x0 y60 w300 h20, Gui, Add, Edit, x0 y80 w300 h200 vshow, Gui, Add, StatusBar, x0 y280 Gui, Show, , Excel追加数据提取(去重) return a: data_a := StrSplit(Clipboard,"`n","`r") ;按行分割成数组 SB_SetText("数据A粘贴成功!") x := StrSplit(data_a[1],"`t") ;获取字段 y = for k,v in x y .= v ? "|" k "_" v : "" GuiControl,, key, % y return b: data_b := StrSplit(Clipboard,"`n","`r") SB_SetText("数据B粘贴成功!") return c: SB_SetText("") GuiControlGet, key if !key { MsgBox, 4112, 错误, 未选择关键字段 return } d := StrSplit(key,"_") ;获取关键字段id key_num := d[1] SB_SetText("生成数据A哈希") hash_a := [] for k,v in data_a { if A_index>1 { if RegExMatch(v,"^[A-Za-z0-9]+$") ;纯数字字母组合直接加入提高效率 hash_a["" v] := A_Index ;加""强制转成文本 else ;复杂值获取MD5 hash_a[MD5(StrSplit(v,"`t")[key_num],"CP0")] := A_index } } SB_SetText("生成数据B哈希") hash_b := [] for k,v in data_b { if A_index>1 { if RegExMatch(v,"^[A-Za-z0-9]+$") hash_b["" v] := A_Index else hash_b[MD5(StrSplit(v,"`t")[key_num],"CP0")] := A_index } } out := data_a[1] SB_SetText("去重") for k,v in hash_b { if !hash_a[k] ;数据A中不存在此关键字段值 out .= "`n" data_b[v] } GuiControl, , show, % out Clipboard := out SB_SetText("完成,结果已复制到剪切板") data_a:="",data_b:="",hash_a:="",hash_a:="",x:="",y:="",key_num:="",out:="" GuiControl, , key, | return GuiClose: ExitApp
环境Elastix2.5
编辑/etc/asterisk/extensions.conf
[from-internal] exten=>#,1,Answer //这里设置的是#号键 exten=>#,n,MySql(connect connid localhost root 123456 asteriskcdrdb) //连接mysql 操作 ;exten=>#,n,MySql(query resultidr ${connid} insert into test (msg) values ('${CALLERID(num)}')) //测试插入 exten=>#,n,MySql(query resultidr ${connid} select dst as a,uniqueid as b from cdr where src=${CALLERID(num)} order by uniqueid desc limit 1) //获取上一个呼叫记录数据 exten=>#,n,MySql(Fetch foundrow ${resultidr} a b) //取出变量 exten=>#,n,MySql(clear ${resultidr}) //清空结果集 exten=>#,n,MySql(query resultidr ${connid} update cdr set userfield='OK' where uniqueid=${b}) //更新 exten=>#,n,MySql(clear ${resultidr}) exten=>#,n,MySql(disconnect ${connid}) //断开连接 exten=>#,n,saydigits(${a}) //报被叫号码 exten=>#,n,Playback(custom/mark_ok) //“已经标记成功”语音 exten=>#,n,Hangup //挂机 //后面是原来的拨号方案 include => from-internal-noxfer include => from-internal-xfer include => bad-number ; auto-generated
保存完毕后需要重载asterisk生效。
转自cnblogs
在asterisk中,定义了许多变量,或是有些变量能够被其读取。下面给出了它们的列表。在每一个application的帮助文档中,你可以获得更多的信息。所有这些变量都是大写的。
被*标记的变量是内建函数,不能在拨号方案中被设置,只能被读取。对这些变量的赋值将被忽略。
${CDR(accountcode)} * Account co
${BLINDTRANSFER} The name of the channel on the other side of a blind transfer
${BRIDGEPEER} Bridged peer
${BRIDGEPVTCALLID} Bridged peer PVT call ID (SIP Call ID if a SIP call)
${CALLERID(ani)} * Caller ANI (PRI channels)
${CALLERID(ani2)} * ANI2 (Info digits) also called Originating line information or OLI
${CALLERID(all)} * Caller ID
${CALLERID(dnid)} * Dialed Number Identifier
${CALLERID(name)} * Caller ID Name on
${CALLERID(num)} * Caller ID Number on
${CALLERID(rdnis)} * Redirected Dial Number ID Service
${CALLINGANI2} * Caller ANI2 (PRI channels)
${CALLINGPRES} * Caller ID presentation for incoming calls (PRI channels)
${CALLINGTNS} * Transit Network Selector (PRI channels)
${CALLINGTON} * Caller Type of Number (PRI channels)
${CHANNEL} * Current channel name
${CONTEXT} * Current context
${DATETIME} * Current date time in the format: DDMMYYYY-HH:MM:SS
(Deprecated; use ${STRFTIME(${EPOCH},,%d%m%Y-%H:%M:%S)})
${DB_RESULT} Result value of DB_EXISTS() dial plan function
${EPOCH} * Current unix style epoch
${EXTEN} * Current extension
${ENV(VAR)} Environmental variable VAR
${GOTO_ON_BLINDXFR} Transfer to the specified context/extension/priority
after a blind transfer (use ^ characters in place of
| to separate context/extension/priority when setting
this variable from the dialplan)
${HANGUPCAUSE} * Asterisk cause of hangup (inbound/outbound)
${HINT} * Channel hints for this extension
${HINTNAME} * Suggested Caller*ID name for this extension
${INVALID_EXTEN} The invalid called extension (used in the "i" extension)
${LANGUAGE} * Current language (Deprecated; use ${LANGUAGE()})
${LEN(VAR)} * String length of VAR (integer)
${PRIORITY} * Current priority in the dialplan
${PRIREDIRECTREASON} Reason for redirect on PRI, if a call was directed
${TIMESTAMP} * Current date time in the format: YYYYMMDD-HHMMSS
(Deprecated; use ${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)})
${TRANSFER_CONTEXT} Context for transferred calls
${FORWARD_CONTEXT} Context for forwarded calls
${UNIQUEID} * Current call unique identifier
${SYSTEMNAME} * value of the systemname option of asterisk.conf
${ENTITYID} * Global Entity ID set automatically, or from asterisk.conf
当你调用有些application的时候,它们会返回一个值供你读取。对于每一个application,这些状态字段是唯一的。各种状态值,前参考每个application的帮助文档。
${AGISTATUS} * agi()
${AQMSTATUS} * addqueuemember()
${AVAILSTATUS} * chanisavail()
${CHECKGROUPSTATUS} * checkgroup()
${CHECKMD5STATUS} * checkmd5()
${CPLAYBACKSTATUS} * controlplayback()
${DIALSTATUS} * dial()
${DBGETSTATUS} * dbget()
${ENUMSTATUS} * enumlookup()
${HASVMSTATUS} * hasnewvoicemail()
${LOOKUPBLSTATUS} * lookupblacklist()
${OSPAUTHSTATUS} * ospauth()
${OSPLOOKUPSTATUS} * osplookup()
${OSPNEXTSTATUS} * ospnext()
${OSPFINISHSTATUS} * ospfinish()
${PARKEDAT} * parkandannounce()
${PLAYBACKSTATUS} * playback()
${PQMSTATUS} * pausequeuemember()
${PRIVACYMGRSTATUS} * privacymanager()
${QUEUESTATUS} * queue()
${RQMSTATUS} * removequeuemember()
${SENDIMAGESTATUS} * sendimage()
${SENDTEXTSTATUS} * sendtext()
${SENDURLSTATUS} * sendurl()
${SYSTEMSTATUS} * system()
${TRANSFERSTATUS} * transfer()
${TXTCIDNAMESTATUS} * txtcidname()
${UPQMSTATUS} * unpausequeuemember()
${VMSTATUS} * voicmail()
${VMBOXEXISTSSTATUS} * vmboxexists()
${WAITSTATUS} * waitforsilence()
${CURL} * Resulting page content for curl()
${ENUM} * Result of application EnumLookup
${EXITCONTEXT} Context to exit to in IVR menu (app background())
or in the RetryDial() application
${MONITOR} * Set to "TRUE" if the channel is/has been monitored (app monitor())
${MONITOR_EXEC} Application to execute after monitoring a call
${MONITOR_EXEC_ARGS} Arguments to application
${MONITOR_FILENAME} File for monitoring (recording) calls in queue
${QUEUE_PRIO} Queue priority
${QUEUE_MAX_PENALTY} Maximum member penalty allowed to answer caller
${QUEUE_MIN_PENALTY} Minimum member penalty allowed to answer caller
${QUEUESTATUS} Status of the call, on
(TIMEOUT | FULL | JOINEMPTY | LEAVEEMPTY | JOINUNAVAIL | LEAVEUNAVAIL)
${RECORDED_FILE} * Recorded file in record()
${TALK_DETECTED} * Result from talkdetect()
${TOUCH_MONITOR} The filename base to use with Touch Monitor (auto record)
${TOUCH_MONITOR_PREF} * The prefix for automonitor recording filenames.
${TOUCH_MONITOR_FORMAT} The audio format to use with Touch Monitor (auto record)
${TOUCH_MONITOR_OUTPUT} * Recorded file from Touch Monitor (auto record)
${TOUCH_MONITOR_MESSAGE_START} Recorded file to play for both channels at start of monitoring session
${TOUCH_MONITOR_MESSAGE_STOP} Recorded file to play for both channels at end of monitoring session
${TXTCIDNAME} * Result of application TXTCIDName
${VPB_GETDTMF} chan_vpb
${MEETME_RECORDINGFILE} Name of file for recording a conference with the "r" option
${MEETME_RECORDINGFORMAT} Format of file to be recorded
${MEETME_EXIT_CONTEXT} Context for exit out of meetme meeting
${MEETME_AGI_BACKGROUND} AGI script for Meetme (DAHDI on
${MEETMESECS} * Number of seconds a user participated in a MeetMe conference
${CONF_LIMIT_TIMEOUT_FILE} File to play when time is up. Used with the L() option.
${CONF_LIMIT_WARNING_FILE} File to play as warning if 'y' is defined. The default is to say the time remaining. Used with the L() option.
${VM_CATEGORY} Sets voicemail category
${VM_NAME} * Full name in voicemail
${VM_DUR} * Voicemail duration
${VM_MSGNUM} * Number of voicemail message in mailbox
${VM_CALLERID} * Voicemail Caller ID (Person leaving vm)
${VM_CIDNAME} * Voicemail Caller ID Name
${VM_CIDNUM} * Voicemail Caller ID Number
${VM_DATE} * Voicemail Date
${VM_MESSAGEFILE} * Path to message left by caller
${AUTH_MAILBOX} * Authenticated mailbox
${AUTH_CONTEXT} * Authenticated mailbox context
${DUNDTECH} * The Technology of the result from a call to DUNDiLookup()
${DUNDDEST} * The Destination of the result from a call to DUNDiLookup()
${ANI2} * The ANI2 Co
${CALLTYPE} * Type of call (Speech, Digital, etc)
${CALLEDTON} * Type of number for incoming PRI extension i.e. 0=unknown, 1=international, 2=domestic, 3=net_specific, 4=subscriber, 6=abbreviated, 7=reserved
${CALLINGSUBADDR} * Called PRI Subaddress
${FAXEXTEN} * The extension called before being redirected to "fax"
${PRIREDIRECTREASON} * Reason for redirect, if a call was directed
${SMDI_VM_TYPE} * When an call is received with an SMDI message, the 'type' of message 'b' or 'u'
${SIPCALLID} * SIP Call-ID: header verbatim (for logging or CDR matching)
${SIPDOMAIN} * SIP destination domain of an inbound call (if appropriate)
${SIPUSERAGENT} * SIP user agent (deprecated)
${SIPURI} * SIP uri
${SIP_CODEC} Set the SIP codec for a call
${SIP_URI_OPTIONS} * additional options to add to the URI for an outgoing call
${RTPAUDIOQOS} RTCP QoS report for the audio of this call
${RTPVIDEOQOS} RTCP QoS report for the video of this call
${AGENTMAXLOGINTRIES} Set the maximum number of failed logins
${AGENTUPDATECDR} Whether to update the CDR record with Agent channel da
${AGENTGOODBYE} Sound file to use for "Good Bye" when agent logs out
${AGENTACKCALL} Whether the agent should acknowledge the incoming call
${AGENTAUTOLOGOFF} Auto logging off for an agent
${AGENTWRAPUPTIME} Setting the time for wrapup between incoming calls
${AGENTNUMBER} * Agent number (username) set at login
${AGENTSTATUS} * Status of login ( fail | on | off )
${AGENTEXTEN} * Extension for logged in agent
${DIALEDPEERNAME} * Dialed peer name
${DIALEDPEERNUMBER} * Dialed peer number
${DIALEDTIME} * Time for the call (seconds). Is on
${ANSWEREDTIME} * Time from answer to hangup (seconds)
${DIALSTATUS} * Status of the call, on
${DYNAMIC_FEATURES} * The list of features (from the [applicationmap] section of features.conf) to activate during the call, with feature names separated by '#' characters
${LIMIT_PLAYAUDIO_CALLER} Soundfile for call limits
${LIMIT_PLAYAUDIO_CALLEE} Soundfile for call limits
${LIMIT_WARNING_FILE} Soundfile for call limits
${LIMIT_TIMEOUT_FILE} Soundfile for call limits
${LIMIT_CONNECT_FILE} Soundfile for call limits
${OUTBOUND_GROUP} Default groups for peer channels (as in SetGroup) * See "show application dial" for more information
${AVAILCHAN} * the name of the available channel if on
${AVAILORIGCHAN} * the canonical channel name that was used to create the channel
${AVAILSTATUS} * Status of requested channel
${MACRO_EXTEN} * The calling extensions
${MACRO_CONTEXT} * The calling context
${MACRO_PRIORITY} * The calling priority
${MACRO_OFFSET} Offset to add to priority at return from macro
${SPYGROUP} * A ':' (colon) separated list of group names. (To be set on spied on channel and matched against the g(grp) option)
${OSPINHANDLE} OSP handle of in_bound call
${OSPINTIMELIMIT} Duration limit for in_bound call
${OSPOUTHANDLE} OSP handle of out_bound call
${OSPTECH} OSP technology
${OSPDEST} OSP destination
${OSPCALLING} OSP calling number
${OSPOUTTOKEN} OSP token to use for out_bound call
${OSPOUTTIMELIMIT} Duration limit for out_bound call
${OSPRESULTS} Number of remained destinations
环境说明:
Elastix 2.5
ln -s /var/spool/asterisk/monitor /var/www/html/
接口文件(php):
<?php $con=mysql_connect("localhost","root","passwd"); if(!$con) echo "没有连接成功!"; mysql_select_db("asteriskcdrdb", $con); mysql_query("SET NAMES UTF8"); if(isset($_GET["phone"])){ $phone=$_GET["phone"]; if(isset($_GET["date"])){ $calldate=$_GET["date"]; $q = "SELECT * FROM `cdr` WHERE `dst`='$phone' and cast(`calldate` as date)='$calldate' order by `calldate` desc limit 100"; //此处注意dst和src }else{ $q = "SELECT * FROM `cdr` WHERE `dst`='$phone' order by `calldate` desc limit 100"; } $result = mysql_query($q, $con); if(mysql_num_rows($result)>0){ while($obj=mysql_fetch_object($result)){ $obj->src; $obj->dst; $obj->channel; $obj->billsec; $obj->calldate; $recordingfile = $obj->recordingfile; if($recordingfile){ $a = explode("-",$recordingfile);; $subdir = substr($a[3],0,4)."/".substr($a[3],4,2)."/".substr($a[3],6,2); $uri = "/monitor/$subdir/$recordingfile"; }else{ $uri=''; } echo $obj->src.",".$obj->dst.",".$obj->channel.",".$obj->dstchannel.",".$obj->disposition.",".$obj->billsec.",".$obj->calldate.",".$uri."\n"; } } } mysql_free_result($result); mysql_close($con); ?>
客户端程序(Autohotkey):
FileCreateDir, %A_ScriptDir%\sox FileCreateDir, c:\temp\ FileInstall, libgomp-1.dll, %A_ScriptDir%\sox\libgomp-1.dll FileInstall, pthreadgc2.dll, %A_ScriptDir%\sox\pthreadgc2.dll FileInstall, sox.exe, %A_ScriptDir%\sox\sox.exe FileInstall, zlib1.dll, %A_ScriptDir%\sox\zlib1.dll gui, Add, text, x0 y0 w60 h20, 号码 gui, Add, edit, x60 y0 w140 h20 vphone, Gui, Add, Checkbox, x200 y0 w100 h20 vcd, 呼叫时间 Gui, add, DateTime, x300 y0 w200 h20 vdate, Gui, Add, Button, x500 y0 w100 h20 Default gsearch, 查询 Gui, Add, Button, x600 y0 w100 h20 glisten, 听取所选 gui, add, ListView, x0 y20 w700 h300, 被叫|主叫|通道|目标通道|状态|通话时长|呼叫时间|录音链接 Gui, Add, ActiveX, x0 w700 h100 vwmp, {6BF52A52-394A-11D3-B153-00C04F79FAA6} gui, show, , 本地呼叫系统录音听取 GuiControl, , cd, 1 wmp.Settings.Volume := 100 return search: Gui, Submit, NoHide if cd=1 { FormatTime, calldate, % date, yyyy-MM-dd search_url := "http://192.168.1.2/monitor.php?phone=" phone "&date=" calldate } else search_url := "http://192.168.1.2/monitor.php?phone=" phone result := URLDownloadToVar(search_url) LV_Delete() loop, Parse, result, `n, `r { obj := StrSplit(A_LoopField,",") LV_Add("",obj*) } LV_ModifyCol() return listen: FocusedRowNumber := LV_GetNext(0, "F") if not FocusedRowNumber { MsgBox, 4144, 提示, 您未选择任何一条记录! Return } LV_GetText(uri, FocusedRowNumber, 8) if uri { url := "http://192.168.1.2" uri if RegExMatch(uri,".*/(.*)\.gsm$",m) { URLDownloadToFile, % url, % "c:\temp\" m1 ".gsm" RunWait, %A_ScriptDir%\sox\sox.exe c:\temp\%m1%.gsm c:\temp\%m1%.wav rate -v, , hide } else { RegExMatch(uri,".*/(.*)\.wav$",m) URLDownloadToFile, % url, % "c:\temp\" m1 ".wav" } wmp.Url := "c:\temp\" m1 ".wav" } else MsgBox, 64, 提示, 录音链接不存在! return GuiClose: ExitApp
EVfilterPath(path){ pattern = (.*)path:("|)[^"]*("|)\s(.*) ControlGetText, search_string, Edit1, ahk_class EVERYTHING if RegExMatch(search_string,pattern,m) ControlSetText, Edit1, % m1 "path:""" path """ " m4, ahk_class EVERYTHING else ControlSetText, Edit1, % "path:""" path """ " search_string, ahk_class EVERYTHING }
Autohotkey示例:
Gui Add, ActiveX, xm w700 h100 vwmp, {6BF52A52-394A-11D3-B153-00C04F79FAA6} Gui Show ;wmp.Settings.AutoStart := 0 wmp.Settings.Volume := 100 wmp.Url := "D:\我的文档\My Music\brave.mp3"
AAuto示例:
import win.ui; import fsys.dlg; /*DSG{{*/ var winform = ..win.form(text="AAuto Form";right=322;bottom=157) winform.add( static={cls="static";left=5;top=5;right=314;bottom=153;db=1;dl=1;dr=1;dt=1;edge=1;transparent=1;z=1} ) /*}}*/ //创建控件 var wmplay = winform.static.createEmbed("{6BF52A52-394A-11d3-B153-00C04F79FAA6}"); var filepath=fsys.dlg.open("mp3音乐|*.mp3","打开"); wmplay._object.Url = filepath; winform.show() win.loopMessage();
# encoding: utf-8 #!/usr/bin/python import os import time import MySQLdb #设置目录 timearray = time.localtiime(time.time()) timedir = time.strftime("%Y/%m/%d/",timearray) monitordir = "/var/spool/asterisk/monitor/"+timedir vi conv.p # 打开数据库连接 db = MySQLdb.connect("localhost","root","Elastixdb","asteriskcdrdb" ) # 使用cursor()方法获取操作游标 cursor = db.cursor() sql = "SELECT recordingfile from cdr where recordingfile like '%.wav';" try: # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() for row in results: recordingfile = row[0] if os.path.exists(monitordir+recordingfile): print "转换:%s" % monitordir+recordingfile os.system("sox "+monitordir+recordingfile+" "+monitordir+recordingfile.replace('wav','gsm')) os.remove(monitordir+recordingfile.replace('gsm','wav')) sql = "update cdr set recordingfile=replace(recordingfile,'wav','gsm') where recordingfile='"+recordingfile+"';" cursor.execute(sql) db.commit() else: print "找不到文件:%s" % monitordir+recordingfile except: print "Error: unable to fecth data" # 关闭数据库连接 db.close()
#NoEnv ;首先你要在ftp创建upload文件夹 FileInstall, ftp_upload.exe, ftp_upload.exe Gui, add, edit, x0 y0 w300 h20 vpath, Gui, Add, Button, x300 y0 w100 h20 gsfile, 浏览 Gui, add, edit, x0 y20 w300 h20 vdpath, Gui, Add, Button, x300 y20 w100 h20 gupload, 上传获取URL gui, show, , Nano云文件外链(FTP上传) ;定义你的ftp用户名密码 result := FtpOpen("ftp.nanoyun.com",,"xxxxx/xxxxxcdn","xxxxxxxpass") if result = 0 { MsgBox, 4112, 错误, 无法连接到服务器 ExitApp } return sfile: FileSelectFile, path, , , 选择要上传的文件, (*jpg;*.png;*.gif;*.zip;*.rar;*.zip;*.7z;*.ahk;*.aau;*.exe) ;允许上传的文件类型 if path { IfNotInString, path, %A_Space% GuiControl, , path, % path else { FileCopy, % path, % npath := RegExReplace(path," ","_") GuiControl, , path, % npath } GuiControl, , dpath, } return upload: Gui, Submit, NoHide if path { FileDelete, result.txt SplitPath, path, , , ext md5 := FileMD5(path) /* 外部工具方案 RunWait, % ComSpec " /c ftp_upload.exe ftp.nanoyun.com user pass " path " /upload/" md5 "." ext " >result.txt", , Hide FileRead, result, result.txt if result MsgBox, 64, 提示, % result */ result := FtpPutFile(path, "/upload/" md5 "." ext, 2) if result = 0 { MsgBox, 4112, 错误, 上传遇到错误! return } MsgBox, 64, 提示, % result "`n已复制到剪切板!" GuiControl, , dpath, % Clipboard := "http://cdn.ywwx.com.cn/upload/" md5 "." ext ;此处是你的外链网址 需要修改 } return GuiClose: FtpClose() ExitApp ;ftp函数集 FtpCreateDirectory(DirName) { ;创建目录 global ic_hInternet r := DllCall("wininet\FtpCreateDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRemoveDirectory(DirName) { ;移除目录 global ic_hInternet r := DllCall("wininet\FtpRemoveDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpSetCurrentDirectory(DirName) { ;设置当前目录 global ic_hInternet r := DllCall("wininet\FtpSetCurrentDirectoryA", "uint", ic_hInternet, "str", DirName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpPutFile(LocalFile, NewRemoteFile="", Flags=0) { ;上传文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 文本方式 ;FTP_TRANSFER_TYPE_BINARY = 2 二进制方式 If NewRemoteFile= NewRemoteFile := LocalFile global ic_hInternet r := DllCall("wininet\FtpPutFileA" , "uint", ic_hInternet , "str", LocalFile , "str", NewRemoteFile , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFile(RemoteFile, NewFile="", Flags=0) { ;下载文件 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 If NewFile= NewFile := RemoteFile global ic_hInternet r := DllCall("wininet\FtpGetFileA" , "uint", ic_hInternet , "str", RemoteFile , "str", NewFile , "int", 1 ;do not overwrite existing files , "uint", 0 ;dwFlagsAndAttributes , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpGetFileSize(FileName, Flags=0) { ;获取文件大小 ;Flags: ;FTP_TRANSFER_TYPE_UNKNOWN = 0 (Defaults to FTP_TRANSFER_TYPE_BINARY) ;FTP_TRANSFER_TYPE_ASCII = 1 ;FTP_TRANSFER_TYPE_BINARY = 2 global ic_hInternet fof_hInternet := DllCall("wininet\FtpOpenFileA" , "uint", ic_hInternet , "str", FileName , "uint", 0x80000000 ;dwAccess: GENERIC_READ , "uint", Flags , "uint", 0) ;dwContext If (ErrorLevel != 0 or fof_hInternet = 0) return -1 FileSize := DllCall("wininet\FtpGetFileSize", "uint", fof_hInternet, "uint", 0) DllCall("wininet\InternetCloseHandle", "UInt", fof_hInternet) return, FileSize } FtpDeleteFile(FileName) { ;删除文件 global ic_hInternet r := DllCall("wininet\FtpDeleteFileA", "uint", ic_hInternet, "str", FileName) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpRenameFile(Existing, New) { ;重命名文件 global ic_hInternet r := DllCall("wininet\FtpRenameFileA", "uint", ic_hInternet, "str", Existing, "str", New) If (ErrorLevel != 0 or r = 0) return 0 else return 1 } FtpOpen(Server, Port=21, Username=0, Password=0 ,Proxy="", ProxyBypass="") { ;打开ftp连接 IfEqual, Username, 0, SetEnv, Username, anonymous IfEqual, Password, 0, SetEnv, Password, anonymous If (Proxy != "") AccessType=3 Else AccessType=1 ;#define INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration ;#define INTERNET_OPEN_TYPE_DIRECT 1 // direct to net ;#define INTERNET_OPEN_TYPE_PROXY 3 // via named proxy ;#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS global ic_hInternet, io_hInternet, hModule hModule := DllCall("LoadLibrary", "str", "wininet.dll") io_hInternet := DllCall("wininet\InternetOpenA" , "str", A_ScriptName ;lpszAgent , "UInt", AccessType , "str", Proxy , "str", ProxyBypass , "UInt", 0) ;dwFlags If (ErrorLevel != 0 or io_hInternet = 0) { FtpClose() return 0 } ic_hInternet := DllCall("wininet\InternetConnectA" , "uint", io_hInternet , "str", Server , "uint", Port , "str", Username , "str", Password , "uint" , 1 ;dwService (INTERNET_SERVICE_FTP = 1) , "uint", 0 ;dwFlags , "uint", 0) ;dwContext If (ErrorLevel != 0 or ic_hInternet = 0) return 0 else return 1 } FtpClose() { ;关闭ftp连接 global ic_hInternet, io_hInternet, hModule DllCall("wininet\InternetCloseHandle", "UInt", ic_hInternet) DllCall("wininet\InternetCloseHandle", "UInt", io_hInternet) DllCall("FreeLibrary", "UInt", hModule) } FileMD5(filename) ;计算文件MD5值 { return CalcFileHash(filename, 0x8003, 64 * 1024) } CalcFileHash(filename, algid, continue = 0, byref hash = 0, byref hashlength = 0) ;计算文件hash { fpos := "" if (!(f := FileOpen(filename, "r"))) { return } f.pos := 0 if (!continue && f.length > 0x7fffffff) { return } if (!continue) { VarSetCapacity(data, f.length, 0) f.rawRead(&data, f.length) f.pos := oldpos return CalcAddrHash(&data, f.length, algid, hash, hashlength) } hashlength := 0 while (f.pos < f.length) { readlength := (f.length - fpos > continue) ? continue : f.length - f.pos VarSetCapacity(data, hashlength + readlength, 0) DllCall("RtlMoveMemory", "Ptr", &data, "Ptr", &hash, "Ptr", hashlength) f.rawRead(&data + hashlength, readlength) h := CalcAddrHash(&data, hashlength + readlength, algid, hash, hashlength) } return h } CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) { static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"] static b := h.minIndex() hProv := hHash := o := "" if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xf0000000)) { if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash)) { if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0)) { if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0)) { VarSetCapacity(hash, hashlength, 0) if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0)) { loop % hashlength { v := NumGet(hash, A_Index - 1, "UChar") o .= h[(v >> 4) + b] h[(v & 0xf) + b] } } } } DllCall("advapi32\CryptDestroyHash", "Ptr", hHash) } DllCall("advapi32\CryptReleaseContext", "Ptr", hProv, "UInt", 0) } return o }
49 queries in 6.361 seconds |