版本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
使用方法
- 按照github页面内的方法部署好
- 使用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);
}
}