在这里,我需要通过单击按钮向特定的WhatsApp号发送消息。 Twilio API用于发送消息,并由https://www.twilio.com/console配置。我还注册并从Twilio获得ID和令牌到我的人员WhatsApp号。下面是我的代码。
abc.blade.php
def sevenzipoficial(type, song, catalogue, edition):
print(subprocess.call(['7z', 'a', catalogue,
'-p{racer21}', 'randomroute\\',type,'\\',song,'\\',edition,' - ',catalogue,'\\randomroute\\']))
实用程序/Twilio.php
<div class="col-md-6" align="center" style="margin-top: 30px;">
<button class="btn btn-sm pmd-btn-fab pmd-btn-flat pmd-ripple-effect btn-primary" type="button" style="margin-left: 10px; margin-top: 40px; width:100px;" onclick="sendMsg(this);">Upload</button></div>
<script type="text/javascript">
function sendMsg()
{
$.ajax({
url: "{{route('toChatAPI')}}",
type: "GET",
dataType:"json",
success: function (data)
{
alert("OK");
}
});
}
</script>
Controller.php
<?php
namespace Utils;
class Twilio {
private $sid = "AC967540fbaf69f951a3b42e229a93c110"; // Your Account SID from www.twilio.com/console
private $token = "67bbbd8e95339a3db91b503a3f02fa34"; // Your Auth Token from www.twilio.com/console
private $client;
public function __construct() {
$this->client = new \Twilio\Rest\Client($this->sid, $this->token);
}
public function sendSMS($from, $body, $to) {
$message = $this->client->messages->create(
$to, // Text this number
array(
'from' => $from, // From a valid Twilio number
'body' => $body
)
);
return $message->sid;
}
}
在按钮上单击功能会出现此错误'
[HTTP 400]无法创建记录:“收件人”编号47xxxxxxxx不是 有效的电话号码。
'发生。预先感谢。