feat: add callback

This commit is contained in:
yanghao05
2025-04-14 21:15:24 +08:00
parent ea867f7261
commit 6e822e1a1b
7 changed files with 95 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ package wepay
import (
"context"
"crypto/rsa"
"encoding/json"
"errors"
"time"
@@ -55,11 +56,23 @@ func (c *Client) GetClient() *wechat.ClientV3 {
return c.payClient
}
// WxPublicKeyMap
func (c *Client) WxPublicKeyMap() map[string]*rsa.PublicKey {
return c.payClient.WxPublicKeyMap()
}
type PrepayData struct {
client *Client
AppID string `json:"app_id"`
PrepayID string `json:"prepay_id"`
}
// PaySignOfJSAPI
func (pay *PrepayData) PaySignOfJSAPI() (*wechat.JSAPIPayParams, error) {
return pay.client.payClient.PaySignOfJSAPI(pay.AppID, pay.PrepayID)
}
func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*PrepayData, error) {
bm := NewBodyMap(c.config)
f(bm)
@@ -76,6 +89,8 @@ func (c *Client) V3TransactionJsapi(ctx context.Context, f func(*BodyMap)) (*Pre
}
return &PrepayData{
client: c,
AppID: c.config.AppID,
PrepayID: resp.Response.PrepayId,
}, nil

View File

@@ -45,8 +45,11 @@ func (s *WePayTestSuite) Test_PrePay() {
})
So(err, ShouldBeNil)
So(resp, ShouldNotBeNil)
s.T().Logf("prepay response: %+v", resp)
sign, err := resp.PaySignOfJSAPI()
So(err, ShouldBeNil)
s.T().Logf("Sign: %+v", sign)
})
})
}