Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

26 lines
1.2KB

  1. # encoding:utf-8
  2. import requests
  3. from bot.bot import Bot
  4. class BaiduUnitBot(Bot):
  5. def reply(self, query, context=None):
  6. token = self.get_token()
  7. url = 'https://aip.baidubce.com/rpc/2.0/unit/service/v3/chat?access_token=' + token
  8. post_data = "{\"version\":\"3.0\",\"service_id\":\"S73177\",\"session_id\":\"\",\"log_id\":\"7758521\",\"skill_ids\":[\"1221886\"],\"request\":{\"terminal_id\":\"88888\",\"query\":\"" + query + "\", \"hyper_params\": {\"chat_custom_bot_profile\": 1}}}"
  9. print(post_data)
  10. headers = {'content-type': 'application/x-www-form-urlencoded'}
  11. response = requests.post(url, data=post_data.encode(), headers=headers)
  12. if response:
  13. return response.json()['result']['context']['SYS_PRESUMED_HIST'][1]
  14. def get_token(self):
  15. access_key = 'wdNwpvzh4fBr8xzTuPePOWhU'
  16. secret_key = 'EUtLXyrogfTQV8nnjncnqNEfeyoHDUqS'
  17. host = 'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + access_key + '&client_secret=' + secret_key
  18. response = requests.get(host)
  19. if response:
  20. print(response.json())
  21. return response.json()['access_token']