当前位置:网站首页>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 !";
}
边栏推荐
- Design of VHDL telephone billing system
- 小型圖書館項目總結
- DB queries the database, merges two unrelated tables, adds non-existent fields, and assigns default values
- Shell implementation of Memcache cache cache hit rate monitoring script
- R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
- Storage principle of string
- GoAhead WebServer移植
- 每周招聘|DBA数据工程师,年薪35+ ,梦起九州,星河灿烂!
- varnish 503 no backend connection – varnish健康检查
- Implementation and Simulation of ads131a04 ADC Verilog
猜你喜欢

数字密码锁verilog设计+仿真+上板验证

leetcode:238. 除自身以外数组的乘积

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

【ROS进阶篇】第三讲 ROS文件系统与分布式通信

【ROS进阶篇】第四讲 ROS中的重名问题(节点、话题与参数)

leetcode:724. Find the central subscript of the array

Summary of document level symbols under different systems

THREEJS基础入门

知识蒸馏(Knowledge Distilling)学习笔记

【ROS进阶篇】第二讲 自定义头、源文件封装
随机推荐
Numpy's research imitation 1
DB queries the database, merges two unrelated tables, adds non-existent fields, and assigns default values
R language plot visualization: plot to visualize the normalized histograms of multiple data sets, set different histograms to use different bin sizes, and add edge axis whisker graph rugs at the botto
My creation anniversary
Goahead webserver migration
Implementation and Simulation of ads131a04 ADC Verilog
Basic qualities of management personnel
Knowledge distilling learning notes
[advanced ROS] Lecture 3 ROS file system and distributed communication
Go standard library context package: data, cancellation signal, deadline and other related operations between a single request and multiple goroutines and the request domain
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
leetcode:370. 区间加法
What is unique about MES system?
Implementing LDAP proxy service with haproxy + keepalive
不同系统下的文件层级符号小结
leetcode:724. Find the central subscript of the array
Verilog realizes serial communication and sends it to the nixie tube
CLI tool foundation of ros2 robot f1tenth
阿里巴巴关键字搜索商品API接口(item_search-按关键字搜索商品接口),阿里巴巴搜索API接口