日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

智能问答——小i机器人的pythonAPI调用

發(fā)布時間:2024/3/24 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 智能问答——小i机器人的pythonAPI调用 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文作者:?峽州仙士

原文鏈接:?https://cjh0613.github.io/blog/20200521xiaoiAPI.html

聲明:?如文章有更新,將首先在本網(wǎng)站(峽州仙士之頁)發(fā)布!(可百度搜到)| 本網(wǎng)站(峽州仙士之頁)所有文章除特別聲明外,均采用?BY-NC-SA?許可協(xié)議。轉(zhuǎn)載請注明出處!


首先,登陸http://open.xiaoi.com,左側(cè)開發(fā)者中心,客服API,得到Key和Secret

調(diào)用示例:
僅返回字符:

print(cjhGetResponse("你好","0"))

返回xml:

print(cjhGetResponse("你好","1"))

函數(shù):

import urllib import random import hashlibimport requestsimport re, json#兩個函數(shù): def getNonce():strs = ''for i in range(18):strs += (str(random.randint(0, 15)))return strsdef cjhGetResponse(question,t):appKey = '你的Key'appSecret = '你的Secret'HA1 = hashlib.sha1(':'.join([appKey, "xiaoi.com", appSecret]).encode("utf8")).hexdigest()HA2 = hashlib.sha1(u"GET:/ask.do".encode("utf8")).hexdigest()nonce = getNonce() # ':'.join([HA1, nonce, HA2]).encode("utf8")sig = hashlib.sha1(':'.join([HA1, nonce, HA2]).encode("utf8")).hexdigest()headers = {"X-Auth": "app_key=\"{0}\",nonce=\"{1}\",signature=\"{2}\"".format(appKey, nonce, sig)}post_data = {"question": question,"userId": 'someone',"type": t,"platform": "web"}post_data = urllib.parse.urlencode(post_data)url = "http://robot.open.xiaoi.com/ask.do?"+post_datarequest = urllib.request.Request(url, None, headers)request.add_header('Content-Type', 'text/html; charset=UTF-8')response = urllib.request.urlopen(request)return str(response.read(), 'utf8')

總結(jié)

以上是生活随笔為你收集整理的智能问答——小i机器人的pythonAPI调用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。