当前位置:网站首页>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 !";
}
边栏推荐
- yolov6训练自己的数据记录+yolov5对比测试
- PostgreSQL weekly news - June 22
- 亚马逊商品详情API接口-(item_get-获得AMAZON商品详情接口),亚马逊详情API接口
- How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture
- 炒股开户请问哪个券商佣金是最低最安全的
- 唯品会关键词搜索API接口(item_search-按关键字搜索唯品会商品API接口),唯品会API接口
- R language plot visualization: plot visualization box graph and several box plots of multiple classification variables
- 亚马逊关键词搜索API接口(item_search-按关键字搜索亚马逊商品接口),亚马逊API接口
- Flame retardant test of aluminum sheet as/nzs 1530.1 non combustible materials
- 【ROS进阶篇】第三讲 ROS文件系统与分布式通信
猜你喜欢

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

Storage principle of string

How can colleges and universities build future oriented smart campus based on cloud native? Full stack cloud native vs traditional technology architecture

Cloud native database query optimization - statistics and row count estimation

透过华为军团看科技之变(五):智慧园区

CORDIC based Signal Processor desgn

leetcode:238. Product of arrays other than itself

美国隧道法ASTM E84 表面阻燃测试

Yolov6 training your own data record +yolov5 comparison test

Matlab adds noise / disturbance to data
随机推荐
Cloud native database query optimization - statistics and row count estimation
Common methods of string class
路由汇总带来的三层环路-解决实验
Verilog realizes serial communication and sends it to the nixie tube
leetcode:370. Interval addition
铝板AS/NZS 1530.1 不燃性材料的阻燃测试
My creation anniversary
As for the domestic Kirin system running QT, it can be run on the command line but cannot be run by double clicking (no response)
Vipshop Keyword Search API interface (item_search- search vipshop commodity API interface by keyword), vipshop API interface
Matlab output format control%d,%f,%c,%s usage
炒股开户请问哪个券商佣金是最低最安全的
Alibaba product details API interface (item_get- get product details interface), Alibaba API interface
Db查询数据库合并两个不相关的表,新增不存在的字段,并赋予默认值
阿里巴巴关键字搜索商品API接口(item_search-按关键字搜索商品接口),阿里巴巴搜索API接口
Alibaba keyword search commodity API interface (item_search- commodity search interface by keyword), Alibaba Search API interface
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
The explain function of the DALEX package of R language generates a machine learning model interpreter and predict for the specified classification prediction_ The parts function analyzes the contribu
Rsync 建立多目录模块的方法
小型图书馆项目总结
[crossbeam series] 5 crossbeam util and crossbeam queue: some practical gadgets