Php 卷曲post数据并得到结果
这是我的代码:Php 卷曲post数据并得到结果,php,arrays,regex,curl,Php,Arrays,Regex,Curl,这是我的代码: <?php $url = 'http://huaweiunlockcalculator.com/v201-huawei-unlock-calculator-v3'; $fields = array('imei' => $_POST['imei']); //url-ify the data for the POST $fields_string=""; foreach($fields as $key=>$value) { $fields_string .= $k
<?php
$url = 'http://huaweiunlockcalculator.com/v201-huawei-unlock-calculator-v3';
$fields = array('imei' => $_POST['imei']);
//url-ify the data for the POST
$fields_string="";
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, 'http://huaweiunlockcalculator.com/v201-huawei-unlock-calculator-v3');
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute post
$result = curl_exec($ch);
$output=preg_match_all("/Unlock \(V[123]\): ([0-9]+)/",$result, $matches);
echo $matches[0];
//print_r($matches[0][2]);echo "<br>";
//print_r($matches[0][1]);echo "<br>";
//print_r($matches[0][0]);echo "<br>";
curl_close($ch);
//close connection
某些网页需要完整的post数据,无论值是否为null。一个名为http_build_query()的函数可以轻松地构建post或get查询字符串,您只需给出一个参数类型数组 什么是$result
?在$matches
中打印preg\u match\u all
的输入是什么。预期的产出是什么?错误的结果是什么?什么是正确的?
$url = "http://www.example.com/api/WalletVerification";
$params = array();
$inputs = array();
$inputs['rid']=100;//$retailer_id;
$inputs['merchantid']="B170127CT3D9H2XJAQUYF0L";
$inputs['amount']=10;//$wallet_raminfo;
$params =json_encode($inputs);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
$output= json_decode($result);
// print_r($output);
if($output->status=='000'){
$raminfostrans_id= $output->transactionid;
$payment_status=TRUE;
}else{
$payment_status=false;
$failure_msg="insuffient balance";
}