游逗网,重度移动游戏垂直门户!

最新游戏|最新软件|游戏更新|电脑软件|电脑游戏|专题合集|合集排行
您当前位置:首页 > 资讯教程 > 软件教程 >  如何在微信小程序上制作智能机器人?

如何在微信小程序上制作智能机器人?

作者:囚人发布时间:

  如何在微信小程序上制作智能机器人? 还不会操作的小伙伴,就跟着小编一起去了解具体的方法吧!

  项目为智能应答机器人,使用了图灵机器人接口,慢慢调戏吧

  首页,主要处理页:

  //index.js

  var app = getApp();

  var that;

  var chatListData = [];

  Page({

  data: {

  askWord: \'\',

  userInfo: {},

  chatList: [],

  },

  onLoad: function () {

  that = this;

  //获取用户信息

  app.getUserInfo(function (userInfo) {

  that.setData({

  userInfo: userInfo

  });

  });

  },

  onReady: function () {

  //问候语

  setTimeout(function () {

  that.addChat(\'你好啊!\', \'l\');

  }, 1000);

  },

  sendChat: function (e) {

  let word = e.detail.value.ask_word ? e.detail.value.ask_word : e.detail.value;//支持两种提交方式that.addChat(word, \'r\');//请求api获取回答

  app.req(\'post\', \'openapi/api\', {

  \'data\': { \'info\': word, \'loc\': \'广州\', \'userid\': \'123\' },\'success\': function (resp) {that.addChat(resp.text, \'l\');

  if (resp.url) {

  that.addChat(resp.url, \'l\');

  }

  },

  });

  //清空输入框

  that.setData({

  askWord: \'\'

  });

  },

  //新增聊天列表

  addChat: function (word, orientation) {

  let ch = { \'text\': word, \'time\': new Date().getTime(), \'orientation\': orientation };chatListData.push(ch);that.setData({

  chatList: chatListData

  });

  }

  })

  页面:

  //index.wxml

  

  

  

  

  

  

  {{item.text}}

  

  

  {{item.text}}{{item.url}}

  

  

  

  

  

  

  

  网络请求方法:

  //app.js

  req: function (method, url, arg) {

  let domian = \'//www.tuling123.com/\', data = { \'key\': \'9d2ff29d44b54e55acadbf5643569584\' }, dataType = \'json\';//为方便广大群众,提供keylet header = { \'content-type\': \'application/x-www-form-urlencoded\' };if (arg.data) {data = Object.assign(data, arg.data);

  }

  if (arg.header) {

  header = Object.assign(header, arg.header);}

  if (arg.dataType) {

  dataType = arg.dataType;

  }

  let request = {

  method: method.toUpperCase(),

  url: domian + url,

  data: data,

  dataType: dataType,

  header: header,

  success: function (resp) {

  console.log(\'response content:\', resp.data);let data = resp.data;typeof arg.success == "function" && arg.success(data);},fail: function () {

  wx.showToast({

  title: \'请求失败,请稍后再试\',

  icon: \'success\',

  duration: 2000

  });

  typeof arg.fail == "function" && arg.fail();},complete: function () {

  typeof arg.complete == "function" && arg.complete();}

  };

  wx.request(request);

  }

 以上就是如何在微信小程序上制作智能机器人的全部内容了,大家都学会了吗?

复制本文链接攻略文章为游逗网所有,未经允许不得转载。
系统教程更多
相关资讯更多
热门资讯更多
  1. 1如何在AutoCAD中选框选图形?在AutoCAD中选框选图形的方法
  2. 2QQ如何使用面对面快传?QQ使用面对面快传的方法
  3. 3怎么使用AutoCAD中的快速标注?
  4. 4如何在会声会影10中插入字幕?
  5. 5微信电脑版如何视频聊天?微信电脑版视频聊天的方法
  6. 6微信电脑版如何无限多开?微信电脑版无限多开的方法
  7. 7微信电脑版撤回消息的具体操作步骤介绍
  8. 8会声会影X7功能优势是什么?会声会影X7功能优势详解
火爆软件榜更多
精选资讯更多
热门专题全部>
热门分类全部>