Page History: [PHP] 서명(signature) 생성 샘플코드
Compare Page Revisions
Page Revision: 2012/06/01 19:27
서명(signature) 생성 PHP 샘플코드
here is slight difference between .Net and PHP. While .Net expects byte array as key, PHP expects string as key. Thus we have to form string representing byte array.
예제1
<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$sig = hash_hmac('sha256', "t=HelloWorld&r=10", $key);
echo '<img src="http://mqr.kr/qr/?t=HelloWorld&r=10&sign='.$sig.'"/>';
?>
예제1
- 현재 날짜 / 시간으로 QR 코드를 생성을위한 PHP 코드 샘플
<?php
$key = pack('c*', 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff);
$text = date('Y.m.d H:i:s');
$query = 't='.urlencode($text).'&r=10&j=1&m=20&lb=fccd13<=ed1e2e&rt=155ca2';
$sig = hash_hmac('sha256', $query, $key);
echo '<img src="http://mqr.kr/qr/?'.htmlentities($query).'&sign='.$sig.'"/>';
?>
- $text 변수에 텍스트를 삽입할 수 있습니다