Code Monkey home page Code Monkey logo

servermsgpush's Introduction

开篇

  • 实现功能:通过测试公众号模版消息推送,能够实时获知服务器的状态。

  • ideal 来源于 方糖气球的 Server酱。 博主没有开源出来,就自己造个轮子用。

  • 代码基于python3的tornado实现的,实现方法很简单,语言只是工具。

  • 项目地址, Follower, Fork, Stars, Issues 啥都可以 🤣

具体过程

    exc_name: {{keyword1.DATA}}
    exc_value: {{keyword2.DATA}}
    filename: {{keyword3.DATA}}
    lineno: {{keyword4.DATA}}
    name: {{keyword5.DATA}}
    line: {{keyword6.DATA}}
  • 获取关注者信息 openid

  • config

    [base]
    port = 8000
    appid = 1  # 测试号信息
    appsecret = 2  # 测试号信息
    token_url = https://api.weixin.qq.com/cgi-bin/token?
    maintainer = ['a', 'b']  # 要推送人员的openid,可从关注者选
    [template]
    id = 1  # 模版id
    send = https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=
    url = https://github.com/iakisey  # 在微信上点击模版消息时所跳转的URL
  • 效果图

  • 代码片段

@update_token
def send_msg(openid, url, a, b, c, d, e, f):
    data = json.dumps({
        'touser': openid,
        'template_id': config['template']['exception_id'],
        'url': url,
        'data': {
            'keyword1': {
                'value': a,
                'color': '#173177'
            },
            'keyword2': {
                'value': b,
                'color': '#173177'
            },
            'keyword3': {
                'value': c,
                'color': '#173177'
            },
            'keyword4': {
                'value': d,
                'color': '#173177'
            },
            'keyword5': {
                'value': e,
                'color': '#173177'
            },
            'keyword6': {
                'value': f,
                'color': '#173177'
            },
        }
    }).encode()
    url = config['template']['send']
    url += config['base']['access_token']
    with urllib.request.urlopen(url, data) as f:
        print('send_msg result: {}'.format(f.read().decode()))

def output_wechat():
    from . import config
    exc_type, exc_value, exc_tb = sys.exc_info()
    exc_type_msg = exc_type.__name__ if exc_type else exc_type
    exc_tbs = sorted(
        [e for e in traceback.extract_tb(exc_tb)],
        key=lambda e: len(e.filename))
    exc_tb = exc_tbs[0] if exc_tbs else None
    exc_tb = exc_tb if exc_tb else None
    for user in eval(config['base']['maintainer']):
        send_msg(
            user,
            config['template']['url'],
            exc_type_msg,
            str(exc_value) if exc_value else None,
            *exc_tb
        ) if exc_type_msg or exc_value or exc_tb else None

servermsgpush's People

Contributors

iakisey avatar

Watchers

James Cloos avatar  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.