✏️ 正在编辑: Whatsapp.php
路径:
/srv/systems_dir/yuppiecred/library/Core/Whatsapp/Whatsapp.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_Whatsapp_Whatsapp { protected $config; protected $url; protected $request; protected $response; protected $action; protected $params; protected $method = 'POST'; protected $contentType = 'application/x-www-form-urlencoded'; protected $domain = "mandeumzap.com.br"; public function getAction() { return $this->action; } public function setAction($action): Core_Whatsapp_Whatsapp { $this->action = $action; return $this; } public function getParams() { return $this->params; } public function setParams($params): Core_Whatsapp_Whatsapp { $this->params = $params; return $this; } public function getMethod() { return $this->method; } public function setMethod($method): Core_Whatsapp_Whatsapp { $this->method = $method; return $this; } public function getContentType() { return $this->contentType; } public function setContentType($contentType): Core_Whatsapp_Whatsapp { $this->contentType = $contentType; return $this; } public function getDomain() { return $this->domain; } public function setDomain($domain) { $this->domain = $domain; } public function getResponse() { return $this->response; } public function setResponse($response) { $this->response = $response; } public function __construct() { $this->loadConfig(); } protected function loadConfig() { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $application = $bootstrap->getOptions(); $this->config = $application['whatsapp'][$this->class]; if( !empty($this->config['domain']) ){ $this->domain = $this->config['domain']; } } public function makeUrl() { $this->url = "https://{$this->config['companyName']}-api.{$this->getDomain()}/v1/{$this->getAction()}"; if (!empty($this->config['urlBase'])) { $this->url = $this->config['urlBase'] . "/" . $this->getAction(); } return $this->url; } public function makeRequestGET() { $this->request = curl_init(); curl_setopt($this->request, CURLOPT_URL, $this->url); curl_setopt($this->request, CURLOPT_RETURNTRANSFER, 1); curl_setopt($this->request, CURLOPT_USERAGENT, Zend_Http_UserAgent::DEFAULT_HTTP_USER_AGENT); curl_setopt($this->request, CURLOPT_HTTPHEADER, [ "Authorization: Bearer " . $this->config['token'], "Content-Type: " . $this->getContentType() ]); } public function makeRequestPOST() { $this->request = curl_init(); curl_setopt_array($this->request, [ CURLOPT_URL => $this->url, CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $this->params, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . $this->config['token'], "Content-Type: " . $this->getContentType() ], ]); } protected function sendRequest($params = null) { $method = $this->getMethod(); $makeRequest = "makeRequest{$method}"; $this->params = $params; $this->makeUrl(); $this->_prepareParams(); $this->$makeRequest(); $response = curl_exec($this->request); $this->response = json_decode($response, true); //prepareResponse curl_close($this->request); return $this->response; } protected function sendRequestFile($params) { $params = json_encode($params, JSON_HEX_APOS|JSON_HEX_QUOT|JSON_UNESCAPED_SLASHES); $this->makeUrl(); $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => $this->url, CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => $params, CURLOPT_HTTPHEADER => [ "Authorization: Bearer " . $this->config['token'], "Content-Type: " . $this->getContentType() ], ]); $response = curl_exec($curl); $this->response = json_decode($response); curl_close($curl); return $this->response; } private function _prepareParams() { if (!count($this->params) > 0) return false; $contador = 1; $params = ''; foreach ($this->params as $key => $value) { if( is_array($value) ){ foreach( $value as $k => $v ){ $params .= "&{$k}={$v}"; } } else{ $params .= $contador++ > 1 ? "&$key={$value}" : "$key={$value}"; } } $this->params = $params; } public function logar($params) { $dateFile = Zend_Date::now()->get("yyyy-MM-dd"); $urlSistema = Yuppie_Auth::getSiteKey(); $file = "/var/log/sistemayuppie/whatsapp-$this->class-$urlSistema-$dateFile"; $writer = new Zend_Log_Writer_Stream("$file.txt"); $log = new Zend_Log($writer); $id = is_object($params) ? $params->id : $params['id']; $log->log("MessageID: " . print_r($id, 1), Zend_Log::INFO); } }
💾 保存文件
← 返回文件管理器