如何在curl函数中创建工作变量(PHP)

kulphzqa  于 2022-11-13  发布在  PHP
关注(0)|答案(1)|浏览(178)

我需要将数据从varlable saved 1传递到reply_message(第45行)中,但它不起作用
“{“正文”我试过了:“${saved 1}"}但无响应。
预期结果是“text”:“第1行\n 123 \n第3行”
输出量
线路1
123
线路3
任何帮助都是感激的谢谢&问候

<?php
    send_reply($access_token,$reply_message);
        
    
        $reply_message='{
            
            "messaging_type": "RESPONSE",
            "recipient": {
                "id": "1631126643573991"
                },
            "message": {
                "text": "line1 \n $saved1 \n line 3"                
                }
        }';
        
    send_reply($access_token,$reply_message);
    }
    

    function send_reply($access_token='',$reply='')
    {
        $url="https://graph.facebook.com/v14.0/me/messages?access_token=$access_token";
        $ch = curl_init();
        $headers = array("Content-type: application/json");
        curl_setopt($ch, CURLOPT_URL,$url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST,1);
        curl_setopt($ch, CURLOPT_POSTFIELDS,$reply);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $st=curl_exec($ch);
        $result=json_decode($st,TRUE);
        return $result;
    }

?>
hgqdbh6s

hgqdbh6s1#

如下所示,对$saved1使用串联。

$reply_message='{

            "messaging_type": "RESPONSE",
            "recipient": {
                "id": "1631126643573991"
                },
            "message": {
                "text": "line1 \n '.$saved1.' \n line 3"
                }
        }';

相关问题