如何将 API 响应数组字符串插入数据库
How to insert API response array string into database
我正在尝试集成银行支付网关,其中数据提交和处理运行良好,但收到的如下成功响应未插入数据库,因为它是数组形式的字符串。
BRN=837740&STC=000&RMK=success&TRN=5230896525&TET=2020/02/08 11:54:18 PM&PMD=CD&RID=253357&VER=1.0&CID=3636&TYP=Test&CRN=802406&CNY=INR&AMT=10000.00
例如:在这段代码中BRN是一个参数,837740是它的返回值同样STC是参数,000是它的返回值。
现在我想在 php 变量中设置所有这些值,以便插入数据,如果没有返回值,则应将 null 存储在 db 中,例如;
BRN=837741&STC=111&RMK=failure&TRN=1172146589&TET=&PMD=AIB&RID=126036&VER=1.0&CID=3636&TYP=Test&CRN=740076&CNY=INR&AMT=10000.00
我尝试了下面的代码,如果所有参数都返回了值,那么它就不会工作,因为分隔符序列被打乱了。
$chunks = preg_split('/(=|&)/', $qStr,-1, PREG_SPLIT_NO_EMPTY);
//print_r($chunks);
echo '<pre>';
print_r($chunks);
echo '</pre>';
/*
echo "<br>";
echo "<br>";
$nweString = $chunks[0];
for($i=1; $i<count($chunks); $i++) {
// $nweString .= ':'.$chunks[$i];
}
echo $nweString;
*/
echo "<br>";
echo "<br>";
echo "BRN = " . $BRN = $chunks[1] . "<br>";
// echo "BRN = " . $BRN = $chunks[2] . "<br>";
echo "STC = " . $STC = $chunks[3] . "<br>";
// echo "BRN = " . $BRN = $chunks[4] . "<br>";
if ($chunks[5] == "success") {$txtclr1 = '09CB00';}
echo "<font color='$txtclr1'>" ."RMK = " . $RMK = $chunks[5]."</font>". "<br>";
//echo "RMK = " . $RMK = $chunks[5] . "<br>";
//echo "BRN = " . $BRN = $chunks[6] . "<br>";
echo "TRN = " . $TRN = $chunks[7] . "<br>";
//echo "TET = " . $BRN = $chunks[8] . "<br>";
echo "TET = " . $TET = $chunks[9] . "<br>";
//echo "BRN = " . $BRN = $chunks[10] . "<br>";
echo "PMD = " . $PMD = $chunks[11] . "<br>";
//echo "BRN = " . $BRN = $chunks[12] . "<br>";
echo "RID = " . $RID = $chunks[13] . "<br>";
//echo "BRN = " . $BRN = $chunks[14] . "<br>";
echo "VER = " . $VER = $chunks[15] . "<br>";
//echo "BRN = " . $BRN = $chunks[16] . "<br>";
echo "CID = " . $CID = $chunks[17] . "<br>";
//echo "BRN = " . $BRN = $chunks[18] . "<br>";
echo "TYP = " . $TYP = $chunks[19] . "<br>";
//echo "BRN = " . $BRN = $chunks[20] . "<br>";
echo "CRN = " . $CRN = $chunks[21] . "<br>";
//echo "BRN = " . $BRN = $chunks[22] . "<br>";
echo "CNY = " . $CNY = $chunks[23] . "<br>";
//echo "BRN = " . $BRN = $chunks[24] . "<br>";
echo "AMT = " . $AMT = $chunks[25] . "<br>";
请帮忙....
我在使用数组和爆炸函数后得到了答案..
思考
我正在尝试集成银行支付网关,其中数据提交和处理运行良好,但收到的如下成功响应未插入数据库,因为它是数组形式的字符串。
BRN=837740&STC=000&RMK=success&TRN=5230896525&TET=2020/02/08 11:54:18 PM&PMD=CD&RID=253357&VER=1.0&CID=3636&TYP=Test&CRN=802406&CNY=INR&AMT=10000.00
例如:在这段代码中BRN是一个参数,837740是它的返回值同样STC是参数,000是它的返回值。
现在我想在 php 变量中设置所有这些值,以便插入数据,如果没有返回值,则应将 null 存储在 db 中,例如;
BRN=837741&STC=111&RMK=failure&TRN=1172146589&TET=&PMD=AIB&RID=126036&VER=1.0&CID=3636&TYP=Test&CRN=740076&CNY=INR&AMT=10000.00
我尝试了下面的代码,如果所有参数都返回了值,那么它就不会工作,因为分隔符序列被打乱了。
$chunks = preg_split('/(=|&)/', $qStr,-1, PREG_SPLIT_NO_EMPTY);
//print_r($chunks);
echo '<pre>';
print_r($chunks);
echo '</pre>';
/*
echo "<br>";
echo "<br>";
$nweString = $chunks[0];
for($i=1; $i<count($chunks); $i++) {
// $nweString .= ':'.$chunks[$i];
}
echo $nweString;
*/
echo "<br>";
echo "<br>";
echo "BRN = " . $BRN = $chunks[1] . "<br>";
// echo "BRN = " . $BRN = $chunks[2] . "<br>";
echo "STC = " . $STC = $chunks[3] . "<br>";
// echo "BRN = " . $BRN = $chunks[4] . "<br>";
if ($chunks[5] == "success") {$txtclr1 = '09CB00';}
echo "<font color='$txtclr1'>" ."RMK = " . $RMK = $chunks[5]."</font>". "<br>";
//echo "RMK = " . $RMK = $chunks[5] . "<br>";
//echo "BRN = " . $BRN = $chunks[6] . "<br>";
echo "TRN = " . $TRN = $chunks[7] . "<br>";
//echo "TET = " . $BRN = $chunks[8] . "<br>";
echo "TET = " . $TET = $chunks[9] . "<br>";
//echo "BRN = " . $BRN = $chunks[10] . "<br>";
echo "PMD = " . $PMD = $chunks[11] . "<br>";
//echo "BRN = " . $BRN = $chunks[12] . "<br>";
echo "RID = " . $RID = $chunks[13] . "<br>";
//echo "BRN = " . $BRN = $chunks[14] . "<br>";
echo "VER = " . $VER = $chunks[15] . "<br>";
//echo "BRN = " . $BRN = $chunks[16] . "<br>";
echo "CID = " . $CID = $chunks[17] . "<br>";
//echo "BRN = " . $BRN = $chunks[18] . "<br>";
echo "TYP = " . $TYP = $chunks[19] . "<br>";
//echo "BRN = " . $BRN = $chunks[20] . "<br>";
echo "CRN = " . $CRN = $chunks[21] . "<br>";
//echo "BRN = " . $BRN = $chunks[22] . "<br>";
echo "CNY = " . $CNY = $chunks[23] . "<br>";
//echo "BRN = " . $BRN = $chunks[24] . "<br>";
echo "AMT = " . $AMT = $chunks[25] . "<br>";
请帮忙....
我在使用数组和爆炸函数后得到了答案..
思考