-1

我正在从 Controller 调用 360Dialog API,但将 $minombre 传递给 TO 字段并将 $minumero 作为有效负载的参数传递给参数文本对我不起作用。似乎 Heredoc <<<'PAYLOAD'不允许我这样做,或者我做错了。

class MensajeController extends Controller
{

public function enviar(Request $request, $plantilla_id)
{
$empresas =  User::find(Auth::user()->id)->empresas()->where('estado', '=', 1)->get();
$plantilla = Plantilla::find($plantilla_id);
$minombre = "Eduardo Tapia";
$minumero = "56996436710";
        
// comienzo llamado API 360Dialog

$url = "https://waba-sandbox.360dialog.io/v1/messages";

$payload = <<<'PAYLOAD'
{
    "to": $minumero,
    "type": "template",
    "template": {
        "namespace": "c8ae5f90_307a_ca4c_b8f6_d1e2a2573574",
        "language": {
            "policy": "deterministic",
            "code": "en"
        },
        "name": "first_welcome_messsage",
        "components": [
            {
                "type": "body",
                "parameters": [
                    {
                        "type": "text",
                        "text": $minombre
                    }
                ]
            }
        ]
    }
}
PAYLOAD;
$headers = [
    "Content-Type: application/json",
    "D360-Api-Key: DkdU6Z_sandbox",
];

$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => $headers,
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "curl error: " . $err;
} else {
    echo $response;
}

如何传递可变参数?

4

0 回答 0