Giter VIP home page Giter VIP logo

example's People

Contributors

silenceper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

example's Issues

服务器运行了实力程序但是微信后台配置失败

➜  wxoff go run main.go
wechat server listener at :8001

服务器已经抛弃了了,但是微信后台提示提交时失败

image

package main

import (
    "fmt"
    "net/http"

    wechat "github.com/silenceper/wechat/v2"
    "github.com/silenceper/wechat/v2/cache"
    offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
    "github.com/silenceper/wechat/v2/officialaccount/message"
)

func serveWechat(rw http.ResponseWriter, req *http.Request) {
    wc := wechat.NewWechat()
    //这里本地内存保存access_token,也可选择redis,�memcache或者自定cache
    memory := cache.NewMemory()
    cfg := &offConfig.Config{
        AppID:     "xxx",
        AppSecret: "xxx",
        Token:     "xxx",
        //EncodingAESKey: "xxxx",
        Cache: memory,
    }
    officialAccount := wc.GetOfficialAccount(cfg)

    // 传入request和responseWriter
    server := officialAccount.GetServer(req, rw)
    //设置接收消息的处理方法
    server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
        //TODO
        //回复消息:演示回复用户发送的消息
        text := message.NewText(msg.Content)
        return &message.Reply{MsgType: message.MsgTypeText, MsgData: text}
    })

    //处理消息接收以及回复
    err := server.Serve()
    if err != nil {
        fmt.Println(err)
        return
    }
    //发送回复的消息
    server.Send()
}

func main() {
    http.HandleFunc("/", serveWechat)
    fmt.Println("wechat server listener at", ":8001")
    err := http.ListenAndServe(":8001", nil)
    if err != nil {
        fmt.Printf("start server error , err=%v", err)
    }
}

参数我已经修改了

officialAccount.go serve 函数事例有错误

实例里返回消息时返回类型写错了
func (ex *ExampleOfficialAccount) Serve(c *gin.Context) { // 传入request和responseWriter server := ex.officialAccount.GetServer(c.Request, c.Writer) server.SkipValidate(true) //设置接收消息的处理方法 server.SetMessageHandler(func(msg *message.MixMessage) *message.Reply { //TODO //回复消息:演示回复用户发送的消息 text := message.NewText(msg.Content) // text := message.NewText("") -- return &message.Reply{MsgType: message.MsgTypeImage, MsgData: text} ++ return &message.Reply{MsgType: message.MsgTypeText, MsgData: text} ......

cannot use c.Request (variable of type *http.Request) as *http.Request value in argument to officialAccount.GetServercompiler field Request *http.Request (gin.Context).Request on pkg.go.dev No quick fixes available

cannot use c.Request (variable of type *http.Request) as *http.Request value in argument to officialAccount.GetServercompiler
field Request *http.Request
(gin.Context).Request on pkg.go.dev

No quick fixes available

func (mp *MP) Serve(c *gin.Context) {
	newMP := mp.NewMP()
	officialAccount := newMP.OpenPlatform.GetOfficialAccount(newMP.Options.AppId)

	officialAccount.GetServer(c.Request, c.Writer)
}

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.