当前位置:网站首页>Automatic reply of wechat bulletin number intelligent reply with Turing robot
Automatic reply of wechat bulletin number intelligent reply with Turing robot
2022-06-29 21:46:00 【Grow beans and walk the world】
Automatic reply of wechat bulletin number uses Turing robot to realize intelligent reply
YiYanTang interface call , Automatically reply with one sentence , Follow the blog section
HitokotoUtil .java:
package com.qfjy.project.weixin.api.hitokoto;
import com.qfjy.project.weixin.util.WeixinUtil;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;
/** * @Classname HitokotoUtil * @Author guoweixin * @Description TODO A word One sentence service https://v1.hitokoto.cn/ * @Date 2021/6/24 14:15 * @Created by Administrator */
@Component
public class HitokotoUtil {
private static String HITOKOTO_URL="https://v1.hitokoto.cn/";
/** java jdk Native :UrlConnection apache:HttpClient OKHTTP spring frame :RestTemplate */
public String getResult(){
JSONObject jsonObject= WeixinUtil.httpRequest(HITOKOTO_URL,"GET",null);
String result=jsonObject.getString("hitokoto");
return result;
}
}
stay CoreService.java in :
1. Import objects
@Autowired
private HitokotoUtil hitokotoUtil;
2. Call object
// A text message
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
respContent = hitokotoUtil.getResult();
//respContent = " You are sending a text message !";
}
Use Turing robot to realize intelligent reply
The Turing interface is available every day 100 Time :
InputText.java:
package com.qfjy.project.weixin.api.tuling.bean;
import lombok.Data;
@Data
public class InputText {
/** Enter text directly */
private String text;
}
Perception.java:
package com.qfjy.project.weixin.api.tuling.bean;
import lombok.Data;
@Data
public class Perception {
/** A text message */
private InputText inputText;
}
TulingBean.java:
package com.qfjy.project.weixin.api.tuling.bean;
import lombok.Data;
@Data
public class TulingBean {
/** Input type :0- Text ( Default )、1- picture 、2- Audio */
private int reqType=0;
/** Input information */
private Perception perception;
/** User parameters */
private UserInfo userInfo;
}
TulingUtil.java:
package com.qfjy.project.weixin.api.tuling;
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;
import org.springframework.stereotype.Component;
@Component
public class TulingUtil {
/** * Register Turing platform http://www.tuling123.com/ * And complete real name certification . Apply for robots . * API Tutorial access documentation :https://www.kancloud.cn/turing/www-tuling123-com/718227 */
private static String TULING_URL_POST="http://openapi.tuling123.com/openapi/api/v2";
public String getResult(String msg){
//1 object turn JSON
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("java2101");
userInfo.setApiKey("5d46f432d7a744dab2d0cdb7f5e5532b");
tulingBean.setUserInfo(userInfo);
JSONObject json1=JSONObject.fromObject(tulingBean);
System.out.println(json1.toString());
//2 To the server interface address send out POST request
JSONObject jsonObject= WeixinUtil.httpRequest(TULING_URL_POST,"POST",json1.toString());
//3 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;
}
public static void main(String[] args) {
//1 object turn JSON
TulingBean tulingBean=new TulingBean();
tulingBean.setReqType(0);
Perception perception=new Perception();
InputText inputText=new InputText();
inputText.setText(" have you had dinner ");
perception.setInputText(inputText);
tulingBean.setPerception(perception);
UserInfo userInfo=new UserInfo();
userInfo.setUserId("java2101");
userInfo.setApiKey("acc513be8b5e4b26929247e83132f116");
tulingBean.setUserInfo(userInfo);
JSONObject json1=JSONObject.fromObject(tulingBean);
System.out.println(json1.toString());
//2 To the server interface address send out POST request
JSONObject jsonObject= WeixinUtil.httpRequest(TULING_URL_POST,"POST",json1.toString());
//3 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");
System.out.println(result);
}
}
stay CoreService.java in :
1. Import objects
@Autowired
private TulingUtil tuLingUtil;
2. Call object
// A text message
if (msgType.equals(MessageUtil.REQ_MESSAGE_TYPE_TEXT)) {
respContent = tuLingUtil.getResult(content);
//respContent = hitokotoUtil.getResult();
//respContent = " You are sending a text message !";
}
Next section , 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 .
边栏推荐
- Top ten questions for senior Performance Test Engineer
- 尚硅谷实时数据仓库项目(阿里云实时数仓)
- HAproxy + Keepalive实现LDAP代理服务
- 一次 Keepalived 高可用的事故,让我重学了一遍它!
- C. Most Similar Words
- 【ROS进阶篇】第二讲 自定义头、源文件封装
- shell 实现Memcache缓存命中率监控脚本
- Weibo comments on high availability and high performance computing architecture
- Verilog implements DDS waveform generator module, which can realize adjustable frequency and phase, three waveforms
- yolov6训练自己的数据记录+yolov5对比测试
猜你喜欢

Verilog realizes serial communication and sends it to the nixie tube

Bs-gx-018 student examination system based on SSM

PostgreSQL weekly news - June 22

直播预告 | PostgreSQL 内核解读系列第一讲:PostgreSQL 系统概述

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

Small library project summary

小型圖書館項目總結
![[advanced ROS chapter] lesson 2 custom header and source file encapsulation](/img/25/85e8c55605f5cc999a8e85f0a05f93.jpg)
[advanced ROS chapter] lesson 2 custom header and source file encapsulation

Design of VHDL telephone billing system

【ROS进阶篇】第二讲 自定义头、源文件封装
随机推荐
Summary of document level symbols under different systems
How to prepare samples for application of color coated steel sealing plates to BS 476-3?
STM32 minimum system construction (schematic diagram)
[fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
Flutter technology and Practice (2)
STM32 and gd32 notes
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
MES系统究竟有何独特之处?
flutter BottomNavigationBar切换页面保持状态
小型图书馆项目总结
数字密码锁verilog设计+仿真+上板验证
Shell implementation of Memcache cache cache hit rate monitoring script
不同系统下的文件层级符号小结
LeetCode 1. 两数之和
leetcode:724. 寻找数组的中心下标
Implementing LDAP proxy service with haproxy + keepalive
[advanced ROS] Lecture 3 ROS file system and distributed communication
After inventing anti-virus software, he chose to be a top-notch gangster
彩涂钢板密封板申请BS 476-3如何备样?
Cloud native database query optimization - statistics and row count estimation