Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static function send_textru($text,$ignore=false)
- {
- global $config;
- $postQuery = array();
- $postQuery['text'] = $text;
- $postQuery['userkey'] = $config['tx_api_code'];
- if ($ignore!==FALSE) $postQuery['exceptdomain'] = $ignore;
- $postQuery = http_build_query($postQuery, '', '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://api.text.ru/post');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
- $json = curl_exec($ch);
- $errno = curl_errno($ch);
- // если произошла ошибка
- if (!$errno)
- {
- $resAdd = json_decode($json);
- if (isset($resAdd->text_uid))
- {
- $text_uid = $resAdd->text_uid;
- $ret = $text_uid;
- }
- else
- {
- $error_code = $resAdd->error_code;
- $error_desc = $resAdd->error_desc;
- $ret = false;
- }
- }
- else
- {
- $errmsg = curl_error($ch);
- file_put_contents(__DIR__.'/temp/textru.error.send.txt', $text.'||'.$errmsg."\r\n\r\n\r\n", FILE_APPEND);
- $ret = false;
- }
- curl_close($ch);
- return $ret;
- }
- public static function get_textru($text_uid)
- {
- global $config;
- $postQuery = array();
- $postQuery['uid'] = $text_uid;
- $postQuery['userkey'] = $config['tx_api_code'];
- // Раскомментируйте следующую строку, если вы хотите получить более детальную информацию в результатах проверки текста на уникальность
- $postQuery['jsonvisible'] = "detail";
- $postQuery = http_build_query($postQuery, '', '&');
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, 'http://api.text.ru/post');
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
- $json = curl_exec($ch);
- $errno = curl_errno($ch);
- if (preg_match('#502 Bad Gateway#si', $json))
- {
- //file_put_contents(__DIR__.'/temp/text.ru.log.txt', date('d.m.Y H:i:s').' - '.$text_uid." - 502\r\n", FILE_APPEND);
- return FALSE;
- }
- if (!$errno)
- {
- $resCheck = json_decode($json);
- if (isset($resCheck->text_unique))
- {
- $ret['text_unique'] = $resCheck->text_unique;
- $ret['result_json'] = json_decode($resCheck->result_json);
- $ret['seo'] = json_decode($resCheck->seo_check);
- }
- else
- {
- $error_code = $resCheck->error_code;
- $error_desc = $resCheck->error_desc;
- //file_put_contents(__DIR__.'/temp/text.ru.log.txt', date('d.m.Y H:i:s').' - '.$text_uid.' - '.$error_code.' : '.$error_desc."\r\n", FILE_APPEND);
- $ret = false;
- }
- }
- else
- {
- $errmsg = curl_error($ch);
- //file_put_contents(__DIR__.'/temp/text.ru.log.txt', date('d.m.Y H:i:s').' - '.$text_uid.' - '.$errmsg."\r\n", FILE_APPEND);
- $ret = false;
- }
- curl_close($ch);
- return $ret;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement