代码地址以及视频地址

代码地址

视频地址

实现小夹子网的对接

打开小夹子网了解如何对接

小夹子网

小夹子API对接文档

完成认证的功能

通过小夹子网编写相关常量信息

public interface ClipWebConstants {/*** 基础路由*/String BASIC_URI = "http://101.33.214.46/comm_pc/communication-support-clip/v1/clip-api";/*** 应用ID*/String APPID = "";/*** 绑定邮箱*/String mail = "18061877017@163.com";}

编写小夹子网公共响应

@Data
public class ClipWebResponse {@SerializedName("result")private Boolean result;@SerializedName("code")private Integer code;@SerializedName("message")private String message;@SerializedName("data")private Object data;
}

引入http请求依赖

参考文档

<!--    okhttp    -->
<dependency><groupId>com.mzlion</groupId><artifactId>easy-okhttp</artifactId><version>1.1.4</version>
</dependency>

测试认证请求是否成功

@SpringBootTest
public class ClipWebTest {@Testpublic void testAuth() {var response = HttpClient.get(ClipWebConstants.BASIC_URI + "/auth").queryString("appId", ClipWebConstants.APPID).queryString("mail", ClipWebConstants.MAIL).asBean(ClipWebResponse.class);System.out.println(response);}
}

完成获取内容列表

@Test
public void testContentList() {var authResponse = HttpClient.get(ClipWebConstants.BASIC_URI + "/auth").queryString("appId", ClipWebConstants.APPID).queryString("mail", ClipWebConstants.MAIL).asBean(ClipWebResponse.class);String token = authResponse.getData().toString();var contentListResponse = HttpClient.get(ClipWebConstants.BASIC_URI + "/contentList").header("ApiToken", token).queryString("title", "qq").queryString("current", 1).queryString("size", 100).asBean(ClipWebResponse.class);System.out.println(contentListResponse);
}

实现list_clip_title_like指令

增加相关配置信息

在application.yml中加入

qq:owner: 1781913075group: 680634950

指令定义

模糊查询clip列表

定义指令: list_clip_title_like

对应正则: list_clip_title_like\s.{1,30}

编写list_clip_title_like指令代码

    @OnGroup@Filter(value = "list_clip_title_like\s(?<title>.{1,30})", matchType = MatchType.REGEX_MATCHES, trim = true)public void doPrivateMsg(GroupMsg event, MsgSender sender, @FilterValue("title") String title) {GroupInfo groupInfo = event.getGroupInfo();if (groupCode.equals(groupInfo.getGroupCode())) {String msg = event.getMsg();System.out.println("=============");System.out.println(title);System.out.println("=============");}}
}

实现token缓存,引入相关依赖

<!--    redis    -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!--    fastjson    -->
<dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>1.2.72</version>
</dependency>

在application.yml添加相关配置信息

spring:redis:url: redis://123456@localhost:6379username: rootjedis:pool:max-active: 8max-wait: -1min-idle: 0max-idle: 8
/*** Redis使用FastJson序列化** @author linq*/
public class FastJson2JsonRedisSerializer<T> implements RedisSerializer<T> {public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");static {ParserConfig.getGlobalInstance().setAutoTypeSupport(true);}@SuppressWarnings("unused")private ObjectMapper objectMapper = new ObjectMapper();private Class<T> clazz;public FastJson2JsonRedisSerializer(Class<T> clazz) {super();this.clazz = clazz;}@Overridepublic byte[] serialize(T t) throws SerializationException {if (t == null) {return new byte[0];}return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(DEFAULT_CHARSET);}@Overridepublic T deserialize(byte[] bytes) throws SerializationException {if (bytes == null || bytes.length <= 0) {return null;}String str = new String(bytes, DEFAULT_CHARSET);return JSON.parseObject(str, clazz);}public void setObjectMapper(ObjectMapper objectMapper) {Assert.notNull(objectMapper, "'objectMapper' must not be null");this.objectMapper = objectMapper;}protected JavaType getJavaType(Class<?> clazz) {return TypeFactory.defaultInstance().constructType(clazz);}
}
@Configuration
@EnableCaching
public class RedisConfig extends CachingConfigurerSupport {@Bean@SuppressWarnings(value = {"unchecked", "rawtypes", "deprecation"})public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory connectionFactory) {RedisTemplate<Object, Object> template = new RedisTemplate<>();template.setConnectionFactory(connectionFactory);FastJson2JsonRedisSerializer serializer = new FastJson2JsonRedisSerializer(Object.class);ObjectMapper mapper = new ObjectMapper();mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);serializer.setObjectMapper(mapper);template.setValueSerializer(serializer);// 使用StringRedisSerializer来序列化和反序列化redis的key值template.setKeySerializer(new StringRedisSerializer());template.afterPropertiesSet();return template;}
}
@Slf4j
@Component("simpleBotPrivateMsgEvent")
public class SimpleBotPrivateMsgEvent {@Value("${qq.group}")private String groupCode;@Value("${qq.owner}")private String ownerCode;@Resourceprivate StringRedisTemplate stringRedisTemplate;@PostConstructpublic void initAuthToken() {doSetAuthToken();log.info("auth-token: {}", stringRedisTemplate.opsForValue().get(ClipWebConstants.AUTH_TOKEN));}private void doSetAuthToken() {var response = HttpClient.get(ClipWebConstants.BASIC_URI + "/auth").queryString("appId", ClipWebConstants.APPID).queryString("mail", ClipWebConstants.MAIL).asBean(ClipWebResponse.class);stringRedisTemplate.opsForValue().setIfAbsent(ClipWebConstants.AUTH_TOKEN, response.getData().toString(), 12, TimeUnit.HOURS);}@OnGroup@Filter(value = "list_clip_title_like\s(?<title>.{1,30})", matchType = MatchType.REGEX_MATCHES, trim = true)public void doPrivateMsg(GroupMsg event, MsgSender sender, @FilterValue("title") String title) {GroupInfo groupInfo = event.getGroupInfo();if (groupCode.equals(groupInfo.getGroupCode())) {String authToken = stringRedisTemplate.opsForValue().get(ClipWebConstants.AUTH_TOKEN);if (authToken == null || authToken.equals("")) {doSetAuthToken();}String msg = event.getMsg();System.out.println("=============");System.out.println(title);System.out.println("=============");}}}

完成推送功能

package linc.cool.robot.simple;import catcode.CatCodeUtil;
import catcode.CodeBuilder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.mzlion.easyokhttp.HttpClient;
import linc.cool.robot.clip.ClipWebContentInfo;
import linc.cool.robot.clip.response.ClipWebResponse;
import linc.cool.robot.constants.ClipWebConstants;
import lombok.extern.slf4j.Slf4j;
import love.forte.simbot.annotation.Filter;
import love.forte.simbot.annotation.FilterValue;
import love.forte.simbot.annotation.OnGroup;
import love.forte.simbot.api.message.containers.GroupAccountInfo;
import love.forte.simbot.api.message.containers.GroupInfo;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.sender.MsgSender;
import love.forte.simbot.filter.MatchType;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;/*** @author yqlin* @date 2022/4/6 17:05* @description*/
@Slf4j
@Component("simpleBotPrivateMsgEvent")
public class SimpleBotPrivateMsgEvent {@Value("${qq.group}")private String groupCode;@Value("${qq.owner}")private String ownerCode;private final CatCodeUtil catCodeUtil = CatCodeUtil.INSTANCE;@Resourceprivate StringRedisTemplate stringRedisTemplate;@PostConstructpublic void initAuthToken() {doSetAuthToken();log.info("auth-token: {}", stringRedisTemplate.opsForValue().get(ClipWebConstants.AUTH_TOKEN));}private void doSetAuthToken() {var response = HttpClient.get(ClipWebConstants.BASIC_URI + "/auth").queryString("appId", ClipWebConstants.APPID).queryString("mail", ClipWebConstants.MAIL).asBean(ClipWebResponse.class);stringRedisTemplate.opsForValue().setIfAbsent(ClipWebConstants.AUTH_TOKEN, response.getData().toString(), 12, TimeUnit.HOURS);}@OnGroup@Filter(value = "list_clip_title_like\s(?<title>.{1,30})", matchType = MatchType.REGEX_MATCHES, trim = true)public void doPrivateMsg(GroupMsg event, MsgSender sender, @FilterValue("title") String title) {GroupInfo groupInfo = event.getGroupInfo();if (groupCode.equals(groupInfo.getGroupCode())) {String authToken = stringRedisTemplate.opsForValue().get(ClipWebConstants.AUTH_TOKEN);if (authToken == null || authToken.equals("")) {doSetAuthToken();}authToken = stringRedisTemplate.opsForValue().get(ClipWebConstants.AUTH_TOKEN);List<ClipWebContentInfo> contentInfoList = doGetUrlList(title, authToken);final CodeBuilder<String> codeBuilder = catCodeUtil.getStringCodeBuilder("at", false);GroupAccountInfo accountInfo = event.getAccountInfo();String atAccountInfo = codeBuilder.key("code").value(accountInfo.getAccountCode()).build();StringBuilder contentInfo = new StringBuilder();for (ClipWebContentInfo content : contentInfoList) {contentInfo.append(content.getTitle()).append("->").append(content.getUrlContent()).append("\n");}String template = """= = = 亮哥小弟提示你 = = =%s   %s    = = = = = = = = = = = =                """;sender.SENDER.sendGroupMsgAsync(groupCode, String.format(template, contentInfo, atAccountInfo));}}private List<ClipWebContentInfo> doGetUrlList(String title, String authToken) {var contentListResponse = HttpClient.get(ClipWebConstants.BASIC_URI + "/contentList").header("ApiToken", authToken).queryString("title", title).queryString("current", 1).queryString("size", 100).asBean(ClipWebResponse.class);Object data = contentListResponse.getData();JSONObject jsonObject = JSONArray.parseObject(JSON.toJSONString(data));JSONArray records = jsonObject.getJSONArray("records");List<ClipWebContentInfo> contentList = new ArrayList<>();for (int i = 0; i < records.size(); i++) {JSONObject record = records.getJSONObject(i);String t = String.valueOf(record.get("title"));String u = String.valueOf(record.get("urlContent"));contentList.add(new ClipWebContentInfo(t, u));}return contentList;}}

QQ机器人相关指令实现-对接小夹子相关推荐

  1. QQ机器人AutMan安装及对接

    序言 相信很多人在安装傻妞是总会遇到各种各样的困难,今天,我就教大家部署另一个机器人--AutMan(一听这个名字就知道一定很好用) 部署与安装 安装完成并启动后可进入autMan后台地址:http: ...

  2. OpenAi[ChatGPT] 使用Python对接OpenAi APi 实现智能QQ机器人-学习详解篇

    文章大部分来自:https://lucent.blog 原文博客地址:https://blog.ideaopen.cn 最近火热全文的ChatGPT,被很多人玩出了花,我们在Github上可以看到几个 ...

  3. QQ机器人开放式服务框架 Version 0.1 Draft - 测试用QQ机器人介绍

    测试用QQ机器人帐号:1146122992 (可随意添加好友.入群,无需验证.不过拒绝骚扰机器人!拒绝对机器人发送广告信息!) 测试用QQ机器人基本指令: #help 查看帮助信息(所有模式中的帮助信 ...

  4. 量子面板 管理多个青龙+对接公众号+QQ机器人+多面板管理+VLW

    作者教程文档:量子安装官方文档 go-cqhttp安装(QQ机器人) 1.go-cqhttp下载 这个是云服务器amd架构的 根据自己的系统选择下载 go-cqhttp 官网:go-cqhttp 帮助 ...

  5. 卷毛机器人抢大龙视频_腾讯这一措施,又砸碎了一些小企业的饭碗,QQ机器人成为历史...

    腾讯最近又开始搞"骚动作",第三方QQ机器人已经停止运营,包括晨风.酷Q.契约.mpq.乾坤.oneQQ.lightQQ.miral, 没想到,我最爱的酷Q也停止了,本来还打算再做 ...

  6. 手把手QQ机器人制作教程,根据官方接口进行开发,基于Python语言制作的详细教程(更新中)

    第 1 课.注册 QQ 开放平台账户 QQ开放平台官方地址:https://q.qq.com/#/app/bot QQ开放平台包含:QQ机器人.QQ小程序.QQ小游戏,我们这边选择QQ机器人. 机器人 ...

  7. 万字长文保姆级教你制作自己的多功能QQ机器人

    转载请注明出处:小锋学长生活大爆炸(https://xfxuezhang.blog.csdn.net/) 若发现存在部分图片缺失,可以访问原文:万字长文保姆级教你制作自己的多功能QQ机器人 - 小锋学 ...

  8. [“空头计划“第二期 ] QQ机器人(Python ^3.7 + 机器人框架NoneBot-beta2最新版本)实现

    文章目录 前言 正文 步骤详细分析 一. 完整功能框架 注意 帮助文档 创建新项目`QQ_Robot` 1. 模块 `nb-cli` 的安装(开发模块包含NoneBot2) 2. 驱动器 `httpx ...

  9. 开发 mirai QQ机器人起步教程

    前言 虽然该文最终是达到以python开发mirai机器人的目的,但起步教程,尤其是环境配置上仍然有大量的相同操作,对其他编程语言仍有借鉴之处 假设你已经安装好了 Java.Python等运行必须的环 ...

最新文章

  1. 人工智能与智能系统的先驱人物
  2. Ubuntu 火狐浏览器不能上网解决办法
  3. #386. 【UNR #3】鸽子固定器
  4. SAP CRM One Order old design in index table
  5. java类与对象明星,明星档案的
  6. linux和裸机的区别,操作系统与裸机的区别
  7. Bzoj3309-DZY Loves Math【莫比乌斯反演,线性筛】
  8. php 验证码文件,php实现的验证码文件类实例
  9. 华农专业课计算机基础,华南农业大学期末考试大学计算机基础试卷.doc
  10. mysql timestamp 默认值是什么#039;_MYSQL中TIMESTAMP类型的默认值
  11. 十五、Oracle学习笔记:序列(用于表字段值自增)
  12. 令牌环网概念_令牌环网工作原理_令牌环网为什么没人用
  13. arcgis图例背景白色,留出空间
  14. 数据可视化 Echarts + 边框图片 + ES6拼接字符串
  15. JavaScript 是怎么运行起来的?
  16. 分子动力学基本概念(持续更新)
  17. 悟空浏览器——青龙羊毛
  18. Whitelabel Error Page并且报500
  19. 股票K线统计,各个分钟线,日线,周线统计,sql示例
  20. php制作404,thinkphp制作404跳转页的简单实现方法

热门文章

  1. Axure 安卓组件库 Material Design
  2. Mapbox学习笔记(1)——style
  3. mybatis动态sql及分页
  4. 数据库系统基础教程第三版 部分实验命令
  5. mysql数据库系统原理_数据库系统原理及MySQL应用教程
  6. 旧物回收软件都需要哪些功能?
  7. Android WiFi系统
  8. 【181030】超酷的VC++屏幕作图(电子画笔)程序源代码
  9. 全球10大智慧港口介绍
  10. 常用数据库jdbc连接池的配置(在spring中的配置)