123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace crmeb\services;
- use PullWord\PullWord;
- class VicWordService
- {
- private static $instance = null;
-
- protected $url = 'https://sms.crmeb.net/api/v2/open/keyword';
- public function __construct()
- {
- }
- private function __clone()
- {
- }
- public static function instance()
- {
- if (self::$instance === null) {
- self::$instance = new self();
- }
- return self::$instance;
- }
- public function getWord($str)
- {
- try {
- $res = HttpService::getRequest($this->url ,['keyword' => $str]);
- $data = json_decode($res, true) ?: [];
- $data = array_column($data['data'] ?? [], 0);
- } catch (\Throwable $e) {
- $data = [];
- }
-
- if (!count($data)) {
- $data[] = $str;
- }
- return $data;
- }
- public function getWordV1($str)
- {
- try {
- $pullWord = new PullWord($str);
- $result = $pullWord->pull()->toJson()->get();
- $result = json_decode($result, true);
- $data = is_array($result) ? array_column($result, 't') : [];
- } catch (\Throwable $e) {
- $data = [];
- }
-
- if (!count($data)) {
- $data[] = $str;
- }
- return $data;
- }
- }
|