PHP接收和发送数据


PHP receives and sends data

我有以下php代码,它将数据发送到线索工具。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL =>"https://mkt.university-private.internal/form/submit",                                                                                                                                                                                                                                                                                                                                                                           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 => array('mauticform[f_email]' => '[email protected]','mauticform[f_name]' => 'Gabriel','mauticform[formId]' => '5'),
  CURLOPT_HTTPHEADER => array(
   "X-Forwarded-For: 91.92.103.192"
  ),
));

$response = curl_exec($curl);

curl_close($curl);
echo $response;

问题是我必须在php脚本中手动输入数据。

我现在有一个CRM,该CRM可以执行POST并以正文形式的数据发送以下数据:

[email protected]&name=Gabriel&IP=91.92.103.192&formId=5

我需要的是我的php代码接受具有以上这些值的CRM帖子,并使用来自CRM的数据在潜在客户工具中提出请求。

在我的erp上,我可以调用一个URL,然后我将调用我的script.php的URL。

他需要先发送转换并将该字段的名称放在该命名法之间,
Leads工具仅接受具有以下术语的字段:

mauticform[f_FIELDNAME]

任何人都可以帮助


非常容易,只需要利用$_POST将值传输到变量,然后使用它

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php

$P_email = $_POST['email'];
$P_name = $_POST['name'];
$P_formId = $_POST['formId'];
$P_ip = $_POST['IP'];

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL =>"https://mkt.university-private.internal/form/submit",  
  //..hidden                                                                                                                                                                                                                  
  CURLOPT_POSTFIELDS => array('mauticform[f_email]' => $P_email,'mauticform[f_name]' => $P_name,'mauticform[formId]' => $P_formId),

  //hidden

  //*update* FOR IP
  CURLOPT_HTTPHEADER => array(
   "X-Forwarded-For: $P_ip"
  ),
));


//..

更新:因此要解决动态变量名称

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Create an array to hold the name=value pairs
$P_arr = [];
//Loop over $_POST and populate $P_arr
foreach($_POST as $key=>$value){
    $P_arr[$key] = $value;
   // $key will run through all those keys' values you sent //name ,email ..
   // so will $value but on the literals like"[email protected]","Gabriel"
}

/* We have now an array of key value pairs */
// adjust the KEYs to"mauticform"'s format before using
$mauticformArr = [];

foreach($P_arr as $key=>$value){
   if($key != 'IP'){
      if($key!= 'formId')
        $mauticformArr['mauticform[f_'.$key .']'] = $value;
      else
        $mauticformArr['mauticform['.$key .']'] = $value;      
   }
}

// Then use inside you code as
curl_setopt_array($curl, array(
  CURLOPT_URL =>"https://mkt.university-private.internal/form/submit",  
  //..hidden                
CURLOPT_POSTFIELDS => $mauticformArr,
  //..hidden
  //..


您可能会发现" Guzzle"比实际使用CURL效果更好...