wechatpay-apiv3 / wechatpay-go

微信支付 APIv3 的官方 Go Library
https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/index.shtml
Apache License 2.0
1.02k stars 140 forks source link

not valid wechatpay notify request: you must init Validator with auth.Verifier #106

Closed ResistanceTo closed 2 years ago

ResistanceTo commented 2 years ago

我想测试一下通知接口的使用,代码如下

func TestReq(c *gin.Context) {
    var handler notify.Handler
    // handler := new(notify.Handler)
    content := new(payments.Transaction)
    notifyReq, err := handler.ParseNotifyRequest(context.Background(), c.Request, content)
    if err != nil {
        fmt.Println(err)
        return
    }

    // 处理通知内容
    fmt.Println(notifyReq.Summary)
    fmt.Println(content)
}

发送数据用的postman - json

curl --location --request POST 'http://127.0.0.1:9101/api/pay/PaymentWechatNotify' \
--header 'User-Agent: apifox/1.0.0 (https://www.apifox.cn)' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "EV-2018022511223320873",
    "create_time": "2015-05-20T13:29:35+08:00",
    "resource_type": "encrypt-resource",
    "event_type": "TRANSACTION.SUCCESS",
    "summary": "支付成功",
    "resource": {
        "original_type": "transaction",
        "algorithm": "AEAD_AES_256_GCM",
        "ciphertext": "",
        "associated_data": "",
        "nonce": ""
    }
}'

代码样例是从测试文件中拿出来的,但是一执行就报错not valid wechatpay notify request: you must init Validator with auth.Verifier,请问这个怎么初始化呢。

https://github.com/wechatpay-apiv3/wechatpay-go/blob/44606123a4c0aef7462e11d07130c7ccdc38a2de/core/notify/example_test.go#L14

EmmetZC commented 2 years ago

你好,你可以看一下这里,有写明如何初始化一个 notify.Handler

ResistanceTo commented 2 years ago

你好,你可以看一下这里,有写明如何初始化一个 notify.Handler

谢谢您的解答