[英]sending message from Facebook whatsapp api to my number
我正在從 Facebook whatsapp api 發送消息到我的號碼進行測試。 消息是從 php 發送的,但在移動設備上未收到。 我必須在 facebook 注冊公司嗎?
{"messaging_product":"whatsapp","contacts":[{"input":"923040165804","wa_id":"923040165804"}],"messages":[{"id":"wamid.HBgMOTIzMDQwMTY1ODA0FQIAERgSOEM3RDJDRDMyMkFENkIzMTgyAA==" }]}
我正在使用的這個 php 代碼。
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://graph.facebook.com/v13.0/********/messages/',
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 =>json_encode(array("to"=> $number, "messaging_product" => 'whatsapp', "recipient_type" => 'individual',"type"=>"text", 'text'=> array('body'=>'hello_wo332233rld','preview_url'=>'false'))),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer '.$chatApiToken,
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
這里同樣的問題。 並從開發控制台模板發送,同樣的問題。 換了手機號后就可以了。 我不知道是否可以在生產環境中工作,但是...
嘿,我遇到了同樣的問題,解決方案是將whatsapp升級到我手機上的最新版本。 我在 Ruby 庫中添加了一些故障排除問題,可以幫助解決類似問題。
這是一個示例代碼,希望對您有所幫助。 這個對我有用
要記住的要點 必須提及模板名稱。 消息以批准的模板為准
$number = $_GET['number']; //you can use POST, I tried GET for testing
$template = array(
'name'=>'hello_world', //your your own or any default template. The names and samples are listed under message templates
'language'=>array('code'=>'en_us') //you can use yours
);
$endpoint = 'https://graph.facebook.com/v15.0/USE_YOUR_OWN/messages';
$params = array('messaging_product'=>'whatsapp', 'to'=>$number, 'type'=>'template', 'from'=>'91xxxxxxxxxx', 'access_token'=>'YOUR_ACCESS_TOKEN','template'=>json_encode($template));
$headers = array('Authorization'=>'YOUR_ACCESS_TOKEN','Content-Type'=>'application/json', 'User-Agent'=>'(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36');
$url = $endpoint . '?' . http_build_query($params);
//echo $params.'<br>';
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, $endpoint);
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $params);
$result = curl_exec($ch );
echo $result; //you can skip this, I did it to check the results
curl_close( $ch );
這最終呼應了結果
{"messaging_product":"whatsapp","contacts":[{"input":"15645446547","wa_id":"15645446547"}],"messages":[{"id":"wamid.HBgLMTU2NDU0NDY1NDcVAgARGBIwNjJEMjc3NzIzQzA2RjY2QTYA"}]}
並且正在收到消息。
請參考以下線程,了解如何傳遞參數 AKA“傳遞組件”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.