feat: 영수증 인쇄를 TCP→DLL 방식으로 전환

TCP 소켓(PRINTSTART/PRINTEND) 대신 AllThatPayCatReqMC(iCmd=2)로
DLL→MMF 경유 인쇄. GW 포트 변경에 영향받지 않음.

- ProcessPrint: TCP 소켓 제거, DLL CatReqMC(2) 호출로 대체
- FindGWPort: 8080/7779 포트 제외 로직 추가
- 실패 시 FindGWPort+ConnectDLL 재연결 후 1회 재시도
- build.bat, test_print_dll.ps1 추가 (DLL 인쇄 단독 테스트용)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
청춘약국
2026-04-11 10:47:37 +09:00
parent 7f66ee82b6
commit c658ac4c43
4 changed files with 205 additions and 1 deletions

105
test_print_dll.ps1 Normal file
View File

@@ -0,0 +1,105 @@
# 32비트 PowerShell에서 AllthatModule.dll iCmd=2 영수증출력 테스트
# 실행: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File test_print_dll.ps1
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public class AllThatPay {
private const string DLL = @"C:\Program Files (x86)\AllthatpayClient\AllthatModule.dll";
[DllImport(DLL, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AllThatPayOpenModule(string gwIp, string gwPort, string atpIp, string atpPort, string bizNo, string ediType, int optFlag);
[DllImport(DLL, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int AllThatPayCloseModule();
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
public static extern int AllThatPayCatReqMC(int iCmd, byte[] pInBuf, int iInLength);
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
public static extern int AllThatPayRetCon();
[DllImport(DLL, CallingConvention = CallingConvention.StdCall)]
public static extern IntPtr AllThatPayRetData(int iPosition);
}
"@
# --- GW 포트 자동 탐지 ---
$gwPort = $null
$proc = Get-Process -Name "AllthatpayClient" -ErrorAction SilentlyContinue | Select-Object -First 1
if ($proc) {
$netstat = netstat -ano 2>$null
foreach ($line in $netstat) {
if ($line -match "LISTENING" -and $line -match "\s$($proc.Id)\s*$") {
if ($line -match ":(\d+)\s") {
$port = [int]$Matches[1]
if ($port -ne 8080 -and $port -ne 7779) {
$gwPort = $port.ToString()
break
}
}
}
}
}
if (-not $gwPort) {
Write-Host "[ERROR] GW port not found" -ForegroundColor Red
exit 1
}
Write-Host "[INFO] GW Port: $gwPort" -ForegroundColor Cyan
# --- DLL 연결 ---
$r = [AllThatPay]::AllThatPayOpenModule("127.0.0.1", $gwPort, "", "", "8134500294", "P01", 0)
Write-Host "[INFO] OpenModule: $r (1=OK)" -ForegroundColor $(if ($r -eq 1) {"Green"} else {"Red"})
if ($r -ne 1) {
Write-Host "[ERROR] OpenModule failed" -ForegroundColor Red
exit 1
}
# --- 영수증 텍스트 (EUC-KR) ---
$eucKr = [System.Text.Encoding]::GetEncoding("euc-kr")
$text = "================================================`n"
$text += " [ 청 춘 약 국 ]`n"
$text += " 경기 양주시 양주역로 7-3 1층`n"
$text += " TEL: 033-481-7390`n"
$text += "================================================`n"
$text += "`n"
$text += " ** DLL iCmd=2 인쇄 테스트 **`n"
$text += " 시간: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')`n"
$text += "`n"
$text += "------------------------------------------------`n"
$text += " ★ 마일리지 적립 ★`n"
$text += " QR 스캔하고 100P 받으세요!`n"
$text += " (유효기간: 30일)`n"
$text += "------------------------------------------------`n"
$text += "`n`n"
$textBytes = $eucKr.GetBytes($text)
# --- QR 코드 추가: FS×4 + ATQR_URL (명세서 CMD 2 규격) ---
$qrUrl = "https://shc.pharmq.kr/claim?t=test_dll_print"
[byte]$fs = 0x1C
$qrTag = $eucKr.GetBytes("ATQR_" + $qrUrl)
$buf = New-Object System.Collections.Generic.List[byte]
$buf.AddRange($textBytes)
$buf.Add($fs); $buf.Add($fs); $buf.Add($fs); $buf.Add($fs)
$buf.AddRange($qrTag)
$packet = $buf.ToArray()
Write-Host "[INFO] iCmd=2 send ($($packet.Length) bytes, text=$($textBytes.Length) + QR=$($qrTag.Length))..." -ForegroundColor Yellow
# --- iCmd=2 영수증출력 ---
try {
$pr = [AllThatPay]::AllThatPayCatReqMC(2, $packet, $packet.Length)
Write-Host "[INFO] CatReqMC(2): $pr" -ForegroundColor $(if ($pr -ne 0) {"Green"} else {"Red"})
} catch {
Write-Host "[ERROR] CatReqMC exception: $_" -ForegroundColor Red
}
# --- 정리 ---
try { [AllThatPay]::AllThatPayCloseModule() | Out-Null } catch {}
Write-Host "[DONE]" -ForegroundColor Cyan