|
@@ -5,48 +5,45 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
|
|
- "github.com/wechatpay-apiv3/wechatpay-go/core/option"
|
|
|
"github.com/wechatpay-apiv3/wechatpay-go/services/payments/jsapi"
|
|
|
- payUtils "github.com/wechatpay-apiv3/wechatpay-go/utils"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
- "log"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
-const (
|
|
|
- MchPKFileName = "../hongze_mfyx/utils/cert/apiclient_key.pem"
|
|
|
- Mchid = "1624495680"
|
|
|
- MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
|
- MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
|
-)
|
|
|
+//const (
|
|
|
+// MchPKFileName = "../hongze_mfyx/utils/cert/apiclient_key.pem"
|
|
|
+// Mchid = "1624495680"
|
|
|
+// MchCertificateSerialNumber = "5ED2719CFAE5205763034AD80BF4B8A33533C418"
|
|
|
+// MchAPIv3Key = "W1tbnzQrzQ7yRRNuQCIHjis8dgdasKVX"
|
|
|
+//)
|
|
|
|
|
|
-// 微信商户建立连接
|
|
|
-func getWechatClient() (context.Context, *core.Client, error) {
|
|
|
- var err error
|
|
|
- defer func() {
|
|
|
- if err != nil {
|
|
|
- fmt.Println("err", err)
|
|
|
- go utils.SendAlarmMsg(fmt.Sprint("微信商户建立连接失败 getWechatClient, err:", err.Error()), 2)
|
|
|
- }
|
|
|
- }()
|
|
|
- // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
- mchPrivateKey, err := payUtils.LoadPrivateKeyWithPath(MchPKFileName)
|
|
|
- if err != nil {
|
|
|
- log.Print("load merchant private key error")
|
|
|
- return nil, nil, err
|
|
|
- }
|
|
|
- ctx := context.Background()
|
|
|
- // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
|
|
- opts := []core.ClientOption{
|
|
|
- option.WithWechatPayAutoAuthCipher(Mchid, MchCertificateSerialNumber, mchPrivateKey, MchAPIv3Key),
|
|
|
- }
|
|
|
- client, err := core.NewClient(ctx, opts...)
|
|
|
- if err != nil {
|
|
|
- log.Printf("new wechat pay client err:%s", err)
|
|
|
- return nil, nil, err
|
|
|
- }
|
|
|
- return ctx, client, nil
|
|
|
-}
|
|
|
+//// 微信商户建立连接
|
|
|
+//func getWechatClient() (context.Context, *core.Client, error) {
|
|
|
+// var err error
|
|
|
+// defer func() {
|
|
|
+// if err != nil {
|
|
|
+// fmt.Println("err", err)
|
|
|
+// go utils.SendAlarmMsg(fmt.Sprint("微信商户建立连接失败 getWechatClient, err:", err.Error()), 2)
|
|
|
+// }
|
|
|
+// }()
|
|
|
+// // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
+// mchPrivateKey, err := payUtils.LoadPrivateKeyWithPath(MchPKFileName)
|
|
|
+// if err != nil {
|
|
|
+// log.Print("load merchant private key error")
|
|
|
+// return nil, nil, err
|
|
|
+// }
|
|
|
+// ctx := context.Background()
|
|
|
+// // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
|
|
|
+// opts := []core.ClientOption{
|
|
|
+// option.WithWechatPayAutoAuthCipher(Mchid, MchCertificateSerialNumber, mchPrivateKey, MchAPIv3Key),
|
|
|
+// }
|
|
|
+// client, err := core.NewClient(ctx, opts...)
|
|
|
+// if err != nil {
|
|
|
+// log.Printf("new wechat pay client err:%s", err)
|
|
|
+// return nil, nil, err
|
|
|
+// }
|
|
|
+// return ctx, client, nil
|
|
|
+//}
|
|
|
|
|
|
//func init() {
|
|
|
// GetQueryOrderByOutTradeNo("OD202404081631545174")
|
|
@@ -61,16 +58,17 @@ func GetQueryOrderByOutTradeNo(outTradeNo string) (tradeState string, statusCode
|
|
|
go utils.SendAlarmMsg(fmt.Sprint("根据订单号查询订单状态失败 GetQueryOrderByOutTradeNo, err:", err.Error(), "outTradeNo", outTradeNo), 2)
|
|
|
}
|
|
|
}()
|
|
|
- ctx, client, err := getWechatClient()
|
|
|
- if err != nil {
|
|
|
- log.Printf("getWechatClientt err:%s", err)
|
|
|
- return
|
|
|
- }
|
|
|
- svc := jsapi.JsapiApiService{Client: client}
|
|
|
+ //ctx, client, err := getWechatClient()
|
|
|
+ //if err != nil {
|
|
|
+ // log.Printf("getWechatClientt err:%s", err)
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ ctx := context.Background()
|
|
|
+ svc := jsapi.JsapiApiService{Client: utils.WechatCertClient}
|
|
|
resp, result, err := svc.QueryOrderByOutTradeNo(ctx,
|
|
|
jsapi.QueryOrderByOutTradeNoRequest{
|
|
|
OutTradeNo: core.String(outTradeNo),
|
|
|
- Mchid: core.String(Mchid),
|
|
|
+ Mchid: core.String(utils.Mchid),
|
|
|
},
|
|
|
)
|
|
|
statusCode = result.Response.StatusCode
|