Created
June 3, 2019 07:15
-
-
Save qwertik17/36d90579d9dfd9218003ca27d147906c to your computer and use it in GitHub Desktop.
Service crm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class mcrm { | |
public $baseUrl = "******"; | |
public $resto_key = "****"; | |
function __construct(modX &$modx, array $config = array()) | |
{ | |
$this->modx =& $modx; | |
$this->sid =& $_COOKIE["mcrm_sid"]; | |
} | |
//Отправка запроса | |
/** | |
* var $method (string) - название метода | |
* var $request (array) - данные POST | |
* @return array | |
**/ | |
public function sendRequest ($method, $request=array(), $params=null) | |
{ | |
$url = $this->baseUrl.$method.'?resto_key='.$this->resto_key.$params; | |
$curlHandle = curl_init($url); | |
curl_setopt($curlHandle, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $request); | |
$execResult = curl_exec($curlHandle); | |
$resultOrder = json_decode($execResult, true); | |
return $resultOrder; | |
} | |
//Авторизация зарегистрированного пользователя | |
public function userauth ($request) | |
{ | |
$method = 'userauth'; | |
$request['sid'] = $this->sid; | |
$response = $this->sendRequest($method, $request); | |
if ($response['error'] == 'OK') { | |
setCookie('mcrm_access_token', $response['access_token'], time() + 60 * 60 * 24 * 12, "/"); | |
} | |
return $response; | |
} | |
//Регистрация пользователя | |
/** | |
* var $data (array) - данные POST | |
* @return json | |
**/ | |
public function register ($request) | |
{ | |
$method = 'register'; | |
$request['sid'] = $this->sid; | |
return $this->sendRequest($method, $request); | |
} | |
//Запрос СМС с кодом проверки | |
/** | |
* var $phone (string) - номер телефона | |
* @return json | |
**/ | |
public function verify ($phone) | |
{ | |
$method = 'verify'; | |
$request = array( | |
'phone' => $phone | |
); | |
return $this->sendRequest($method, $request); | |
} | |
/** | |
* Получение районов | |
* @return json | |
**/ | |
public function getdistrict () | |
{ | |
$method = 'getdistrict'; | |
return $this->sendRequest($method); | |
} | |
/** | |
* Получение пользовательской анкеты | |
* @return json | |
**/ | |
public function getuserdata () | |
{ | |
$method = 'getuserdata'; | |
$request = array( | |
'sid' => $this->sid | |
); | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Обновление пользовательской анкеты | |
public function userupdate ($request) | |
{ | |
$method = 'userupdate'; | |
$request['sid'] = $this->sid; | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Получить список транзакций пользователя | |
public function gettransactionlist () | |
{ | |
$method = 'gettransactionlist'; | |
$request['sid'] = $this->sid; | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Узнать количество транзакций для постраничного вывода | |
public function gettransactioncount () | |
{ | |
$method = 'gettransactioncount'; | |
$request['sid'] = $this->sid; | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
//$params = '&access_token=d0190d6b0258c984a2e40d3ad10f3eab'; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Получение баланса карты | |
public function getbalance () | |
{ | |
$method = 'getbalance'; | |
$request = array( | |
'sid' => $this->sid | |
); | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Оплата бонусами | |
public function payorder ($request) | |
{ | |
$method = 'payorder'; | |
$request['sid'] = $this->sid; | |
$params = '&access_token='.$_COOKIE['mcrm_access_token']; | |
//$params = '&access_token=d0190d6b0258c984a2e40d3ad10f3eab'; | |
return $this->sendRequest($method, $request, $params); | |
} | |
//Получить всплывающее окно | |
public function getpopup () | |
{ | |
return ''; | |
} | |
//Отметить всплывающее окно как прочитанное | |
public function setpopupread () | |
{ | |
return ''; | |
} | |
//Получить сообщения "Специально для Вас" | |
public function getspecial () | |
{ | |
$method = 'getspecial'; | |
return $this->sendRequest($method); | |
} | |
/** | |
* Восстановление пароля | |
* var $phone (string) - номер телефона | |
* @return json | |
**/ | |
public function recover ($phone) | |
{ | |
$method = 'recover'; | |
$request = array( | |
'login' => $phone | |
); | |
return $this->sendRequest($method, $request); | |
} | |
/** | |
* Выход | |
**/ | |
public function logout () | |
{ | |
setCookie('mcrm_access_token', $response['access_token'], time() - 100, "/"); | |
$page_redirect = 1582; | |
$this->modx->sendRedirect($this->modx->makeUrl($page_redirect)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment