溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

同花順授權(quán)自動更新腳本

發(fā)布時(shí)間:2020-07-19 16:12:46 來源:網(wǎng)絡(luò) 閱讀:368 作者:lysweb 欄目:系統(tǒng)運(yùn)維

相信大家如果同花順臨時(shí)授權(quán)很多,手動更新非常麻煩,重復(fù)勞動太多,可采用如下powershell腳本downkey.ps1實(shí)現(xiàn)自動更新,主要實(shí)現(xiàn)判斷pauth.ini中證書在一周內(nèi),執(zhí)行則會去自動更新授權(quán),如把腳本放置在計(jì)劃任務(wù)中,定義晚上8點(diǎn)更新,則可做到自動更新授權(quán)(前提是同花順已經(jīng)重新授權(quán))。
具體腳本如下:
#同花順更新委托主站證書,注意key有特殊字符+-等要轉(zhuǎn)義,無轉(zhuǎn)義情況下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="證書截止時(shí)間"
$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)
#獲取當(dāng)前日期
$dateNow = get-date
#key值與當(dāng)前日期比較,lt是小于,ge是大于
if($dateLast -le $dateNow) {
#開始執(zhí)行下載授權(quán)文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啟委托主站
taskkill /im hxwt.exe /f
Start-Sleep -s 3
cd $AuthPath
start hxwt.exe
}

################################################################################################
#同花順更新委托網(wǎng)關(guān)證書,注意key有特殊字符+-等要轉(zhuǎn)義,無轉(zhuǎn)義情況下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="證書截止時(shí)間"
$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)
#獲取當(dāng)前日期
$dateNow = get-date
#key值與當(dāng)前日期比較,lt是小于,ge是大于
if($dateLast -le $dateNow) {
#開始執(zhí)行下載授權(quán)文件
$client = new-object System.Net.WebClient
$client.DownloadFile($NetFile,$SaveFile)
#重啟委托網(wǎng)關(guān)
taskkill /im WTMonitor.exe /f
Start-Sleep -s 3
cd $AuthPath
start WTMonitor.exe
}

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI