当前位置:网站首页>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 !";
}
边栏推荐
- CLI tool foundation of ros2 robot f1tenth
- What is unique about MES system?
- Implementing LDAP proxy service with haproxy + keepalive
- Change detection and batch update
- C. Most Similar Words
- Rsync method of establishing multi directory module
- Vipshop product details API interface (item_get- get vipshop product details interface), vipshop details API interface
- Alibaba product details API interface (item_get- get product details interface), Alibaba API interface
- 数字密码锁verilog设计+仿真+上板验证
- [advanced ROS chapter] Lecture 4: duplicate names in ROS (nodes, topics and parameters)
猜你喜欢
STM32最小系统搭建(原理图)
leetcode:238. 除自身以外数组的乘积
Golang operation NSQ distributed message queue
STL tutorial 6-deque, stack, queue, list container
Redis (I) -- getting started with redis (1) -- redis introduction, installation and startup, and common configurations
[cloud native] use of Nacos taskmanager task management
Small library project summary
ads131a04 ADC verilog实现及仿真
PostgreSQL每周新聞—6月22日
PostgreSQL Weekly News - 22 juin
随机推荐
PostgreSQL weekly news - June 22
Layer 3 loop brought by route Summary - solution experiment
Huawei cloud AOM version 2.0 release
什么是 SYN 洪水攻击?如何防护?
A keepalived high availability accident made me learn it again!
Cloud native database query optimization - statistics and row count estimation
Verilog implements DDS waveform generator module, which can realize adjustable frequency and phase, three waveforms
Practical guide to GStreamer application development (V)
verilog实现串口通信发送到数码管
HAproxy + Keepalive实现LDAP代理服务
Simple application and configuration of Rsync
CORDIC based Signal Processor desgn
LeetCode 1. 两数之和
GoAhead WebServer移植
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
BUAA OO unit 4 HW16 unit 4 Summary and course review
I want to register my stock account online. How do I do it? In addition, is it safe to open a mobile account?
Weibo comments on high availability and high performance computing architecture
透过华为军团看科技之变(五):智慧园区
My creation anniversary