//確認資料長度沒錯 if (strlen($a[glFrom]) == 8 && strlen($a[glTo]) == 8 && strlen($a[glCity]) == 3) { $app++; $str_cdno = "select AES_DECRYPT(f6no,'{$key_str_ch}') as f6no,AES_DECRYPT(c5no,'{$key_str_ch}') as c5no,AES_DECRYPT(lsno,'{$key_str_ch}') as lsno from o_cdno where sr='{$a['authsr']}' limit 1 "; $res_cdno = mysql_query($str_cdno); $N_cdno = @mysql_fetch_array($res_cdno); $a['cardno'] = $N_cdno[f6no] . $N_cdno[c5no] . $N_cdno[lsno]; $MIDaa_OUT .= "D"; //固定D $MIDaa_OUT .= " "; //空格正確,其它錯誤 $MIDaa_OUT .= CARD_SPACE("15", $aMID[mid]); //特店代號 , 左靠右補空白 $MIDaa_OUT .= " "; //空格正確,其它錯誤 $MIDaa_OUT .= CARD_SPACE("19", $a[cardno]); //卡號 , 左靠右補空白 $MIDaa_OUT .= " "; //空格正確,其它錯誤 $MIDaa_OUT .= sprintf("%06s", $a[auth]); //授權碼 $MIDaa_OUT .= " "; //空格正確,其它錯誤 $MIDaa_OUT .= substr($a[isdt], 4, 4) . substr($a[isdt], 0, 4); //交易日期 MMDDYYYY $MIDaa_OUT .= " "; //檢核結果 $MIDaa_OUT .= sprintf("%07d", $a[amount]); //金額 $MIDaa_OUT .= " "; //檢核結果
//取出交易日 //先濾掉卡號的空格, 有些卡不是 16碼 $aco[cardno] = str_replace(' ', '', $aco[cardno]); if (preg_match("/[\\x{4e00}-\\x{9fa5}]/u", $bill_name)) { //中文 縮小為23 並在最後補2個空白 $ListAuth .= '1' . $close_dt . CARD_ZAO(16, $aco[cardno]) . '000' . $asv . sprintf("%06s", $aco['auth']) . sprintf("%010s", $amount_ok) . MB_CARD_SPACE(23, substr($bill_name, 0, 10 * 3)) . $aco['eci'] . ' ' . "\r\n"; } else { //英文 $ListAuth .= '1' . $close_dt . CARD_ZAO(16, $aco[cardno]) . '000' . $asv . sprintf("%06s", $aco['auth']) . sprintf("%010s", $amount_ok) . CARD_SPACE(25, substr($bill_name, 0, 25)) . $aco['eci'] . ' ' . "\r\n"; } $trailer++; if ($ss_nb == $PSnb || $amq == $ss_all) { if (preg_match("/[\\x{4e00}-\\x{9fa5}]/u", $bill_name)) { $ListAuthTOP .= '8' . date("ymd") . $MID_nb . $MID_nb_ch . sprintf("%08s", $ss_big) . sprintf("%010s", $ss_big_amount) . sprintf("%08s", $ss_smo) . sprintf("%010s", $ss_smo_amount) . ' ' . MB_CARD_SPACE(38, substr($bill_name, 0, 10 * 3)) . ' ' . "\r\n"; } else { $ListAuthTOP .= '8' . date("ymd") . $MID_nb . $MID_nb_ch . sprintf("%08s", $ss_big) . sprintf("%010s", $ss_big_amount) . sprintf("%08s", $ss_smo) . sprintf("%010s", $ss_smo_amount) . ' ' . CARD_SPACE(40, substr($bill_name, 0, 40)) . ' ' . "\r\n"; } $ListAuthALL .= $ListAuthTOP . $ListAuth; $ss_nb = 0; //批次筆數 $ss_big = 0; //請款筆數 $ss_smo = 0; //退款筆數 $ss_big_amount = 0; //請款金額 $ss_smo_amount = 0; //退款金額 $ListAuthTOP = ''; $ListAuth = ''; $trailer++;
$Ptt = '01'; $aco[amount] = 0 - $aco[amount]; //將負值轉成正值 } //資料 $axa_hoho .= sprintf("%010s", $aMID[mid]); //10碼 mid 001-010 $axa_hoho .= sprintf("%08s", $aTID[tid]); //08碼 tid 011-018 $axa_hoho .= CARD_SPACE(40, $aco[authsr]); //40碼 訂單編號, 左靠右補空白 $axa_hoho .= str_repeat(' ', 19); //19碼 空白 $axa_hoho .= sprintf("%08s", $aco['amount']); //08碼 交易金額, 右靠前補零 078-085 $axa_hoho .= CARD_SPACE(8, $aco['auth']); //08碼 授權碼, 左靠右補空白 086-093 $axa_hoho .= $Ptt; //02碼 交易碼: 01:退貨,02:請款 094-095 $axa_hoho .= substr($aff['dt'], 0, 8); //08碼 交易日期, YYYYMMDD 096-103 $axa_hoho .= str_repeat(' ', 16); //16碼 使用者自訂欄位, 左靠右補空白 104-119 $axa_hoho .= str_repeat(' ', 40); //40碼 卡人資訊, 左靠右補空白, 此欄位需填放 BIG5〝全形字元〞, 如果沒有資料請填全形空白 120-159 //以下都是回傳用欄, 送出為空 $axa_hoho .= str_repeat(' ', 6); //06碼 帳單處理日期YYMMDD (西曆) 160-165 $axa_hoho .= str_repeat(' ', 3); //03碼 回應碼,固定三碼“00 "為請款成功,其他代碼則是請款失敗 166-168 $axa_hoho .= str_repeat(' ', 16);
$amq = mysql_num_rows($q); //共有多少筆資料 if ($amq > 0) { //確認有帳, 才動作 while ($a = mysql_fetch_array($q)) { if ($authSR != $a[authsr]) { //確定沒重覆才作 //確認資料長度沒錯 //if((strlen($a[glFrom])==8)&&(strlen($a[glTo])==8)&&(strlen($a[glCity])==3)){ if (strlen($a[glCity]) == 3) { $str_cdno = "select AES_DECRYPT(f6no,'{$key_str_ch}') as f6no,AES_DECRYPT(c5no,'{$key_str_ch}') as c5no,AES_DECRYPT(lsno,'{$key_str_ch}') as lsno from o_cdno where sr='{$a['authsr']}' limit 1 "; $res_cdno = mysql_query($str_cdno); $N_cdno = @mysql_fetch_array($res_cdno); $a['cardno'] = $N_cdno[f6no] . $N_cdno[c5no] . $N_cdno[lsno]; //DATA $MIDaa_OUT .= 'D ' . CARD_SPACE("15", $a_mid) . ' ' . CARD_SPACE("19", $a[cardno]) . ' ' . sprintf("%06s", $a[auth]) . ' ' . substr($a[isdt], 4, 4) . substr($a[isdt], 0, 4) . ' ' . sprintf("%07d", $a[amount]) . ' ' . sprintf("%08d", $a[glFrom]) . ' ' . sprintf("%08d", $a[glTo]) . ' ' . sprintf("%03d", $a[glCity]) . ' A ' . "\n"; $ne_news++; //寫入 o_glu 請款資料庫 $strcos = "insert into o_glu "; $strcos .= "(aa,sr,auth,paydt,glFrom,glTo,glCity,isGuolu,gludt,stat,client,amount)"; $strcos .= "values(0,'{$a['authsr']}','{$a['auth']}','{$a['isdt']}','{$a['glFrom']}','{$a['glTo']}','{$a['glCity']}','{$a['isGuolu']}','{$hohsnYMD}','送審中','{$a['client']}','{$a['amount']}')"; mysql_query($strcos, $plink); } } $authSR = $a[authsr]; } } } $allamq = $re_nums + $ne_news; //merge台鐵國旅檔 //讀台鐵關帳檔, 把檔案合併
$All_auth_amt += $auth_amt; //總請款金額 $All_repy_ite += $repy_ite; //總退款筆數 $All_repy_amt += $repy_amt; //總退款金額 //== 02 資料內容 //02000002GWPGTW0101900586GREENWORLD 69599 $OUT_txt_02 = "02"; //02碼, 交易類別代碼, always 02 Record Type //$OUT_txt_02.=sprintf("%06d",$c_aa); //06碼, 流水號, 檔案完成後才編進去 $OUT_txt_02 .= 'GWPGTW'; //06碼, Submission Reference $OUT_txt_02 .= $aMID[mid]; //10碼, 交易商店代號mid $OUT_txt_02 .= CARD_SPACE(30, $aMID[enname]); //30碼, 商店名稱(左靠後面補空白) $OUT_txt_02 .= '69'; //02碼, Industry Code 行業代碼 $OUT_txt_02 .= '599'; //03碼, Sub Industry Code 行業代碼 $OUT_txt_02 .= str_repeat(' ', 291); //291碼, Reserved $OUT_txt_02 .= "\r\n"; // 04 資料內容 //0400000500000200000001000000000100 $OUT_txt_04 = "04"; //02碼, 交易類別代碼, always 04 Record Type //$OUT_txt_04.=sprintf("%06d",$c_aa); //06碼, 流水號, 檔案完成後才編進去 $OUT_txt_04 .= sprintf("%06d", $All_ite_02); //06碼, 總筆數
//檔案開頭 X(2) 此欄位固定為”FD”(檢核項) $OUT_txt .= CARD_SPACE(20, $aco[authsr]); //訂單編號 X(20) 與原授權交易的訂單編號相同 $OUT_txt .= $Type_amt; //交易碼 X(2) 請款交易‘05’ ,退貨交易‘06’ , 非’05’及’06’交易碼會踢除該筆交易。 $OUT_txt .= sprintf("%010d", $aco['amount']) . "00"; //金額 9(12) 整數10位,小數2位(右靠左補0) $OUT_txt .= " "; //回覆碼 X(2) 半形白空 , 回覆 只有'00' 成功其它都失敗 $OUT_txt .= str_repeat(' ', 25); //消費明細英文說明 X(25) 半型字25個字元,長度不足者補半形空白。 $OUT_txt .= str_repeat(' ', 20); //消費明細中文說明 X(40) 中文全形字20個字元,長度不足補全形空白 $OUT_txt .= str_repeat(' ', 20); //備註X(20) 依據專案使用,否則給空白 $OUT_txt .= CARD_SPACE(25, $aco[sr]); //備註2 X(25) 給空白 $OUT_txt .= "\r\n"; $strUP = "update o_close set stat='關帳中' where sr='{$aco['sr']}' and stat='要關帳' limit 1 "; //更新為關帳中 mysql_query($strUP, $plink); $strUP = "update o_close set bank_stat='關帳中' where sr='{$aco['sr']}' and bank_stat='要關帳' limit 1 "; mysql_query($strUP, $plink); $strUP = "update o_close_bank set stat='關帳中' where sr='{$aco['sr']}' and stat='要關帳' limit 1 "; mysql_query($strUP, $plink); } $OUT_txt_S = "FT"; //檔案開頭 X(2) 此欄位固定為”FT”(檢核項) $OUT_txt_S .= sprintf("%06d", $auth_ite); //筆數合計 9(6) (檢核項) $OUT_txt_S .= "\r\n";
$a_amount = 0 - $axa_amount; //將負值轉成正值 } //單筆金額 if ($aco[amount] > 0) { $Ptt = '02'; $aco[amount] = $aco[amount]; } else { $Ptt = '01'; $aco[amount] = 0 - $aco[amount]; //將負值轉成正值 } if ($aff[auth] == '111111') { $axa_hoho .= sprintf("%010s", $aMID[mid]) . sprintf("%08s", $aTID[tid]) . CARD_SPACE(40, $aco[authsr]) . ' ' . sprintf("%08s", $aco['amount']) . CARD_SPACE(8, $aco['auth']) . $Ptt . substr($aff['dtymd'], 0, 8) . ' ' . ' ' . " " . str_repeat(' ', 20) . "\r\n"; } else { $axa_hoho .= sprintf("%010s", $aMID[mid]) . sprintf("%08s", $aTID[tid]) . CARD_SPACE(40, $aco[authsr]) . ' ' . sprintf("%08s", $aco['amount']) . CARD_SPACE(8, $aco['auth']) . $Ptt . substr($aff['dt'], 0, 8) . ' ' . ' ' . " " . str_repeat(' ', 20) . "\r\n"; } } else { $strUP = "update " . $O_CLOSE . " set stat='被拒絕' where stat='要關帳' and sr='{$aco['sr']}' limit 1 "; //更新為被拒絕 $res = @mysql_query($strUP, $plink); if (!$res) { $sql_error .= $strUP . "<br>"; } $strUP = "update " . $O_CLOSE . " set bank_stat='被拒絕' where bank_stat='要關帳' and sr='{$aco['sr']}' limit 1 "; mysql_query($strUP, $plink); $strUP = "update o_close_bank set stat='被拒絕' where stat='要關帳' and sr='{$aco['sr']}' limit 1 "; mysql_query($strUP, $plink); $warning_msg .= $aco[sr] . "請款金額超過授權金額, 關帳壓回被拒絕<br>"; $warning_nums++; }
$strUP = "update o_close set bank_stat='關帳中' where sr='{$aco['sr']}' and bank_stat='要關帳' limit 1 "; mysql_query($strUP, $plink); $strUP = "update o_close_bank set stat='關帳中' where sr='{$aco['sr']}' and stat='要關帳' limit 1 "; mysql_query($strUP, $plink); } } $All_auth_ite += $auth_ite; //總請款筆數 $All_auth_amt += $auth_amt; //總請款金額 $All_repy_ite += $repy_ite; //總退款筆數 $All_repy_amt += $repy_amt; //總退款金額 $OUT_txt_S = "S"; $OUT_txt_S .= CARD_SPACE(15, $S_MID); //000812770000115(MID15碼左靠後補空白) 2-16 $OUT_txt_S .= sprintf("%06d", $auth_ite); //000000(6碼請款筆數前補0) 17-22 $OUT_txt_S .= sprintf("%010d", $auth_amt) . "00"; //000000000000(10+2碼小數請款金額) 23-34 $OUT_txt_S .= sprintf("%06d", $repy_ite); //000000(6碼退款筆數) 35-40 $OUT_txt_S .= sprintf("%010d", $repy_amt) . "00"; //(10+2碼小數退款金額) 41-52 $OUT_txt_S .= "\r\n"; $All_OUT_txt .= $OUT_txt . $OUT_txt_S; //全資料 } } $OUT_txt_T = "T";