微信小程序-智能机器人

github地址:  https://github.com/HowName/smart-robot

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

 

 

 

-  首页,主要处理页:

 1 //index.js
 2 
 3 var app = getApp();
 4 var that;
 5 var chatListData = [];
 6 
 7 Page({
 8   data: {
 9     askWord: '',
10     userInfo: {},
11     chatList: [],
12   },
13   onLoad: function () {
14     that = this;
15     //获取用户信息
16     app.getUserInfo(function (userInfo) {
17       that.setData({
18         userInfo: userInfo
19       });
20     });
21   },
22   onReady: function () {
23     //问候语
24     setTimeout(function () {
25       that.addChat('你好啊!', 'l');
26     }, 1000);
27   },
28   sendChat: function (e) {
29 
30     let word = e.detail.value.ask_word ? e.detail.value.ask_word : e.detail.value;//支持两种提交方式
31     that.addChat(word, 'r');
32 
33     //请求api获取回答
34     app.req('post', 'openapi/api', {
35       'data': { 'info': word, 'loc': '广州', 'userid': '123' },
36       'success': function (resp) {
37         that.addChat(resp.text, 'l');
38         if (resp.url) {
39           that.addChat(resp.url, 'l');
40         }
41       },
42     });
43 
44     //清空输入框
45     that.setData({
46       askWord: ''
47     });
48   },
49   //新增聊天列表
50   addChat: function (word, orientation) {
51     let ch = { 'text': word, 'time': new Date().getTime(), 'orientation': orientation };
52     chatListData.push(ch);
53     that.setData({
54       chatList: chatListData
55     });
56   }
57 })

-  页面:

 1 //index.wxml
 2 
 3 <view class="container">
 4   <scroll-view class="scrool-view" scroll-y="true">
 5     <view class="chat-list">
 6       <block wx:for="{{chatList}}" wx:key="time">
 7         <view class="chat-left" wx:if="{{item.orientation == 'l'}}">
 8           <image class="avatar-img" src="../../res/image/wechat-logo.png"></image>
 9           <text>{{item.text}}</text>
10         </view>
11         <view class="chat-right" wx:if="{{item.orientation == 'r'}}">
12           <text>{{item.text}}{{item.url}}</text>
13           <image class="avatar-img" src="{{userInfo.avatarUrl}}"></image>
14         </view>
15       </block>
16     </view>
17   </scroll-view>
18   <form bindsubmit="sendChat">
19     <view class="ask-input-word">
20       <input placeholder="" name="ask_word" type="text" bindconfirm="sendChat" value="{{askWord}}" />
21       <button formType="submit" size="mini">发送</button>
22     </view>
23   </form>
24 </view>

-  网络请求方法:

 1 //app.js
 2 
 3 req: function (method, url, arg) {
 4     let domian = 'http://www.tuling123.com/', data = { 'key': '9d2ff29d44b54e55acadbf5643569584' }, dataType = 'json';//为方便广大群众,提供key
 5     let header = { 'content-type': 'application/x-www-form-urlencoded' };
 6 
 7     if (arg.data) {
 8       data = Object.assign(data, arg.data);
 9     }
10     if (arg.header) {
11       header = Object.assign(header, arg.header);
12     }
13     if (arg.dataType) {
14       dataType = arg.dataType;
15     }
16 
17     let request = {
18       method: method.toUpperCase(),
19       url: domian + url,
20       data: data,
21       dataType: dataType,
22       header: header,
23       success: function (resp) {
24         console.log('response content:', resp.data);
25 
26         let data = resp.data;
27 
28         typeof arg.success == "function" && arg.success(data);
29       },
30       fail: function () {
31         wx.showToast({
32           title: '请求失败,请稍后再试',
33           icon: 'success',
34           duration: 2000
35         });
36 
37         typeof arg.fail == "function" && arg.fail();
38       },
39       complete: function () {
40         typeof arg.complete == "function" && arg.complete();
41       }
42     };
43     wx.request(request);
44   }

 完!

 

转载于:https://www.cnblogs.com/longer756567406/p/6371490.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
介绍一下这个软件的目前功能 功能详解: 1:最重要的功能,也就是小程序转码(由于是官方接口,部分只取路径不转码的为手动转码都不可以的,当然机器人也实现不了) 2:一键查询群ID(此功能用于自动加好友拉指定群和发送关键词拉指定群) 3:关键词加群(如上,我见还有人专门另外写个插件另外推广,我的直接在一个软件内) 4:扫码登录小程序账号和接收登录小程序账号(扫码模式直接点击登录公众号会出现一个二维码在软件内,直接扫码登录,接收模式要提前设置一个WXID,给你的机器人发送登录公众号即可自动给你指定的wxid也就是微信号发送一个登录二维码,此举是为了免登服务器,且如果ck到期会自动提醒接收人) 5:自动加好友 6:加上好友自动发送指定消息或图片,或两者并存,且自定义拉群 7:自定义水印(可设置为群水印,私聊水印,这两种模式下又分为转码人的用户名和自定义水印,自定义水印主用于引流) 8:群聊和私聊都可以转二维码模式,别人分享给你网址或者直接发你链接即可转二维码,前提是前缀加http或者https协议头如:https://www.baidu.com 9:二维码转链接模式,发送二维码即可自动解析二维码要跳转的地址,也就是取链接. 10:自动生成appid功能,这个功能其实没啥用,我用于自己的发布活动平台跳转用的,所以加了个. 11:自定义是否关闭私聊功能(此功能折中意见,防止和公众号互怼!) 12:获取小程序路径,一目了然查看邀请链接邀请码,更方便薅羊毛 13:进群@通知并赠送点数(用于收费模式,如下) 14:重点推行的功能,也就是收费模式!支持私聊转码收费和群聊转码收费(转小程序码和转二维码均可设置,且价格自定义)新人加群送多少次数,邀请人进群送多少次数 15:消费提醒,当然这个也没什么卵用,之前定制的客户要的功能,就保留了. 16:这个需要留意:如果收费功能群里面要想转码的需要发送:创建账号 这四个字,否则不能转码,因为这个免费实行给你们,你们的客户无法在我这付费,只能给你们采取这个加数据表的功能,让数据库可以记录付费者的余额.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值