当前位置:网站首页>Wechat bulletin number Turing robot realizes intelligent reply
Wechat bulletin number Turing robot realizes intelligent reply
2022-06-29 21:46:00 【Grow beans and walk the world】
Wechat Announcement No Turing robot realizes intelligent recovery
Use five Turing robots to realize the cycle , If the first robot reply times are used up , You can use the next robot , Five opportunities used up , Then a prompt is returned .
Other detailed codes follow the next section
package com.qfjy.project.weixin.api.tuling.dev;
import com.qfjy.project.weixin.api.tuling.bean.InputText;
import com.qfjy.project.weixin.api.tuling.bean.Perception;
import com.qfjy.project.weixin.api.tuling.bean.TulingBean;
import com.qfjy.project.weixin.api.tuling.bean.UserInfo;
import com.qfjy.project.weixin.util.WeixinUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/** * @Classname TeacherUtil * @Author guoweixin * @Description TODO Turing robot Code function improvement * @Date 2021/6/25 9:34 * @Created by Administrator */
public class TeacherUtil {
/** Turing API Access interface */
private static String TULING_URL_POST="http://openapi.tuling123.com/openapi/api/v2";
/** User unique identification */
private static final String TULING_USER_ID="java2101";
/** * ####TODO Generate Tuling Interface parameter object * @param msg Send a text message * @param apiKey Robotic key */
private JSONObject getJsonObject(String msg,String apiKey){
TulingBean tulingBean=new TulingBean();
tulingBean.setReqType(0);
Perception perception=new Perception();
InputText inputText=new InputText();
inputText.setText(msg);
perception.setInputText(inputText);
tulingBean.setPerception(perception);
UserInfo userInfo=new UserInfo();
userInfo.setUserId(TULING_USER_ID);
userInfo.setApiKey(apiKey);
tulingBean.setUserInfo(userInfo);
JSONObject json1=JSONObject.fromObject(tulingBean);
return json1;
}
/** * ####TODO Send a request to the Turing server , Get response results * @param json1 URL Input parameter of the request */
private String getResult(JSONObject json1){
// 1 To the server interface address send out POST request
JSONObject jsonObject= WeixinUtil.httpRequest(TULING_URL_POST,"POST",json1.toString());
//2 Get the result returned by the Turing server robot
JSONArray json2= (JSONArray) jsonObject.get("results");
JSONObject json3= (JSONObject) json2.get(0);
JSONObject json4= (JSONObject) json3.get("values");
String result= json4.getString("text");
return result;
}
/** * ####TODO Turing intelligent chat robot core method * @param msg * @param apiKey * @return */
public String sendMessage(String msg,String apiKey){
//1 Turing gets the input object
JSONObject jsonObject= this.getJsonObject(msg,apiKey);
//2 Send the request to the server and get the result
String result=this.getResult(jsonObject);
return result;
}
/** * @param msg Users send text messages * @return Turing robot intelligent reply content */
public String send(String msg){
if(TULING_APIKEYS_LOCK_FLAG==false){
return " Today was too tired , Let's talk tomorrow ";
}
String result= this.sendMessage(msg,APIKEYS[APIKEYS_INDEX]);
if(" The number of requests exceeds the limit !".equals(result)){
APIKEYS_INDEX++;
if(APIKEYS_INDEX>=APIKEYS.length){
// recovery 0
APIKEYS_INDEX=0;
// The robots are all unavailable
TULING_APIKEYS_LOCK_FLAG=false;
return " Today was too tired , Let's talk tomorrow ";
}
return this.send(msg);
}
return result;
}
/** All the robots collect key*/
private static String[] APIKEYS={
"fb5a78bb2e79482d8075acd90b13231d",
"acc513be8b5e4b26929247e83132f116",
"911ea1eef67843449750dc7f19fb3d8d"};
/** robot Subscript indices */
private static int APIKEYS_INDEX=0;
/** robot Global lock You can use true Unavailable false*/
public static boolean TULING_APIKEYS_LOCK_FLAG=true;
/** Timing task method 00 am : TULING_APIKEYS_LOCK_FLAG=true; --》 true Robots are all available false All not available Database common fields : status 0 Invalid 1 It works Determine whether all robots are available : 0 Unavailable 1 You can use Whether to switch off in life : 0/1 Express Whether the car is driving or stopping : 0/1 Express * */
/** 1、 Turing each certified account Issued 5 A free robot .( robot KEY) 2、 A robot can only use 100 Secondary intelligent reply function .( After that 12 spot , Automatic restoration of functions ) If you exceed 100 Reply limit of times , The robot will return by default : The number of requests exceeds the limit ! How to make your robot meet the maximum functional recovery every day ? 1、 Collect multiple robots . 5 A robot . 2、 If all robots can't give a default reply function :“ Today was too tired , Let's talk tomorrow “ 3、 After midnight 24 spot , All the robots are working again . */
}
stay CoreService.java in :
1. Import objects
@Autowired
private TeacherUtil teacherUtil;
2. Call object
// A text message
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
//respContent = tuLingUtil.getResult(content);
respContent = teacherUtil.getResult();
//respContent = hitokotoUtil.getResult();
//respContent = " You are sending a text message !";
}
边栏推荐
- HAproxy + Keepalive实现LDAP代理服务
- Bs-gx-018 student examination system based on SSM
- 路由汇总带来的三层环路-解决实验
- Knowledge distilling learning notes
- 一颗新的北极星已经升起!
- Bs-gx-017 online examination management system based on SSM
- Simple application and configuration of Rsync
- leetcode:724. 寻找数组的中心下标
- [advanced ROS] Lecture 3 ROS file system and distributed communication
- GoAhead 翻译—Active Server Pages
猜你喜欢

Divide the bonus pool of 10million + million yuan, and empower developers in the 2022 shengteng AI innovation competition

PostgreSQL Weekly News - 22 juin

VHDL电话计费系统设计

STL tutorial 6-deque, stack, queue, list container

Cloud native database query optimization - statistics and row count estimation

Reading notes on how to connect the network - Web server request and response (V)

报表交付工程师

Bs-gx-017 online examination management system based on SSM

About Effect Size

Golang operation NSQ distributed message queue
随机推荐
阿里巴巴商品详情API接口(item_get-获得商品详情接口),阿里巴巴API接口
CORDIC based Signal Processor desgn
If the evaluation conclusion of waiting insurance is poor, does it mean that waiting insurance has been done in vain?
实现inotify配合rsync实时备份
每周招聘|DBA数据工程师,年薪35+ ,梦起九州,星河灿烂!
小型圖書館項目總結
Desai wisdom number - other charts (basic sunrise chart): high frequency words in graduation speech
[cloud native practice] kubesphere practice - Multi tenant system practice
Rsync 的简单应用与配置
Win10 add SSH public key
[advanced ROS chapter] lesson 2 custom header and source file encapsulation
Shell implementation of Memcache cache cache hit rate monitoring script
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
Win10添加ssh公钥
Vipshop product details API interface (item_get- get vipshop product details interface), vipshop details API interface
Common methods of string class
leetcode:307. Area and retrieval - array modifiable
leetcode:238. 除自身以外数组的乘积
Storage principle of string
【ROS进阶篇】第三讲 ROS文件系统与分布式通信