튜토리얼

PHP 개발환경에서 바로써트 SDK를 추가하여 본인인증 요청(requestIdentity) 함수를 구현하는 예시입니다.

1. BaroCert SDK 추가

Barocert PHP SDK를 추가하기 위해 Laravel 프로젝트의 composer.json 파일의 require 필드 오브젝트에 PassCert SDK 정보를 추가후 composer update 커멘드를 실행하여 barocert 패키지를 설치합니다.

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^7.2.5",
        "fideloper/proxy": "^4.2",
        "fruitcake/laravel-cors": "^1.0",
        "laravel/framework": "^7.30.3",
        "laravel/tinker": "^2.0",
        "linkhub/barocert": "^1.4.0"
    },
    // 생략 ...
}

2. BaroCert SDK 설정

SDK 설정을 위해 laravel 프로젝트 config 폴더에 barocert.php 파일을 추가합니다.

<?php

return [

	// 링크아이디
	'LinkID' => 'TESTER',

	// 비밀키
	'SecretKey' => 'SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=',

	// 통신방식 기본은 CURL , PHP curl 모듈 사용에 문제가 있을 경우 STREAM 기재가능.
	// STREAM 사용시에는 php.ini의 allow_url_fopen = on 으로 설정해야함.
	'LINKHUB_COMM_MODE' => 'CURL',

	// 인증토큰 IP 검증 설정, ture-사용, false-미사용, (기본값:true)
	'IPRestrictOnOff' => true,

	// 통신 고정 IP, true-사용, false-미사용, (기본값:false)
	'UseStaticIP' => false
];

3. RequestIdentity 기능 구현

Controller를 추가하고 클래스 생성자(__construct)에 바로써트 서비스 클래스 초기화 코드와 RequestIdentity 함수를 추가합니다.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Linkhub\LinkhubException;
use Linkhub\Barocert\BarocertException;
use Linkhub\Barocert\PasscertService;
use Linkhub\Barocert\PassIdentity;
use Linkhub\Barocert\PassIdentityVerify;

class PasscertController extends Controller
{
	public function __construct() {

		// 통신방식 설정
		define('LINKHUB_COMM_MODE', config('barocert.LINKHUB_COMM_MODE'));

		// 패스써트 서비스 클래스 초기화
		$this->PasscertService = new PasscertService(config('barocert.LinkID'), config('barocert.SecretKey'));

		// 인증토큰 IP 검증 설정, ture-사용, false-미사용, (기본값:true)
		$this->PasscertService->IPRestrictOnOff(config('barocert.IPRestrictOnOff'));

		// 통신 고정 IP, true-사용, false-미사용, (기본값:false)
		$this->PasscertService->UseStaticIP(config('barocert.UseStaticIP'));
	}

	// HTTP Get Request URI -> 함수 라우팅 처리 함수
	public function RouteHandelerFunc(Request $request){
		$APIName = $request->route('APIName');
		return $this->$APIName();
	}

	/*
	 * 패스 이용자에게 본인인증을 요청합니다.
	 * https://developers.barocert.com/reference/pass/php/identity/api#RequestIdentity
	 */
	public function RequestIdentity(){

		// 이용기관코드 (파트너 사이트에서 확인가능)
		$clientCode = '023070000014';

		// 본인인증 요청정보 객체
		$PassIdentity = new PassIdentity();

		// 수신자 휴대폰번호 - 11자 (하이픈 제외)
		$PassIdentity->receiverHP = $this->PasscertService->encrypt('01012341234');
		// 수신자 성명 - 80자
		$PassIdentity->receiverName = $this->PasscertService->encrypt('홍길동');
		// 수신자 생년월일 - 8자 (yyyyMMdd)
		$PassIdentity->receiverBirthday = $this->PasscertService->encrypt('19700101');

		// 요청 메시지 제목 - 최대 40자
		$PassIdentity->reqTitle = '본인인증 요청 메시지 제목';
		// 요청 메시지 - 최대 500자
		$PassIdentity->reqMessage = $this->PasscertService->encrypt('본인인증 요청 메시지');
		// 고객센터 연락처 - 최대 12자
		$PassIdentity->callCenterNum = '1600-9854';
		// 요청 만료시간 - 최대 1,000(초)까지 입력 가능
		$PassIdentity->expireIn = 1000;
		// 서명 원문 - 최대 2,800자 까지 입력가능
		$PassIdentity->token = $this->PasscertService->encrypt('본인인증 요청 원문');

		// 사용자 동의 필요 여부
		$PassIdentity->userAgreementYN = true;
		// 사용자 정보 포함 여부
		$PassIdentity->receiverInfoYN = true;

		// AppToApp 인증요청 여부
		// true - AppToApp 인증방식, false - 푸시(Push) 인증방식
		$PassIdentity->appUseYN = false;
		 // ApptoApp 인증방식에서 사용
		// 통신사 유형('SKT', 'KT', 'LGU'), 대문자 입력(대소문자 구분)
		// $PassIdentity->telcoType = 'SKT';
		// ApptoApp 인증방식에서 사용
		// 모바일장비 유형('ANDROID', 'IOS'), 대문자 입력(대소문자 구분)
		// $PassIdentity->deviceOSType = 'IOS';

		try {
			$result = $this->PasscertService->requestIdentity($clientCode, $PassIdentity);
		}
		catch(BarocertException $re) {
			$code = $re->getCode();
			$message = $re->getMessage();
			return view('Response', ['code' => $code, 'message' => $message]);
		}

		return view('PassCert/RequestIdentity', ['result' => $result]);
	}
}

호출 결과를 출력하는 페이지(RequestIdentity.blade.php)를 resources/views/Passcert/에 추가합니다.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<link rel="stylesheet" type="text/css" href="/css/example.css" media="screen"/>
	<title>Barocert Laravel Example</title>
</head>
<body>
<div id="content">
	<p class="heading1">Response</p>
	<br/>
	<fieldset class="fieldset1">
		<legend>{{\Request::fullUrl()}}</legend>
		<ul>
			<li>접수아이디 (ReceiptID) : {{ $result->receiptID }}</li>
			<li>앱스킴 (Scheme): {{ $result->scheme }}</li>
			<li>앱다운로드URL (MarketURL): {{ $result->marketUrl }}</li>
		</ul>
	</fieldset>
</div>
</body>
</html>

4. 결과 확인

함수 호출이 정상적으로 처리되면 "푸시(Push) 인증" 방식은 접수아이디(32자리 숫자)가 반환되며, "앱투앱 인증" 방식은 접수아이디와 AppScheme 이 함께 반환됩니다. 실패인 경우 BarocertException으로 오류코드("-"로 시작하는 8자리 숫자값)와 오류메시지가 반환됩니다. [오류코드]