Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. public static function send_textru($text,$ignore=false)
  2. {
  3. global $config;
  4.  
  5. $postQuery = array();
  6. $postQuery['text'] = $text;
  7. $postQuery['userkey'] = $config['tx_api_code'];
  8.  
  9. if ($ignore!==FALSE) $postQuery['exceptdomain'] = $ignore;
  10.  
  11. $postQuery = http_build_query($postQuery, '', '&');
  12.  
  13. $ch = curl_init();
  14. curl_setopt($ch, CURLOPT_URL, 'http://api.text.ru/post');
  15. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  16. curl_setopt($ch, CURLOPT_POST, 1);
  17. curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
  18. $json = curl_exec($ch);
  19. $errno = curl_errno($ch);
  20.  
  21. // если произошла ошибка
  22. if (!$errno)
  23. {
  24. $resAdd = json_decode($json);
  25. if (isset($resAdd->text_uid))
  26. {
  27. $text_uid = $resAdd->text_uid;
  28. $ret = $text_uid;
  29. }
  30. else
  31. {
  32. $error_code = $resAdd->error_code;
  33. $error_desc = $resAdd->error_desc;
  34. $ret = false;
  35. }
  36. }
  37. else
  38. {
  39. $errmsg = curl_error($ch);
  40.  
  41. file_put_contents(__DIR__.'/temp/textru.error.send.txt', $text.'||'.$errmsg."\r\n\r\n\r\n", FILE_APPEND);
  42.  
  43. $ret = false;
  44. }
  45. curl_close($ch);
  46.  
  47. return $ret;
  48. }
  49.  
  50. public static function get_textru($text_uid)
  51. {
  52. global $config;
  53.  
  54. $postQuery = array();
  55. $postQuery['uid'] = $text_uid;
  56. $postQuery['userkey'] = $config['tx_api_code'];
  57. // Раскомментируйте следующую строку, если вы хотите получить более детальную информацию в результатах проверки текста на уникальность
  58. $postQuery['jsonvisible'] = "detail";
  59.  
  60. $postQuery = http_build_query($postQuery, '', '&');
  61.  
  62. $ch = curl_init();
  63. curl_setopt($ch, CURLOPT_URL, 'http://api.text.ru/post');
  64. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  65. curl_setopt($ch, CURLOPT_POST, 1);
  66. curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
  67. $json = curl_exec($ch);
  68. $errno = curl_errno($ch);
  69.  
  70. if (preg_match('#502 Bad Gateway#si', $json))
  71. {
  72. //file_put_contents(__DIR__.'/temp/text.ru.log.txt', date('d.m.Y H:i:s').' - '.$text_uid." - 502\r\n", FILE_APPEND);
  73. return FALSE;
  74. }
  75.  
  76. if (!$errno)
  77. {
  78. $resCheck = json_decode($json);
  79. if (isset($resCheck->text_unique))
  80. {
  81. $ret['text_unique'] = $resCheck->text_unique;
  82. $ret['result_json'] = json_decode($resCheck->result_json);
  83.  
  84. $ret['seo'] = json_decode($resCheck->seo_check);
  85. }
  86. else
  87. {
  88. $error_code = $resCheck->error_code;
  89. $error_desc = $resCheck->error_desc;
  90. //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);
  91. $ret = false;
  92. }
  93. }
  94. else
  95. {
  96. $errmsg = curl_error($ch);
  97. //file_put_contents(__DIR__.'/temp/text.ru.log.txt', date('d.m.Y H:i:s').' - '.$text_uid.' - '.$errmsg."\r\n", FILE_APPEND);
  98. $ret = false;
  99. }
  100.  
  101. curl_close($ch);
  102.  
  103. return $ret;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement