【发布时间】:2020-09-16 18:22:07
【问题描述】:
请原谅我的英语。 我的系统是用php设计的,是关于连接亚马逊自动订购系统(由python和selenium设计的)
这是场景: 客户在我的网站上订购产品 -> 将数据发送到亚马逊自动订购系统(由 python 和 selenium 设计) -> 使用自动化系统下订单 -> 将数据发送到我的系统(php)
我想知道如何将数据发送到 python 并从 python 获取数据 我认为将 Json 格式的数据发送到 python 并从 python 获取 Json 格式的数据会起作用
这里是 python 代码 python code
这里是向 python 发送数据的临时 php 代码
function curlPostForOrder($url, $params){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_USERPWD, $params['client_token'].":"."");
$JsonData = json_encode($params['data']); //Json data post
curl_setopt($ch, CURLOPT_POSTFIELDS, $JsonData); //Set Post Data ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set ReturnTransfer;
curl_setopt($ch, CURLOPT_POST, 1); //Set Post value true ( regular HTTP POST )
$headers = array();
$headers[] = "Content-Type: application/x-www-form-urlencoded";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$retValue['status'] =true;
$ret= curl_exec($ch);
error_log($ret);
if ($ret==false) {
echo 'Error: Curl Error';
$retValue['status'] = false;
$retValue['error_msg'] = curl_error($ch);
}else{
$retValue['data'] = json_decode($ret,true);
}
curl_close($ch);
return $retValue;
这是从 python 获取数据的临时 php 代码
function curlPostForRetrieve($url, $params){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL , $url);
curl_setopt($ch, CURLOPT_USERPWD, $params['client_token'].":".""); //Set UserPWD;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //Set ReturnTransfer;
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$retValue['status'] =true;
$ret=curl_exec($ch);
if ($ret==false) {
echo 'Error: Curl Error';
$retValue['status'] = false;
$retValue['error_msg'] = curl_error($ch);
}else{
$retValue['data'] = json_decode($ret,true);
}
curl_close ($ch);
return $retValue;
感谢您的意见
【问题讨论】:
-
我想我回答了你最后一个类似的问题,但你到底在寻找什么?只是用于读取生成的 JSON 文件的 python 代码,还是更具体的代码?
-
谢谢你的回答我看到你的回答但我还是不明白具体要做什么我想知道python代码来读取php的结果并将数据发送到php更详细