PHP直接用get丟值
//範例一
$PostData = "a=abc&b=def";
$curl = curl_init("https://test.com/test.php?$PostData");
//檢查 curl 有無作用
if (! $curl) {
die( "Cannot allocate a new PHP-CURL handle" );
}
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); //SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//SSL
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
//這個若是沒設 , curl_exec($curl) 會直接印出來
curl_setopt ($curl, CURLOPT_HEADER, 0); // 得到回傳的HTTP頁面.
$data = curl_exec($curl);
echo "&data=$data"; //輸出傳回值
curl_close($curl);
//範例2綠介交易
/ 您的ECBank商店代號
$mer_id = '1';
// 虛擬帳號收單銀行
$setbank = 'ESUN'; // 玉山銀行
// 商店設定在ECBank管理後台的交易加密私鑰
$enc_key = '12345678901234567890';
// 有效繳費天數
$expire_day = '3';
// 自訂編號
$od_sob = '12345';
// 繳費金額
$amt = '300';
// 付款完成通知網址
$ok_url =rawurlencode('https://xxxx.com.tw/test/ecbank_vacc_auth.php');
//ECBank 虛擬帳號取號參數串接
$post_str ='mer_id='.$mer_id.
'&payment_type=vacc'.
'&setbank='.$setbank.
'&enc_key='.$enc_key.
'&od_sob='.$od_sob.
'&amt='.$amt.
'&expire_day='.$expire_day.
'&ok_url='.$ok_url;
// 若需一次大量取號,請自行將以下程式碼,包在?圈中(如for)
// 以curl方式背景取號
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,'https://ecbank.com.tw/gateway.php');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post_str);
$strAuth = curl_exec($ch);
if (curl_errno($ch)) {
$strAuth = false;
}
curl_close($ch);
if($strAuth) {
// 分解字串
parse_str($strAuth, $res);
// 判斷取號結果
if(!isset($res['error']) || $res['error'] != '0'){
echo "取號錯誤";
}else {
echo "銀行代碼:".$res['bankcode'];
echo "銀行帳戶:".$res['vaccno'];
echo "交易單號:".$res['tsr'];
}
} else {
echo "取號失敗";
}