• 记一次基于开源微信机器人实现的Unity构建完成通知


    版本1

    流程为:构建事件触发,然后调用类库Api通知到本地系统,由本地的机器人系统给指定的目标微信名称的账号发送消息

    安装机器人

    地址:https://github.com/danni-cool/docker-wechatbot-webhook
    部署方式按照说明即可,此机器人基于Docker制作

    使用机器人

    • 根据hub地址里面的提示进行Docker部署
    • 根据命令行提示网页访问,使用微信扫码登陆
    • 使用工具(ApiFox、Postman) 或者其他工具进行消息发送测试

    在Unity里面我使用了编辑器拓展的IPostprocessBuildWithReport接口,这个接口会在unity输出完成后自动被Unity调用。而我将 WxNotify.SendMsg(“目标微信昵称”, “程序输出构建完成”);写在了这个方法里面

    C# 类库地址

    https://github.com/zhangtianqing/WxNotify

    版本2

    使用Hook机制实现

    下载地址

    https://github.com/expzhizhuo/WechatBot

    使用方法

    1. 按照github页面内的方法部署好
    2. 使用http访问发送消息即可
    			string msg = $"{Application.productName}构建完成,用时:{EditorApplication.timeSinceStartup - time}s";
                string timeNow = DateTime.Now.ToLongTimeStamp().ToString();
                string sendMsg = "{\"para\": {        \"id\": \""+ timeNow + "\",        \"type\": 555,        \"wxid\": \"目标微信好友的微信号\",        \"roomid\": \"null\",        \"content\": \""+ msg + "\",        \"nickname\": \"null\",        \"ext\": \"null\"}}";
                WxNotify.Post("http://你的服务器访问地址/api/sendtxtmsg", sendMsg);
    
    • 1
    • 2
    • 3
    • 4

    附:Unity编辑器拓展-构建事件通知(构建开始、构建结束)

    using UnityEditor.Build.Reporting;
    using UnityEditor.Build;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    using System.IO;
    using Dll.Utils;
    using UnityEditor;
    using System;
    
    public class BuildCompleteEventListener : IPreprocessBuildWithReport, IPostprocessBuildWithReport,IProcessSceneWithReport
    {
        public int callbackOrder => 0;
        double time;
        public void OnPreprocessBuild(BuildReport report)
        {
            time = EditorApplication.timeSinceStartup;
            Debug.LogWarning("打包前");
        }
        public void OnPostprocessBuild(BuildReport report)
        {
            Debug.LogWarning($"打包后:{report.GetType().FullName}:{report.summary.outputPath}");
            try
            {
                string msg = $"{Application.productName}构建完成,用时:{EditorApplication.timeSinceStartup - time}s";
                string timeNow = DateTime.Now.ToLongTimeStamp().ToString();
                string sendMsg = "{\"para\": {        \"id\": \""+ timeNow + "\",        \"type\": 555,        \"wxid\": \"目标微信好友的微信号\",        \"roomid\": \"null\",        \"content\": \""+ msg + "\",        \"nickname\": \"null\",        \"ext\": \"null\"}}";
                WxNotify.Post("http://你的服务器访问地址/api/sendtxtmsg", sendMsg);
            }
            catch (System.Exception e)
            {
                Debug.Log("WxNotifyError:" + e);
            }
                        
            DeleteExcelOnOutput(report);
        }
        /// 
        /// 打包前遍历场景列表(Scenes In Build)
        /// 
        /// Build Settings中的勾选的场景列表,不勾选的不会遍历到
        /// 
        public void OnProcessScene(Scene scene, BuildReport report)
        {
            Debug.LogWarning("打包前对场景操作:" + scene.name);
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
  • 相关阅读:
    基于SpringBoot的电影购票系统
    IPhone无法usb线共享网络给windows电脑的常规解决办法
    协程的创建
    七、监听器
    如何让 ABAP 报表在后台作业的模式下运行试读版
    独立站FP收款黑科技来啦!再也不用担心账户被封了~
    SSM整合_年轻人的第一个增删改查_基础环境搭建
    使用openpyxl库读取Excel文件数据
    Mozilla Firefox 浏览器
    一文解读 SmartX 超融合虚拟化下的网络 I/O 虚拟化技术
  • 原文地址:https://blog.csdn.net/a1092484359/article/details/133791200