diff --git a/internal/pkg/wechat/utils/wxpay_utility.go b/internal/pkg/wechat/utils/wxpay_utility.go index 9df405c..f141bb1 100644 --- a/internal/pkg/wechat/utils/wxpay_utility.go +++ b/internal/pkg/wechat/utils/wxpay_utility.go @@ -515,8 +515,8 @@ func (srv *MchConfig) Request2(host, method, path string, reqBody []byte) (respo httpRequest.Header.Set("Authorization", authorization) - //hs, _ := json.Marshal(httpRequest.Header) - //fmt.Printf("\npath=%s\nreqBody=%s\nheaders=%s\n", path, string(reqBody), string(hs)) + hs, _ := json.Marshal(httpRequest.Header) + fmt.Printf("\npath=%s\nreqBody=%s\nheaders=%s\n", path, string(reqBody), string(hs)) client := &http.Client{} httpResponse, err := client.Do(httpRequest) @@ -529,6 +529,8 @@ func (srv *MchConfig) Request2(host, method, path string, reqBody []byte) (respo return nil, err } + fmt.Printf("\nrespBody=%s\n", string(respBody)) + if httpResponse.StatusCode >= 200 && httpResponse.StatusCode < 300 { // 2XX 成功,验证应答签名 err = ValidateResponse( diff --git a/test/bank_multi_activity.go b/test/bank_multi_activity.go index 2ad515c..54f1352 100644 --- a/test/bank_multi_activity.go +++ b/test/bank_multi_activity.go @@ -44,14 +44,64 @@ func marketing() *marketing2.Marketing { return &marketing2.Marketing{MchConfig: c} } +func marketingFJxw() *marketing2.Marketing { + + dir, err := os.Getwd() + if err != nil { + panic(err) + } + + parentDir := filepath.Dir(dir) + + //openssl x509 -in xxx.pem -noout -serial + + mchId := "1652465541" + wechatPayPublicKeyId := "PUB_KEY_ID_0117109533612025031800326400002563" + certificateSerialNo := "1E3F2CE013203BA9C3DEFC5782FCD3329C3DAC1C" + + //mchId := "1652465541" + //wechatPayPublicKeyId := "" + //certificateSerialNo := "1E3F2CE013203BA9C3DEFC5782FCD3329C3DAC1C" + + filePath := fmt.Sprintf("%s/cert/wechat/%s", parentDir, mchId) + + c, err := utils.CreateMchConfig( + mchId, // 商户号,是由微信支付系统生成并分配给每个商户的唯一标识符,商户号获取方式参考 https://pay.weixin.qq.com/doc/v3/merchant/4013070756 + certificateSerialNo, // 商户API证书序列号,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013053053 + fmt.Sprintf("%s/%s", filePath, "wechat_private_key.pem"), // 商户API证书私钥文件路径,本地文件路径 + wechatPayPublicKeyId, // 微信支付公钥ID,如何获取请参考 https://pay.weixin.qq.com/doc/v3/merchant/4013038816 + fmt.Sprintf("%s/%s", filePath, "pub_key.pem"), // 微信支付公钥文件路径,本地文件路径 + ) + if err != nil { + panic(err) + } + + return &marketing2.Marketing{MchConfig: c} +} + func MarketingSend() { - openId := "oSNb4ftgnWC22Z0cWTjsQebdr2Yk" - appId := "wx619991cc795028f5" + //openId := "oSNb4ftgnWC22Z0cWTjsQebdr2Yk" + //appId := "wx619991cc795028f5" + + //195516196845312409613 + openId := "ocuH-0Nymo4sJLRNabIBbg9H2XCo" + appId := "wx5d3e839568f24b2b" + //respBody={"coupon_id":"116076813524"} + + //openId := "ocZ-njugTd_fgCJMHTG8PukPAVm4" + //appId := "wxd9137161bc8f9ca9" + //respBody={"coupon_id":"117888124542"} + + //195516196845312409613 + //1958100775326560252 + //1958100775326560251 + //19581007753265602565 + //19581007753265602564 request := &marketing2.SendReq{ - ActivityId: utils.String("11941580000000004"), - StockId: utils.String("20811630"), - OutRequestNo: utils.String("20250801000000001"), + ActivityId: utils.String("11941580000000005"), + StockId: utils.String("20847510"), + OutRequestNo: utils.String("195516196845312409613"), Appid: utils.String(appId), StockCreatorMchId: utils.String("1652465541"), } diff --git a/test/coupon.go b/test/coupon.go index 1e9aaca..eddbb02 100644 --- a/test/coupon.go +++ b/test/coupon.go @@ -106,9 +106,19 @@ func QueryCoupon() { // Openid: core.String("oSNb4fpnLNdkFPk-O43o6f2hxxRo"), //} - appId := "wx619991cc795028f5" - openId := "oSNb4ftgnWC22Z0cWTjsQebdr2Yk" - couponId := "113831004454" + //appId := "wx619991cc795028f5" + //openId := "oSNb4ftgnWC22Z0cWTjsQebdr2Yk" + //couponId := "113831004454" + //req := cashcoupons.QueryCouponRequest{ + // CouponId: core.String(couponId), + // Appid: core.String(appId), + // Openid: core.String(openId), + //} + + appId := "wx5d3e839568f24b2b" + openId := "ocuH-0Nymo4sJLRNabIBbg9H2XCo" + couponId := "116076813524" + req := cashcoupons.QueryCouponRequest{ CouponId: core.String(couponId), Appid: core.String(appId), diff --git a/test/coupon_test.go b/test/coupon_test.go index b103ac2..61daa6f 100644 --- a/test/coupon_test.go +++ b/test/coupon_test.go @@ -29,7 +29,7 @@ func Test_QueryCoupon(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - SendCoupon() + QueryCoupon() }) } }