所以我有一个来自支付网关的 API,它会在一天内返回所有交易,这些交易是 Json 格式的,类似于这样。
{
"status":"1",
"msg":"3 transactions settled on 2016-09-29",
"Txn_details":[
{
"payuid":"58800xxxxxx",
"txnid":"xxxxxx-27410",
"txndate":"2016-09-27 11:06:58",
"mode":"DC",
"amount":"15174.51",
"requestid":"xxxxxxxx",
"requestdate":"2016-09-29 18:17:18",
"requestaction":"capture",
"requestamount":"15174.51",
"mer_utr":"xxxxxxx",
"mer_service_fee":"151.75000",
"mer_service_tax":"22.76000",
"mer_net_amount":"15000.00000",
"bank_name":"VISA",
"issuing_bank":"xxxxxx",
"merchant_subvention_amount":"0.00"
},
{
"payuid":"58800xxxxxx",
"txnid":"xxxxxx-27410",
"txndate":"2016-09-27 11:06:58",
"mode":"DC",
"amount":"15174.51",
"requestid":"xxxxxxxx",
"requestdate":"2016-09-29 18:17:18",
"requestaction":"capture",
"requestamount":"15174.51",
"mer_utr":"xxxxxxx",
"mer_service_fee":"151.75000",
"mer_service_tax":"22.76000",
"mer_net_amount":"15000.00000",
"bank_name":"VISA",
"issuing_bank":"xxxxxx",
"merchant_subvention_amount":"0.00"
}
]
}
因此,在这个 Json 中,我必须查找一个名为的值,requestid
因此我必须通过从付款之日到接下来的 7 天调用 API 来查找该 ID,并匹配它具有的每天天气的每条记录requestid
。我的代码是这样的
function recursiveUTNRcheck($date_of_payment,$payment_reference,$rec_counter=7){
$date = substr($date_of_payment, 0, 10);
$utrNos ='';$brtoggle=false;
for($i=1;$i<=$rec_counter;$i++){
$sett_date= date('Y-m-d', strtotime($date. ' + '.$i.' days'));
$responsePayu = $this->callPayU($sett_date);
$utrnos=array('status'=>0);
if(!is_null($responsePayu)){
$utrNos = json_decode($responsePayu,true);
foreach ($utrNos['Txn_details'] as $value) {
# code...
if($value['requestid']==$payment_reference){
$utrnos['status']=1;
$utrnos['data'] = $value;
$brtoggle=true;
break;
}
}
if($brtoggle)
break;
}
}
return $utrnos;
}
我的问题是,如果假设一天有 2000 笔付款,那么 for 循环将不得不玩 2000 次,并且它必须每天继续这样做,直到它得到它的 ID,
最坏的情况可能是7*2000 = 14000
次。
所以我在想有没有更好的方法将字符串requestid
直接匹配到 json 字符串中?所以我认为性能可能比解码和检查数组好一点。
谢谢