相信你們若是同花順臨時受權不少,手動更新很是麻煩,重複勞動太多,可採用以下powershell腳本downkey.ps1實現自動更新,主要實現判斷pauth.ini中證書在一週內,執行則會去自動更新受權,如把腳本放置在計劃任務中,定義晚上8點更新,則可作到自動更新受權(前提是同花順已經從新受權)。
具體腳本以下:
#同花順更新委託主站證書,注意key有特殊字符+-等要轉義,無轉義狀況下authcodes-authcode1
$AuthCodes='E22-LHjT-4Itu-A7sg-Hnyi-H0U+'
$AuthCodes1='E22-LHjT-4Itu-A7sg-Hnyi-H0U%2B'
$AuthPath='d:\thssj\wtserver\'
$NetFile='http://services.myhexin.com/produser/downloadcert?libver=20030506&authcode='+$AuthCodes1+'&Submit=%CF%C2%D4%D8%D6%A4%CA%E9'
$SaveFile=$AuthPath+$AuthCodes.Substring(0,3)+'.dat'shell
#加載winapi
$ini = Add-Type -memberDefinition @"
[DllImport("Kernel32")]
public static extern int GetPrivateProfileString (
string section ,
string key ,
string def ,
StringBuilder retVal ,
int size ,
string filePath );
"@ -passthru -name MyPrivateProfileString -UsingNamespace System.Text api
#定義配置
$section=$AuthCodes
$filePath=$AuthPath+"pauth.ini"
$key="證書截止時間"
$retVal=New-Object System.Text.StringBuilder(200) ide
#查看配置文件key值
$null=$ini::GetPrivateProfileString($section,$key,"",$retVal,200,$filePath)
$dateStr = $retVal.tostring()
#格式化字符串爲日期
$dateVal = get-date $dateStr
#找到提早七天日期
$dateLast = $dateVal.AddDays(-7)
#獲取當前日期
$dateNow = get-date
#key值與當前日期比較,lt是小於,ge是大於
if($dateLast -le $dateNow) {
#開始執行下載受權文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啓委託主站
taskkill /im hxwt.exe /f
Start-Sleep -s 3
cd $AuthPath
start hxwt.exe
}ui
################################################################################################
#同花順更新委託網關證書,注意key有特殊字符+-等要轉義,無轉義狀況下authcodes-authcode1
$AuthCodes='E19-LHjT-4Itu-A7sg-Hnyi-H0U+'
$AuthCodes1='E19-LHjT-4Itu-A7sg-Hnyi-H0U%2B'
$AuthPath='d:\thssj\WTGateWay\'
$NetFile='http://services.myhexin.com/produser/downloadcert?libver=20030506&authcode='+$AuthCodes1+'&Submit=%CF%C2%D4%D8%D6%A4%CA%E9'
$SaveFile=$AuthPath+$AuthCodes.Substring(0,3)+'.dat'spa
#加載winapi
$ini = Add-Type -memberDefinition @"
[DllImport("Kernel32")]
public static extern int GetPrivateProfileString (
string section ,
string key ,
string def ,
StringBuilder retVal ,
int size ,
string filePath );
"@ -passthru -name MyPrivateProfileString -UsingNamespace System.Text code
#定義配置
$section=$AuthCodes
$filePath=$AuthPath+"pauth.ini"
$key="證書截止時間"
$retVal=New-Object System.Text.StringBuilder(200) server
#查看配置文件key值
$null=$ini::GetPrivateProfileString($section,$key,"",$retVal,200,$filePath)
$dateStr = $retVal.tostring()
#格式化字符串爲日期
$dateVal = get-date $dateStr
#找到提早七天日期
$dateLast = $dateVal.AddDays(-7)
#獲取當前日期
$dateNow = get-date
#key值與當前日期比較,lt是小於,ge是大於
if($dateLast -le $dateNow) {
#開始執行下載受權文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啓委託網關
taskkill /im WTMonitor.exe /f
Start-Sleep -s 3
cd $AuthPath
start WTMonitor.exe
}字符串