相信大家如果同花顺临时授权很多,手动更新非常麻烦,重复劳动太多,可采用如下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'
#加载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
#定义配置 $section=$AuthCodes $filePath=$AuthPath+"pauth.ini" $key="证书截止时间" $retVal=New-Object System.Text.StringBuilder(200)
#查看配置文件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 }
################################################################################################ #同花顺更新委托网关证书,注意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'
#加载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
#定义配置 $section=$AuthCodes $filePath=$AuthPath+"pauth.ini" $key="证书截止时间" $retVal=New-Object System.Text.StringBuilder(200)
#查看配置文件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 }