├── .github ├── FUNDING.yml ├── dependabot.yml └── workflows │ └── php.yml ├── src ├── Exception │ ├── NotFoundException.php │ └── IllegalParameterException.php ├── Ai.php ├── Core │ ├── CoreServiceProvider.php │ ├── Traits │ │ ├── ArgumentProcessingTrait.php │ │ └── FilterTrait.php │ ├── ApplicationProvider.php │ ├── Signature.php │ └── API.php └── LICENSE ├── composer.json ├── .php_cs ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | patreon: justmd5 3 | custom: https://justmd5.com/donate.jpg 4 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: composer 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "21:00" 8 | open-pull-requests-limit: 10 9 | ignore: 10 | - dependency-name: hanson/foundation-sdk 11 | versions: 12 | - 5.0.0 13 | -------------------------------------------------------------------------------- /src/Exception/NotFoundException.php: -------------------------------------------------------------------------------- 1 | =7.0", 25 | "ext-curl": "*", 26 | "ext-json": "*", 27 | "hanson/foundation-sdk": "^4.0", 28 | "overtrue/validation": "^2.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /.github/workflows/php.yml: -------------------------------------------------------------------------------- 1 | name: PHP Composer 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: Validate composer.json and composer.lock 18 | run: composer validate 19 | 20 | - name: Install dependencies 21 | run: composer install --prefer-dist --no-progress --no-suggest 22 | 23 | # Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit" 24 | # Docs: https://getcomposer.org/doc/articles/scripts.md 25 | 26 | # - name: Run test suite 27 | # run: composer run-script test 28 | -------------------------------------------------------------------------------- /src/Ai.php: -------------------------------------------------------------------------------- 1 | 5 | This source file is subject to the MIT license that is bundled 6 | with this source code in the file LICENSE. 7 | EOF; 8 | return PhpCsFixer\Config::create() 9 | ->setRiskyAllowed(true) 10 | ->setRules(array( 11 | '@Symfony' => true, 12 | 'header_comment' => array('header' => $header), 13 | 'array_syntax' => array('syntax' => 'short'), 14 | 'ordered_imports' => true, 15 | 'no_useless_else' => true, 16 | 'no_useless_return' => true, 17 | 'php_unit_construct' => true, 18 | 'php_unit_strict' => true, 19 | )) 20 | ->setFinder( 21 | PhpCsFixer\Finder::create() 22 | ->exclude('vendor') 23 | ->in(__DIR__) 24 | ) 25 | ; -------------------------------------------------------------------------------- /src/Core/CoreServiceProvider.php: -------------------------------------------------------------------------------- 1 | getConfig('appKey'), $pimple->getConfig('appSecret')); 29 | }; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Core/Traits/ArgumentProcessingTrait.php: -------------------------------------------------------------------------------- 1 | getReqSign($params); 27 | 28 | return $params; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Core/ApplicationProvider.php: -------------------------------------------------------------------------------- 1 | filterArray, function ($filter, $key) use (&$pimple) { 30 | $pimple[$key] = function ($pimple) use ($filter, $key) { 31 | return new API($pimple, $key, $filter); 32 | }; 33 | }); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 独步弈城 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 丁海军 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /src/Core/Signature.php: -------------------------------------------------------------------------------- 1 | appId = $appId; 31 | $this->secret = $secret; 32 | } 33 | 34 | /** 35 | * @param array $params 36 | * 37 | * @return string 38 | */ 39 | public function getReqSign(array &$params): string 40 | { 41 | $params['app_id'] = $this->appId; 42 | ksort($params); 43 | $str = ''; 44 | array_walk($params, function ($item, $key) use (&$str) { 45 | if ($item !== '') { 46 | $str .= sprintf('%s=%s&', $key, urlencode($item)); 47 | } 48 | }); 49 | 50 | return strtoupper(md5(sprintf('%s%s=%s', $str, 'app_key', $this->secret))); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/Core/API.php: -------------------------------------------------------------------------------- 1 | classify = $classify; 38 | $this->filter = $filter; 39 | } 40 | 41 | /** 42 | * 请求API. 43 | * 44 | * @param string $method 45 | * @param array $params 46 | * @param array $files 47 | * 48 | *@throws IllegalParameterException 49 | * @throws NotFoundException 50 | * 51 | * @return array 52 | */ 53 | public function request(string $method, array $params = [], array $files = []): array 54 | { 55 | $url = sprintf('%s/%s/%s_%s', self::BASE_API, $this->classify, $this->classify, strtolower($method)); 56 | if (!array_key_exists(strtolower($method), $this->filter)) { 57 | throw new NotFoundException(sprintf('the url %s can not found!please reaffirm', $url)); 58 | } 59 | $factory = new ValidatorFactory(new Translator()); 60 | $validator = $factory->make($params, $this->filter[$method]); 61 | if (!$validator->passes()) { 62 | throw new IllegalParameterException(sprintf('参数错误:[%s]', json_encode($validator->errors(), JSON_UNESCAPED_UNICODE))); 63 | } 64 | $http = $this->getHttp(); 65 | $params = $this->processParams($this->app['signature'], $params); 66 | $response = $files ? $http->upload($url, $params, $files) : $http->post($url, $params); 67 | $result = json_decode(strval($response->getBody()), true); 68 | if (isset($result['ret'])) { 69 | return $result; 70 | } 71 | 72 | return [ 73 | 'ret' => '-1', 74 | 'msg' => sprintf('返回结果:[%s]', json_encode($result, JSON_UNESCAPED_UNICODE)), 75 | ]; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > 📢 请注意!由于腾讯原有免费API已关闭,该项目目前已属于不可用状态 2 | 3 |

腾讯AI开放平台 SDK

4 | 5 |

Tencent AI open platform sdk

6 | 7 |

8 | styleci 9 | PHP from Packagist 10 | GitHub stars 11 | Latest Stable Version 12 | Latest Unstable Version 13 | 14 | License 15 |

16 |

17 | Special thanks to the generous sponsorship by: 18 |

19 | 20 | 21 | 22 |

23 |

24 | 25 | ### Requirement 26 | 1. PHP >= 7.0 27 | 2. **[Composer](https://getcomposer.org/)** 28 | 3. ext-curl 拓展 29 | 4. ext-json 拓展 30 | 31 | ### 安装 32 | 33 | `composer require justmd5/tencent-ai` 34 | 35 | ### 使用 36 | 37 | ```php 38 | 39 | $config = [ 40 | 'appKey' => '1106944xxx', 41 | 'appSecret' => 'dsgnbnWnX8Yxxxxxx', 42 | 'debug' => true,//true show debug info 43 | ]; 44 | $AI = new \Justmd5\TencentAi\Ai($config); 45 | 46 | ``` 47 | 48 | ### 接口调用示例 49 | > [智能闲聊](https://ai.qq.com/doc/nlpchat.shtml) url: https://api.ai.qq.com/fcgi-bin/nlp/nlp_textchat 50 | > 请求示例1: 51 | ``` 52 | $params = [ 53 | 'question'=>'腾讯人工智能', 54 | 'session'=>123, 55 | ]; 56 | try { 57 | dd($AI->nlp->request('textchat', $params)); 58 | } catch (\Justmd5\TencentAi\Exception\NotFoundException $e) { 59 | dd($e); 60 | } 61 | ``` 62 | > [看图说话](https://ai.qq.com/doc/imgtotext.shtml) url: https://api.ai.qq.com/fcgi-bin/vision/vision_imgtotext 63 | > 请求示例2: 64 | ``` 65 | $params = [ 66 | //image 支持两种传递参数方式 67 | // 'image' => base64_encode(file_get_contents(__DIR__ . '/1571126902_843200.jpg')),//old 68 | 'image' => __DIR__ . '/1571126902_843200.jpg',//new 69 | 'session_id' => time(), 70 | ]; 71 | try { 72 | var_dump($AI->vision->request('imgtotext', $params)); 73 | } catch (\Justmd5\TencentAi\Exception\NotFoundException $e) { 74 | print_r($e->getMessage()); 75 | } catch (\Justmd5\TencentAi\Exception\IllegalParameterException $e) { 76 | print_r($e->getMessage()); 77 | } 78 | ``` 79 | ### 文档 80 | [Tencent AI](https://ai.qq.com) · [Official Documents](https://ai.qq.com/doc/index.shtml) 81 | ### 帮助 82 | qq群 83 | 84 |

85 | 86 |

87 | 88 | ### Todo 89 | 90 | - [ ] parameter verify 91 | 92 | ### Stargazers over time 93 | 94 | [![Stargazers over time](https://starchart.cc/justmd5/tencent-ai.svg)](https://starchart.cc/justmd5/tencent-ai) 95 | 96 | 97 | ### 感谢 98 | 99 | - thanks to [hanson/foundation-sdk](https://github.com/Hanson/foundation-sdk) 100 | ### 源码列表 101 | 102 | | SDK 联系人 QQ | 语言 | 实现接口 | 源代码&SDK 地址 | 103 | | --- | --- | --- | --- | 104 | | 783021975 | JAVA | ALL | https://gitee.com/xshuai/taip| 105 | | 1361653339 | Golang | ALL | https://github.com/shiguanghuxian/txai | 106 | | 1280827369 | NodeJS |
非全部接口实现
| https://github.com/w89612b/qqai-api-sdk | 107 | | 1109527533 | Python |
非全部接口实现(完善中)
|https://gitee.com/french-home/TencentAISDK | 108 | | 1928881525 | .NET(C#) |
OCR接口实现人脸模块接口实现
|https://gitee.com/ch_1928881525/Tentcent.Ai | 109 | | 910139966 | PHP | ALL | https://github.com/justmd5/tencent-ai| 110 | 111 | ## License 112 | 113 | MIT 114 | 115 | 116 | 117 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fjustmd5%2Ftencent-ai.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fjustmd5%2Ftencent-ai?ref=badge_large) 118 | -------------------------------------------------------------------------------- /src/Core/Traits/FilterTrait.php: -------------------------------------------------------------------------------- 1 | [ 15 | 'asr' => [ 16 | 'format' => 'required|integer|in:1,2,3,4', 17 | 'speech' => 'required|string|max:8192', 18 | 'rate' => 'required|integer|in:8000,16000', 19 | ], 20 | 'asrs' => [ 21 | 'format' => 'required|integer|in:1,2,3,4', 22 | 'rate' => 'required|integer|in:8000,16000', 23 | 'seq' => 'required|integer', 24 | 'len' => 'required|integer', 25 | 'end' => 'required|integer', 26 | 'speech_id' => 'required|string', 27 | 'speech_chunk' => 'required|string', 28 | ], 29 | 'evilaudio' => [], 30 | 'wxasrs' => [ 31 | 'format' => 'required|integer|in:1,2,3,4', 32 | 'rate' => 'required|integer|in:8000,16000', 33 | 'bits' => 'required|integer', 34 | 'seq' => 'required|integer', 35 | 'len' => 'required|integer', 36 | 'end' => 'required|integer', 37 | 'speech_id' => 'required|string', 38 | 'speech_chunk' => 'required|string', 39 | 'cont_res' => 'required|integer', 40 | ], 41 | 'wxasrlong' => [ 42 | 'format' => 'required|integer|in:1,2,3,4', 43 | 'callback_url' => 'required|string', 44 | 'speech' => 'required_without:speech_url', 45 | 'speech_url' => 'required_without:speech', 46 | ], 47 | 'tts' => [ 48 | 'speaker' => 'required|integer|in:1,5,6,7', 49 | 'format' => 'required|integer|in:1,2,3,', 50 | 'volume' => 'required|integer|between:-10,10', 51 | 'speed' => 'required|integer|between:50,200', 52 | 'text' => 'required|string|size:150', 53 | 'aht' => 'required|integer|between:-24,24', 54 | 'apc' => 'required|integer|between:0,100', 55 | ], 56 | 'tta' => [ 57 | 'text' => 'required|string|size:150', 58 | 'model_type' => 'required|integer|between:0,2', 59 | 'speed' => 'required|integer|between:-2,2', 60 | ], 61 | 'detectkeyword' => [ //关键词检索 62 | 'callback_url' => 'required|url', 63 | 'speech' => 'required_without:speech_url', 64 | 'speech_url' => 'required_without:speech', 65 | 'key_words' => 'required', 66 | 'format' => 'required|integer|in:1', 67 | ], 68 | ], 69 | 'face' => [ 70 | 'detectface' => ['image' => 'required', 'mode' => 'required|in:0,1'], 71 | 'detectmultiface' => ['image' => 'required'], 72 | 'facecompare' => ['image_a' => 'required', 'image_b' => 'required'], 73 | 'detectcrossageface' => ['source_image' => 'required', 'target_image' => 'required'], 74 | 'faceshape' => ['image' => 'required', 'mode' => 'required|in:0,1'], 75 | 'faceidentify' => ['image' => 'required', 'group_id' => 'required', 'topn' => 'required|between:1,10'], 76 | 'faceverify' => ['images' => 'required', 'person_id' => 'required|string'], 77 | 'newperson' => ['image' => 'required', 'group_ids' => 'required', 'person_id' => 'required', 'person_name' => 'required'], 78 | 'delperson' => ['person_id' => 'required'], 79 | 'addface' => ['images' => 'required', 'person_id' => 'required', 'tag' => 'required'], 80 | 'delface' => ['person_id' => 'required|string', 'face_ids' => 'required|string'], 81 | 'setinfo' => ['person_id' => 'required|string'], 82 | 'getinfo' => ['person_id' => 'required|string'], 83 | 'getgroupids' => [], 84 | 'getpersonids' => ['group_id' => 'required|string'], 85 | 'getfaceids' => [], 86 | 'getfaceinfo' => [], 87 | ], 88 | 'image' => [ 89 | 'terrorism' => ['image' => 'required_without:image_url', 'image_url' => 'required_without:image'], 90 | 'food' => ['image' => 'required'], 91 | 'tag' => ['image' => 'required'], 92 | 'fuzzy' => ['image' => 'required'], 93 | ], 94 | 'nlp' => [ 95 | 'speechtranslate' => ['seq' => 'required|integer', 'end' => 'required|integer', 'session_id' => 'required|string|size:64'], 96 | 'textpolar' => ['text' => 'required|max:200'], 97 | 'texttrans' => ['text' => 'required|max:1024'], 98 | 'texttranslate' => ['type' => 'required|integer|between:0,16', 'text' => 'required|max:1024'], 99 | 'textchat' => [ 100 | 'session' => 'required|max:32', 101 | 'question' => 'required|max:3000', 102 | ], 103 | 'textdetect' => ['text' => 'required'], 104 | 'imagetranslate' => [ 105 | 'image' => 'required', 106 | 'session_id' => 'required|max:64', 107 | ], 108 | 'wordner' => ['text' => 'required|max:1024'], 109 | 'wordpos' => ['text' => 'required|max:1024'], 110 | 'wordseg' => ['text' => 'required|max:1024'], 111 | 'wordsyn' => ['text' => 'required|max:1024'], 112 | 'wordcom' => ['text' => 'required|max:100'], 113 | ], 114 | 'ocr' => [ 115 | 'idcardocr' => ['image' => 'required', 'card_type_id' => 'required|in:0,1'], 116 | 'bcocr' => ['image' => 'required'], 117 | 'driverlicenseocr' => ['image' => 'required', 'type' => 'required|in:0,1'], 118 | 'plateocr' => ['image' => 'required_without:image_url', 'image_url' => 'required_without:image'], 119 | 'bizlicenseocr' => ['image' => 'required'], 120 | 'creditcardocr' => ['image' => 'required'], 121 | 'generalocr' => ['image' => 'required'], 122 | 'handwritingocr' => ['image' => 'required_without:image_url', 'image_url' => 'required_without:image'], 123 | ], 124 | 'ptu' => [ 125 | 'facecosmetic' => ['image' => 'required', 'cosmetic' => 'required|integer'], 126 | 'facedecoration' => ['image' => 'required', 'decoration' => 'required|integer'], 127 | 'facesticker' => ['image' => 'required', 'sticker' => 'required|integer'], 128 | 'faceage' => ['image' => 'required'], 129 | 'imgfilter' => ['image' => 'required', 'filter' => 'required|integer'], 130 | ], 131 | 'vision' => [ 132 | 'porn' => ['image' => 'required_without:image_url', 'image_url' => 'required_without:image'], 133 | 'scener' => [], 134 | 'objectr' => [], 135 | 'imgidentify' => [], 136 | 'imgtotext' => ['image' => 'required', 'session_id' => 'required'], 137 | 'imgfilter' => [], 138 | ], 139 | ]; 140 | } 141 | --------------------------------------------------------------------------------