Skip to content

Instantly share code, notes, and snippets.

@s1204IT
Last active January 19, 2024 03:08
Show Gist options
  • Save s1204IT/515b765efabcaf8f9b9a7598aa36e049 to your computer and use it in GitHub Desktop.
Save s1204IT/515b765efabcaf8f9b9a7598aa36e049 to your computer and use it in GitHub Desktop.
ヒマッセ関係
### 規約違反なので、完全自己責任! ###
# 会員番号 (10桁)
$z_id = ""
# パスワード (8~16文字)
$z_psw = ""
Clear-Host
$ProgressPreference = "SilentlyContinue"
$ErrorActionPreference = "SilentlyContinue"
if ($z_id -eq "") { [ValidateLength(10, 10)]$z_id = [String](Read-Host -Prompt '会員番号を入力してください') }
if ($? -eq $false) { Write-Output "会員番号の形式が正しくありません"; exit 1 }
if ($z_psw -eq "") { [ValidateLength(8, 16)]$z_psw = [String]($([Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR((ConvertTo-SecureString $(ConvertFrom-SecureString $(Read-Host -Prompt 'パスワードを入力してください' -AsSecureString))))))) }
if ($? -eq $false) { Write-Output "パスワードの形式が正しくありません"; exit 1 }
Clear-Host
# ZEMItoken があるセッションを作成
Invoke-RestMethod -Method Post -Uri 'https://loginc.benesse.ne.jp/d/login' -Body @{ usr_name = $z_id; usr_password = $z_psw } -ContentType 'application/x-www-form-urlencoded' -SessionVariable ZEMItoken | Out-Null
# Cookie を作成
$akamaiCookie = New-Object System.Net.Cookie
# Cookie の名前
$akamaiCookie.Name = "town_akamai_token"
# akamaiToken の Post 先
## d2[-staging]
$baeURL = "https://d2.benesse.ne.jp/api"
# Cookie の値 (ZEMItoken のセッションを引き継ぎ)
$akamaiCookie.Value = $(Invoke-RestMethod -Method Post -Uri $baeURL -Headers @{ "X-Api-Version" = "1.0" } -Body $(@{ "jsonrpc" = "2.0"; "method" = "common.akamaiToken.get"; "id" = $(New-Guid).Guid } | ConvertTo-Json) -ContentType 'application/json' -WebSession $ZEMItoken).result.token
# Cookie のドメイン
$akamaiCookie.Domain = "townak.benesse.ne.jp"
# セッションオブジェクトの作成
$akamaiReq = New-Object Microsoft.PowerShell.Commands.WebRequestSession
# Cookie をセッションに追加
$akamaiReq.Cookies.Add($akamaiCookie);
# セッションのテスト
Invoke-RestMethod -Method Get -Uri "https://townak.benesse.ne.jp/rel/A/sp_84/authorized/appli/common/config.xml" -ContentType 'application/xml' -WebSession $akamaiReq | Out-Null
if ($? -eq $false) { Write-Output "情報の取得に失敗しました`r`nログイン情報が間違っています。"; Start-Sleep 2; exit 1 }
# デリバリーインフォに Get する内容
$akamaiType = Read-Host -Prompt "[rel,rel2,test,test2-4](Def: rel)"
if ($akamaiType -eq "") { Set-Variable -Name akamaiType -Value "rel" }
$akamaiTable = Read-Host -Prompt "[A,B](Def: A)"
if ($akamaiTable -eq "") { Set-Variable -Name akamaiTable -Value "A" }
$akamaiList = Read-Host -Prompt "200[2-9](Def: 7)"
if ($akamaiList -eq "") { Set-Variable -Name akamaiList -Value "7" }
$akamaiInfo = Read-Host -Prompt "deliveryInfo_APL000[A,B,C,D,H].xml (Def: B)"
if ($akamaiInfo -eq "") { Set-Variable -Name akamaiInfo -Value "B" }
$akamaiBase = "https://townak.benesse.ne.jp/$akamaiType/$akamaiTable/sp_84"
Clear-Host
# デリバリーインフォに Get
[System.Text.Encoding]::UTF8.GetString([System.Text.Encoding]::GetEncoding("ISO-8859-1").GetBytes((Invoke-WebRequest -Method Get -Uri "$akamaiBase/authorized/list/200$akamaiList/deliveryInfo_APL000$akamaiInfo.xml" -ContentType 'application/xml' -WebSession $akamaiReq).Content))>response.xml
if ($? -eq $false) { Write-Output "情報の取得に失敗しました`r`nファイルが見つかりません。"; Start-Sleep 2; exit 1 }
Write-Output $([XML](Get-Content .\response.xml)).deliveryInfo.application
# パスを指定しダウンロード
$akamaiPath = (Read-Host -Prompt "`r`n`"path`"を入力")
Invoke-RestMethod -Method Get -Uri $akamaiBase$(Write-Output $akamaiPath | Foreach-Object { $_ -replace ' ','' } | Foreach-Object { $_ -replace ':','' }) -OutFile $(($akamaiPath).Split("/") | Select-String -Pattern ".zip", ".apk", ".bin", ".hex", ".txt", ".xml" | ForEach-Object { $_ -replace '`n', '' }) -WebSession $akamaiReq -UseBasicParsing
if ($? -eq $false) { Write-Output "`r`n入力された`"path`"が見つかりませんでした:$akamaiPath`n"; Start-Sleep 2; exit 1 }
# 会員情報の変数をクリア
Clear-Variable -Name z_id
Clear-Variable -Name z_psw
# 正常に終了
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment