Last active
March 10, 2022 06:00
-
-
Save httpspace/1e40d5070336a81fc0465d841d5ee5ae to your computer and use it in GitHub Desktop.
pay範例
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$path = 'WebToAppReq'; | |
//qrcode名稱 | |
$qr_code_name = '公司名稱'; | |
//交易金額 | |
$d1 = '500000'; | |
//訂單編號 | |
$d2 = strtotime('now'); | |
//安全碼 | |
$d3 = 'ATjp0KxKU6GG'; | |
//收單行資訊 | |
$d11 = '00,01701784942645000100010001;01,01701784942645000100010001'; | |
//QR Code 效期 | |
$d12 = date('Ymdhis', strtotime('now') + 86400 * 3); | |
// echo $d12; | |
//加密基碼 | |
$base_key = 'xxxxxx'; | |
//驗證參數 | |
$key = pack('H*', 'xxx'); | |
$iv = 'FOCASAPIFOCASAPI'; | |
$qrcode_str = "TWQRP://{$qr_code_name}/158/01/V1?D1={$d1}&D2={$d2}&D3={$d3}&D11={$d11}&D12={$d12}"; | |
$qrcode_str = urlencode($qrcode_str); | |
$url = urlencode('https://vvvv.com/testcallback'); | |
$Payment = array( | |
"acqBank" => "017", | |
"terminalId" => "00010001", | |
"merchantId" => "017849426450001", | |
"txnType" => "01", | |
"orderNumber" => strtotime('now'), | |
"encRetURL" => encodeQrcode2($url), | |
"encQRCode" => encodeQrcode2($qrcode_str), | |
); | |
$sign = verify($Payment); | |
$Payment['verifyCode'] = $sign; | |
echo '<pre>'; | |
var_dump($Payment); | |
echo check_out($path, $Payment); | |
function check_out($method, $form, $post = true) | |
{ | |
$szHtml = '<!doctype html>'; | |
$szHtml .= '<html>'; | |
$szHtml .= '<head>'; | |
$szHtml .= '<meta charset="utf-8">'; | |
$szHtml .= '</head>'; | |
$szHtml .= '<body>'; | |
$szHtml .= '<form name="webpay" id="webpay" method="post" action="https://www.focas-test.fisc.com.tw/FOCAS_WS/API20/QRP/V2/' . $method . '" style="display:none;">'; | |
foreach ($form as $k => $val) { | |
$szHtml .= '<input type="text" name="' . $k . '" value="' . $val . '" type="hidden">'; | |
} | |
$szHtml .= '</form>'; | |
$szHtml .= '<script type="text/javascript">'; | |
if ($post) $szHtml .= 'document.getElementById("webpay").submit();'; | |
$szHtml .= '</script>'; | |
$szHtml .= '</body>'; | |
$szHtml .= '</html>'; | |
return $szHtml; | |
} | |
function verify($config) | |
{ | |
global $base_key; | |
ksort($config); | |
$v = $config; | |
return hash('sha256', implode("", $v) . $base_key); | |
} | |
function encodeQrcode2(string $qrcodedata, $padding = 4) | |
{ | |
global $iv, $key; | |
$qrcodedatahex = bin2hex($qrcodedata); | |
$datalen = strlen($qrcodedata); | |
//qrcode加密資料長度2 bytes,所以16進位表示要補到4碼 | |
$datalenhex = str_pad(dechex($datalen), $padding, '0', STR_PAD_LEFT); | |
$inputdatahex = $datalenhex . $qrcodedatahex; | |
$inputdata = pack('H*', $inputdatahex); | |
$encresult = strtoupper(bin2hex(openssl_encrypt($inputdata, 'aes-128-cbc', $key, OPENSSL_RAW_DATA, $iv))); //加密後的資料 | |
$keyver = '02'; //加密基碼版本02,需依實際資料指定 | |
$enchex = $keyver . $encresult; //加密版本||加密後的資料 | |
$encbase64 = base64_encode(pack('H*', $enchex)); //轉base64 | |
$encurlencode = urlencode($encbase64); //進行url encode | |
return $encurlencode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment