记一次基于开源微信机器人实现的Unity构建完成通知(两种实现方法 Docker 和 Hook)

版本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);

附: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);
    }
    /// <summary>
    /// 打包前遍历场景列表(Scenes In Build)
    /// </summary>
    /// <param name="scene">Build Settings中的勾选的场景列表,不勾选的不会遍历到</param>
    /// <param name="report"></param>
    public void OnProcessScene(Scene scene, BuildReport report)
    {
        Debug.LogWarning("打包前对场景操作:" + scene.name);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值