|
@@ -8,6 +8,7 @@ import (
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
|
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
|
|
|
|
+ "github.com/wechatpay-apiv3/wechatpay-go/services/payments/native"
|
|
payUtils "github.com/wechatpay-apiv3/wechatpay-go/utils"
|
|
payUtils "github.com/wechatpay-apiv3/wechatpay-go/utils"
|
|
"hongze/hongze_web_mfyx/models"
|
|
"hongze/hongze_web_mfyx/models"
|
|
"hongze/hongze_web_mfyx/models/order"
|
|
"hongze/hongze_web_mfyx/models/order"
|
|
@@ -17,7 +18,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
const (
|
|
const (
|
|
- MchPKFileName = "./utils/cert/apiclient_key.pem"
|
|
|
|
|
|
+ MchPKFileName = "../hongze_mfyx/utils/cert/apiclient_key.pem"
|
|
Mchid = "1624495680"
|
|
Mchid = "1624495680"
|
|
MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
@@ -36,6 +37,7 @@ func getWechatClient() (context.Context, *core.Client, error) {
|
|
opts := []core.ClientOption{
|
|
opts := []core.ClientOption{
|
|
option.WithWechatPayAutoAuthCipher(Mchid, MchCertificateSerialNumber, mchPrivateKey, MchAPIv3Key),
|
|
option.WithWechatPayAutoAuthCipher(Mchid, MchCertificateSerialNumber, mchPrivateKey, MchAPIv3Key),
|
|
}
|
|
}
|
|
|
|
+
|
|
client, err := core.NewClient(ctx, opts...)
|
|
client, err := core.NewClient(ctx, opts...)
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Printf("new wechat pay client err:%s", err)
|
|
log.Printf("new wechat pay client err:%s", err)
|
|
@@ -92,6 +94,40 @@ func ExampleJsapiApiServicePrepay(orderDetail *order.CygxOrder, unionId string)
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//func init() {
|
|
|
|
+// ExampleNativeApiService_Prepay()
|
|
|
|
+//}
|
|
|
|
+
|
|
|
|
+func ExampleNativeApiServicePrepay(orderDetail *order.CygxOrder) (codeUrl string, err error) {
|
|
|
|
+ defer func() {
|
|
|
|
+ if err != nil {
|
|
|
|
+ fmt.Println(err)
|
|
|
|
+ go utils.SendAlarmMsg(fmt.Sprint("生成预支付交易单失败 ExampleNativeApiServicePrepay, err:", err.Error(), "OrderCode:", orderDetail.OrderCode), 2)
|
|
|
|
+ }
|
|
|
|
+ }()
|
|
|
|
+ ctx, client, _ := getWechatClient()
|
|
|
|
+ svc := native.NativeApiService{Client: client}
|
|
|
|
+ resp, _, err := svc.Prepay(ctx,
|
|
|
|
+ native.PrepayRequest{
|
|
|
|
+ Appid: core.String(utils.WxAppId),
|
|
|
|
+ Mchid: core.String(Mchid),
|
|
|
|
+ Description: core.String(orderDetail.SourceTitle),
|
|
|
|
+ OutTradeNo: core.String(orderDetail.OrderCode),
|
|
|
|
+ TimeExpire: core.Time(time.Now()),
|
|
|
|
+ Attach: core.String(""),
|
|
|
|
+ NotifyUrl: core.String(utils.WxPayJsapiNotifyUrl),
|
|
|
|
+ GoodsTag: core.String(""),
|
|
|
|
+ SupportFapiao: core.Bool(false),
|
|
|
|
+ Amount: &native.Amount{
|
|
|
|
+ Currency: core.String("CNY"),
|
|
|
|
+ Total: core.Int64(int64(orderDetail.OrderMoney * 100)), // 分
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ )
|
|
|
|
+ codeUrl = *resp.CodeUrl
|
|
|
|
+ return
|
|
|
|
+}
|
|
|
|
+
|
|
type WechatPayCallback struct {
|
|
type WechatPayCallback struct {
|
|
MchID string `json:"mchid"`
|
|
MchID string `json:"mchid"`
|
|
AppID string `json:"appid"`
|
|
AppID string `json:"appid"`
|