我正在整合一个支付网关在我的网站和支付网关启动是通过表单,其中包括隐藏的字段,以张贴数据。
表单的HTML代码是:(仅粘贴HTML代码不能共享详细信息,因为API支持不好,而且由于5-10次频繁的请求,它们还删除了我的沙箱存储ID。)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Easypay</title>
</head>
<body>
<form action="https://easypaystg.easypaisa.com.pk/easypay/Index.jsf" method="POST" id="easyPayStartForm" target="_blank">
<input name="storeId" value="<?php echo $storeId; ?>" hidden = "true"/>
<input name="amount" value="<?php echo $amount; ?>" hidden = "true"/>
<input name="postBackURL" value="<?php echo $postBackURL; ?>" hidden = "true"/>
<input name="orderRefNum" value="<?php echo $orderRefNum; ?>" hidden = "true"/>
<input type ="text" name="expiryDate" value="<?php echo $expiryDate; ?>">
<input type="hidden" name="autoRedirect" value="<?php echo $autoRedirect; ?>" >
<input type ="hidden" name="paymentMethod" value="<?php echo $paymentMethod; ?>">
<input type ="hidden" name="emailAddr" value="<?php echo $emailAddr; ?>">
<input type ="hidden" name="mobileNum" value="<?php echo $mobileNum; ?>">
<input type ="hidden" name="merchantHashedReq" value="<?php echo $hashRequest; ?>">
<button type="submit">Submit</button>
</form>
</body>
</html>当我提交表单时,它将我重定向到支付门户,在成功的交易之后,它会将我抛回回发URL。
通过表单支付网关非常好,但是由于表单将包含敏感网关API的细节,因此我试图通过PHP Curl请求将表单数据发布到后端,以确保安全事务。但是,当我尝试使用PHP curl请求时,它会显示一个无效的请求:
下面是我的PHP Curl请求代码:
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://easypay.easypaisa.com.pk/easypay/Index.jsf",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "storeId=$storeId&amount=$amount&postBackURL=$postBackURL&orderRefNum=$orderRefNum&expiryDate=$expiryDate&autoRedirect=$autoRedirect&paymentMethod=$paymentMethod&emailAddr=$emailAddr&mobileNum=$mobileNum&merchantHashedReq=$merchantHashedReq",
CURLOPT_HTTPHEADER => array(
"Content-Type: application/x-www-form-urlencoded"
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>I将以下python请求(他们在文档中给出)更改为PHP请求:
(数据是虚拟的,所以请求不会成功,请不要尝试运行这段代码,它只是用于python --我已经将它转换为PHP CURL请求)
import httplib,urllib
host='https://easypay.easypaisa.com.pk'
url ='/easypay/Index.jsf'
values ={'storeId':'43','amount':'10','postBackURL':'http://www.my.online-store.com/transaction/MessageHandler','orderRefNum':'1101','expiryDate':'20140606201521',‘merchantHashedReq’=> ‘aasldfjlaksdjf;laksjdf;asdf--=====’,‘autoRedirect’=> ‘0’,‘paymentMethod’=> ‘OTC_PAYMENT_METHOD’,‘emailAddr’=> ‘test.abcd@domain.com’,‘mobileNum’=> ‘03321041021’}
headers={'User-Agent': 'python','Content-Type':'application/x-www-form-urlencoded',}
values =urllib.urlencode(values)
conn = httplib.HTTPSConnection(host)
conn.request("POST",url,values,headers)
response =conn.getresponse()data=response.read()我是不是做错了什么当肌酐PHP curl request
发布于 2020-08-23 20:06:14
如果要将CURLOPT_POSTFIELDS设置为字符串,则需要对值进行url编码,则使用数组更容易、更干净,还需要使用选项CURLOPT_POST => true。
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => [
'storeId' => $storeId,
'amount' => $amount,
'postBackURL' => $postBackURL,
'orderRefNum' => $orderRefNum,
'expiryDate' => $expiryDate,
'autoRedirect' => $autoRedirect,
'paymentMethod' => $paymentMethod,
'emailAddr' => $emailAddr,
'mobileNum' => $mobileNum,
'merchantHashedReq' => $merchantHashedReq
],https://stackoverflow.com/questions/63551254
复制相似问题