Coder Social home page Coder Social logo

wechat-work-pusher's Introduction

企业微信消息推送-Go

Wechat-Work-Pusher Based On Golang

部署

准备工作

1、注册企业微信: https://work.weixin.qq.com/ 注册完成后点击我的企业,获取企业ID(cropId)

2、进入应用管理,创建自建应用,获取agentIdcropSecret

3、进入我的企业-微信插件-邀请关注 扫码关注企业微信

config.json配置

1、将准备工作中获取到的cropId、cropSecret、agentId填入相应位置

2、receiver为默认接收者的微信号,对应通讯录中的帐号

3、填写token

Docker部署

docker run -d -v /home/config.json:/root/config.json -p 9000:9000 --restart=always --name wechat-work-pusher myleo1/wechat-work-pusher

注意:替换/home/config.json 为config.json路径

使用方法

以Go为例,其他语言类似

文本消息

func Push2Wechat(to, msg string) {
   httpkit.Request(httpkit.Req{
      Method: http.MethodPost,
      //将127.0.0.1替换成自己的ip
      Url:    http://127.0.0.1:9000/wechat-work-pusher/msg,
      Header: map[string]string{
         "Cookie": fmt.Sprintf("session=%s", config中填写的token),
      },
      FormData: map[string]string{
         "to":      to,
         "content": msg,
      },
   })
}

卡片消息

卡片消息参数具体请参考:https://work.weixin.qq.com/api/doc/90000/90135/90236#%E6%96%87%E6%9C%AC%E5%8D%A1%E7%89%87%E6%B6%88%E6%81%AF

func Push2WechatCard(to, msg string) {
   httpkit.Request(httpkit.Req{
      Method: http.MethodPost,
      //将127.0.0.1替换成自己的ip
      Url:    http://127.0.0.1:9000/wechat-work-pusher/card,
      Header: map[string]string{
         "Cookie": fmt.Sprintf("session=%s", config中填写的token),
      },
      FormData: map[string]string{
         "to":      to,
         "title":		title
	 "description": fmt.Sprintf("<div class=\"gray\">%s\n</div> <div class=\"normal\">恭喜您%s~,学号[%s]打卡成功!\n</div><div class=\"highlight\">点击卡片进入云战役打卡官网查看详情~</div>", time.Now().Format(timekit.TimeLayoutYMD), name, id),
         "url": "https://www.google.com",
      },
   })
}

效果演示

image

wechat-work-pusher's People

Contributors

myleo1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.