Code Monkey home page Code Monkey logo

wxmp's Introduction

微信公众平台SDK for Go

GoDoc

这是一个使用Go语言编写的微信公众平台SDK

举个栗子

被动回复用户消息

package main

import (
	"log"
	"net/http"

	"github.com/go-with/wxmp/server"
)

const (
	appId          = "" // 应用ID
	token          = "" // 令牌
	encodingAesKey = "" // 消息加解密密钥
)

func main() {
	store := server.NewMemoryStore()
	store.SetToken(appId, token)
	store.SetEncodingAESKey(appId, encodingAesKey)

	h := server.New(store)
	// 注册文本消息处理器
	h.OnMsg(server.MsgTypeText, TextMsgHandler)
	// 注册关注事件处理器
	h.OnEvt(server.EvtTypeSubscribe, SubscribeEvtHandler)

	http.Handle("/wxmp", h)

	err := http.ListenAndServe(":80", nil)
	if err != nil {
		log.Fatal(err)
	}
}

// 文本消息处理器
func TextMsgHandler(c *server.Context) {
	// 回音墙
	content := c.ReqMsg.Content
	err := c.ReplyTextMsg(content)
	if err != nil {
		log.Print(err)
	}
}

// 关注事件处理器
func SubscribeEvtHandler(c *server.Context) {
	err := c.ReplyTextMsg("Hey guy")
	if err != nil {
		log.Print(err)
	}
}

相关链接

微信公众平台

微信公众平台开发者文档

微信公众平台接口调试工具

微信公众平台接口测试帐号申请

许可协议

The MIT License (MIT)

wxmp's People

Contributors

sidbusy avatar

Watchers

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