使用 PHP 通过 WhatsApp API 发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28342651/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending a message by the WhatsApp API using PHP
提问by Srim
I am trying to send a message by the WhatsApp API using PHP. I have the WhatsApp password and am getting by WART using the following code:
我正在尝试使用 PHP 通过 WhatsApp API 发送消息。我有 WhatsApp 密码,并使用以下代码通过 WART 获取:
<?php
require "whatsapp.class.php";
// DEMO OF USAGE
$wa = new WhatsApp("91XXXXXXXXXX", "XXX-XXX", "Nick Name");
$wa->Connect();
$t = $wa->Login();
$wa->Message("5","91XXXXXXXXXX","Good code");
echo "Message sent";
?>
I did not change anything in the whatsapp.class.php file.
我没有更改 whatsapp.class.php 文件中的任何内容。
My files are:
我的文件是:
http://vvsindia.com/stackoverflow/whatsapp.class.txt
http://vvsindia.com/stackoverflow/func.txt
http://vvsindia.com/stackoverflow/decode.txt
For your convenience to view while browsing, I just uploaded them as a txt file, but originally these are PHP files.
为了方便大家浏览时查看,我只是把它们上传为txt文件,但原来这些都是PHP文件。
Using the above code I was not able to send any message. What could the issue be?
使用上面的代码我无法发送任何消息。可能是什么问题?
回答by Jayson
You can use the below script to send a message from WhatsApp in PHP.
您可以使用以下脚本在 PHP 中从 WhatsApp 发送消息。
https://github.com/venomous0x/WhatsAPI/tree/master/examples
https://github.com/venomous0x/WhatsAPI/tree/master/examples
Configure the source code in Apache
and run examples/whatsapp.php
file.
配置源代码Apache
并运行examples/whatsapp.php
文件。
You have to change the below configurations.
您必须更改以下配置。
// Simple password to view this script
$config['webpassword'] = 'MakeUpPassword';
and
和
$config['YOURNAME'] = array(
'id' => 'e807f1fcf82d132f9bb018ca6738a19f',
'fromNumber' => '441234567890',
'nick' => "YOURNICKNAME",
'waPassword' => "EsdfsawS+/ffdskjsdhwebdgxbs=",
'email' => '[email protected]',
'emailPassword' => 'gmailpassword'
);
回答by Rahul
You should rather try this quick and easy interface API:
你应该试试这个快速简单的接口 API:
https://www.mashape.com/motp/whatsapp-pusher
https://www.mashape.com/motp/whatsapp-pusher
As given in the documentation, sending a text message to a WhatsApp user would be a one-step process. Below is a sample cURL call to send a text message to a WhatsApp user.
如文档中所述,向 WhatsApp 用户发送短信将是一个一步过程。以下是向 WhatsApp 用户发送短信的示例 cURL 调用。
curl -XPOST 'http://api.dial2verify.com/WHAPP/SEND/<API_KEY>/<Phone_ISD>' \
-d 'Msg=Text to image URL here'
To get the API key, you are required to drop a request to [email protected], and they would provide you a free API key.
要获取 API 密钥,您需要向 [email protected] 发送请求,他们会为您提供一个免费的 API 密钥。
Phone_ISD: should be a complete phone number including ISD code (for example, 919922003300).
Phone_ISD:应该是一个完整的电话号码,包括 ISD 代码(例如,919922003300)。