【发布时间】:2022-04-07 01:28:07
【问题描述】:
我正在寻找一种使用 Whatsapp API 直接向客户电话号码发送通知的方法
我在一个网站上找到一篇文章,详细解释了如何激活和使用 Whatsapp API。
Add the phone number +34 644 76 66 43 into your Phone Contacts. (Name it it as you wish)
Send this message "I allow callmebot to send me messages" to the new Contact created (using WhatsApp of course)
Wait until you receive the message "API Activated for your phone number. Your APIKEY is 123123" from the bot.
Note: If you don't receive the ApiKey in 2 minutes, please try again after 24hs.
The WhatsApp message from the bot will contain the apikey needed to send messages using the API.
You can send text messages using the API after receiving the confirmation.
完美收据apikey
如何使用 CURL 库从 PHP 发送 WhatsApp 消息 使用 cURL 库从 PHP 发送 WhatsApp 消息非常简单。我建议您创建一个函数,然后在每次要发送消息时调用该函数。
首先,在您的 php 代码中创建函数“send_whatsapp”,如下所示:
function send_whatsapp($message="Test"){
$phone="NUMBER"; // Enter your phone number here
$apikey="YOUR_API_KEY"; // Enter your personal apikey received in step 3 above
$url='https://api.callmebot.com/whatsapp.php?source=php&phone='.$phone.'&text='.urlencode($message).'&apikey='.$apikey;
if($ch = curl_init($url))
{
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
$html = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// echo "Output:".$html; // you can print the output for troubleshooting
curl_close($ch);
return (int) $status;
}
else
{
return false;
}
}
只需将$phone 和$apikey 变量更新为您在上述第3 步中获得的变量即可。
然后从代码中的任何位置调用该函数。
send_whatsapp("this is a test from PHP"); //Text message that your would like to send
您可以从代码中的不同位置调用 send_whatsapp 函数。
问题
完美,每次都会向我指定的号码发送一条消息以激活通知系统。
但是如果我不想将它发送到我的号码而是发送到客户号码呢?
【问题讨论】: