In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
How to call the interface of the AI open platform, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.
Recently, I inadvertently found that a large number of interesting artificial intelligence cloud services are available on Tencent's AI open platform, and they are completely free. You only need to log in with your QQ number. Such a good thing, as a programmer, of course you have to try!
As can be seen from the picture above, the artificial intelligence services provided by Tencent AI open platform mainly include natural language processing, computer vision and intelligent voice. Of course, I started with the simplest natural language processing.
This is the API description of natural language processing on Tencent AI open platform:
Https://ai.qq.com/doc/nlpbase.shtml
In fact, we are familiar with the Restful API call:
Create a new PHP file and paste the source code of the link below:
Https://github.com/i042416/wechat/blob/master/tencent/newfile.php
Then Run As- > PHP CLI Application in Eclipse
You can see the following output: the sentence "Tencent AI open platform" has been successfully particified by Tencent artificial intelligence: Tencent, AI, open, platform.
Let's explain the main logic of the PHP code.
$appkey = 'LHGNH0usjUTRRRSA';$params = array (' app_id' = > '2107823355),' time_stamp' = > strval (time ()), 'nonce_str' = > strval (rand ()),' text' = > 'Tencent AI open platform', 'sign' = >',)
The first and fourth lines are the key and ID of the test application I created on the Tencent AI platform. The fifth line is the timestamp of the request, the sixth line generates a random number with rand (), the seventh behavior hopes to use the input sentence of Tencent AI artificial intelligence segmentation, and the eighth line sign is a signature value that needs to be dynamically calculated.
This signature value is calculated in the following PHP function call:
Params, $appkey)
Now go inside the getRegSign:
First, execute ksort to sort the key-value array $params of PHP in ascending order according to key. You can compare the order before the ascending sort in the above figure and after the sort in the following figure:
Then match each key-value key value in the dictionary with key=value&key=value... In this form of concatenation, note that the text value needs to be encoded in urlencode.
Finally, calculate the MD5 hash value of the connected string with the md5 function, and then convert it to uppercase with strtoupper, which is the calculated signature value.
The final step is to call doHttpPost to send the request.
The fields requested by Post is still a key-value pair of key=value&key=value type. Refer to the screenshot in the debugger below:
For your reference, I recorded the $body displayed in the debugger as follows:
App_id=2107823355&time_stamp=1533960023&nonce_str=12169&text=%CC%DA%D1%B6AI%BF%AA%B7%C5%C6%BD%CC%A8&sign=EA9CAC254A17729B20FAF28757E775DD
Finally, send the request and get the result:
Curl_setopt ($curl, CURLOPT_HEADER, false); curl_setopt ($curl, CURLOPT_NOBODY, false); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, true); curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec ($curl); if ($response = = false) {$response = false; break;} $code = curl_getinfo ($curl, CURLINFO_HTTP_CODE); if ($code! = 200) {$response = false; break;}
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.