Code Monkey home page Code Monkey logo

wechat-5's Introduction

wechat 开发框架

GoDoc

该框架仅为抛砖之作, 没有实现的微信公众号的全部api接口, 仅实现部分接口包括:

项目依赖

快速开始

客户端快速开发指南:

	
	import "github.com/liujianping/wechat"
	import "github.com/liujianping/wechat/entry"

	api := wechat.NewClient("appid", "appsecret")

	// 获取令牌
	var token entry.Token
	if err := api.Access(&token); err != nil {

	}

	// 获取用户信息
	var user_info entry.UserInfo
	if err := api.GetUserInfo("open_id", "zh_CN", &user_info); err != nil {

	}

	// 更多接口(参考其它微信项目的对象定义即可轻松实现)
	...

服务端(支持多应用)快速开发指南:

	package main

	import (
		"log"

		"github.com/liujianping/wechat"
		"github.com/liujianping/wechat/entry"
	)

	func DemoHandle(app *wechat.Application, request *entry.Request) (interface{}, error) {
		log.Printf("demo msg (%v)\n", request)
		return nil, nil
	}

	func EchoHandle(app *wechat.Application, request *entry.Request) (interface{}, error) {
		switch strings.ToLower(request.MsgType) {
		case entry.MsgTypeEvent:
			switch strings.ToLower(request.Event) {
			case entry.EventSubscribe:
				log.Printf("user (%s) subscribed", request.FromUserName)

				var user_info entry.UserInfo
				if err := app.Api().GetUserInfo(request.FromUserName, entry.LangZhCN, &user_info); err != nil {
					return nil, err
				}

				text := entry.NewText(request.FromUserName,
					request.ToUserName,
					time.Now().Unix(),
					fmt.Sprintf("亲爱的(%s), 谢谢您的关注!", user_info.NickName))
				return text, nil

			case entry.EventUnSubscribe:
				log.Printf("user (%s) unsubscribed", request.FromUserName)
			case entry.EventScan:
				log.Printf("user (%s) scan", request.FromUserName)
			case entry.EventLocation:
				log.Printf("user (%s) location", request.FromUserName)
			case entry.EventClick:
				log.Printf("user (%s) menu click (%s)", request.FromUserName, request.EventKey)
			case entry.EventView:
				log.Printf("user (%s) menu view (%s)", request.FromUserName, request.EventKey)
			}
		case entry.MsgTypeText:
			//! echo
			text := entry.NewText(request.FromUserName, request.ToUserName, time.Now().Unix(), request.TextContent)
			return text, nil
		case entry.MsgTypeImage:
		case entry.MsgTypeVoice:
		case entry.MsgTypeVideo:
		case entry.MsgTypeMusic:
		case entry.MsgTypeNews:
		}
		return nil, nil
	}

	func main() {
		demo := wechat.NewApplication("/demo", "demo_secret", "appid", "secret", false)

		btn11 := entry.NewButton("link").URL("http://github.com/liujianping/wechat")
		btn12 := entry.NewButton("click").Event("event_click")
		demo.Menu(entry.NewMenu(btn11, btn12))


		echo := wechat.NewApplication("/echo", "echo_secret", "appid", "secret", false)

		btn21 := entry.NewButton("link").URL("http://github.com/liujianping/wechat")
		btn22 := entry.NewButton("click").Event("event_click")
		echo.Menu(entry.NewMenu(btn21, btn22))

		serv := wechat.NewServer(":8080")
		
		serv.Application(demo, DemoHandle)
		serv.Application(echo, EchoHandle)

		serv.Start()
	}

微信测试号

申请

例子

参考 demo 实现.

老版本

README

wechat-5's People

Watchers

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