166 lines
3.4 KiB
PHP
166 lines
3.4 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: freuddebian
|
||
|
* Date: 08/10/18
|
||
|
* Time: 12:26
|
||
|
*/
|
||
|
|
||
|
error_reporting(E_ALL);
|
||
|
ini_set('display_errors', 1);
|
||
|
include "../../vendor/autoload.php";
|
||
|
use Twilio\Rest\Client;
|
||
|
|
||
|
|
||
|
class Messenger
|
||
|
|
||
|
{
|
||
|
private $contact;
|
||
|
private $message;
|
||
|
private $mail;
|
||
|
private $subject;
|
||
|
private $client;
|
||
|
private $header;
|
||
|
const AccountSid = "ACacdb9c9601741af001ebbc7eca4969cd";
|
||
|
const AuthToken = "e0e2f1176c09b3980c9ecf967187191b";
|
||
|
const sender_name = "iLink World";
|
||
|
const sender_number = "+447400348273";
|
||
|
/**
|
||
|
* Messenger constructor.
|
||
|
* @param $contact
|
||
|
* @param $message
|
||
|
* @param $mail
|
||
|
* @param $subject
|
||
|
*/
|
||
|
public function __construct($contact=null, $message=null, $mail=null, $subject=null)
|
||
|
{
|
||
|
$this->contact = $contact;
|
||
|
$this->message = $message;
|
||
|
$this->mail = $mail;
|
||
|
$this->subject = $subject;
|
||
|
try {
|
||
|
$this->client = new Client(Messenger::AccountSid,Messenger::AuthToken);
|
||
|
}catch (Exception $e){
|
||
|
echo $e->getMessage();
|
||
|
}
|
||
|
}
|
||
|
public function sendSms()
|
||
|
{
|
||
|
|
||
|
try {
|
||
|
/* $sms = $this->client->account->messages->create(
|
||
|
// the number we are sending to - Any phone number
|
||
|
$this->getContact(),
|
||
|
array(
|
||
|
// Step 6: Change the 'From' number below to be a valid Twilio number
|
||
|
// that you've purchased
|
||
|
'from' => Messenger::sender_number,
|
||
|
|
||
|
'body' => $this->getMessage()
|
||
|
)
|
||
|
);*/
|
||
|
return true;
|
||
|
}catch(Exception $e){
|
||
|
// echo json_encode(["message"=>$e->getMessage(),"line"=>$e->getLine(),"trace"=>$e->getTrace()]);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
public function sendMail(){
|
||
|
return mail($this->getMail(),$this->getSubject(),$this->getMessage(),$this->getHeader());
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return mixed
|
||
|
*/
|
||
|
public function getHeader()
|
||
|
{
|
||
|
return $this->header;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param mixed $header
|
||
|
*/
|
||
|
public function setHeader($header)
|
||
|
{
|
||
|
$this->header = $header;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @return null
|
||
|
*/
|
||
|
public function getContact()
|
||
|
{
|
||
|
return $this->contact;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param null $contact
|
||
|
*/
|
||
|
public function setContact($contact)
|
||
|
{
|
||
|
$this->contact = $contact;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return null
|
||
|
*/
|
||
|
public function getMessage()
|
||
|
{
|
||
|
return $this->message;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param null $message
|
||
|
*/
|
||
|
public function setMessage($message)
|
||
|
{
|
||
|
$this->message = $message;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return null
|
||
|
*/
|
||
|
public function getMail()
|
||
|
{
|
||
|
return $this->mail;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param null $mail
|
||
|
*/
|
||
|
public function setMail($mail)
|
||
|
{
|
||
|
$this->mail = $mail;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @return null
|
||
|
*/
|
||
|
public function getSubject()
|
||
|
{
|
||
|
return $this->subject;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @param null $subject
|
||
|
*/
|
||
|
public function setSubject($subject)
|
||
|
{
|
||
|
$this->subject = $subject;
|
||
|
}
|
||
|
|
||
|
public function checkPhoneExist($phone)
|
||
|
{
|
||
|
try {
|
||
|
$phone_number = $this->client->lookups->v1->phoneNumbers($phone)
|
||
|
->fetch();
|
||
|
|
||
|
return isset($phone_number);
|
||
|
} catch(Exception $ex){
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|