Commit 1f6cb3f6 by yemin

no message

parent 3126ec25
......@@ -57,6 +57,7 @@ func SendMeg(p *SendSubscribeMsgParam) error {
return err
}
r := response.MiniProgramResponse{}
fmt.Println("微信返回:" + string(bs))
err = json.Unmarshal(bs, &r)
if err != nil {
return err
......
package subscribe
import (
"fmt"
"testing"
)
func TestSendMeg(t *testing.T) {
/*c := minipro.NewMiniClient("wx7928e9ff9e2a55b5", "c8efb701d50d2a8e5cc5715495474281")
at, _ := c.NewAccessToken()
fmt.Println(at.AccessToken)*/
ds := make([]*SendSubscribeMsgDataParam, 5)
ds[0] = &SendSubscribeMsgDataParam{
Name: "thing1",
Value: "氧气机租赁",
}
ds[1] = &SendSubscribeMsgDataParam{
Name: "character_string2",
Value: "CO202211171729370004",
}
ds[2] = &SendSubscribeMsgDataParam{
Name: "time3",
Value: "2022-11-17 17:31:41",
}
ds[3] = &SendSubscribeMsgDataParam{
Name: "thing4",
Value: "随机名字",
}
ds[4] = &SendSubscribeMsgDataParam{
Name: "thing8",
Value: "30分钟",
}
p := SendSubscribeMsgParam{
AccessToken: "62_Xqd-gMRVBYHr6zwc_CGIrAMDDDcVz38hBr6Et-toqsHx0CtMmT0sBAbcvCiepeJNC_THydXRrkUBn1PB6Uw9AjGHWeolXiO27W-EfYp3j9iE5a6zS-T7ZyCwN8wNQZjAIAJMV",
TemplateId: "RGyTMKMFXP77MGu_xcxk0bToV8rbzuVfW2_tcsgds0I",
Page: "/pages/orderDetail/orderDetail?id=CO202211171729370004",
Touser: "oHzrE4lzjGUmXDGwsn1kfPyog9_4",
Data: ds,
}
err := SendMeg(&p)
if err != nil {
fmt.Println(err.Error())
}
}
......@@ -6,6 +6,7 @@ import (
"crypto/rsa"
"errors"
"fmt"
"git.168cad.top/go/wechat-client-sdk/util"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/auth/verifiers"
"github.com/wechatpay-apiv3/wechatpay-go/core/downloader"
......@@ -76,7 +77,7 @@ func (s *WechatPartnerPayClient) getWxPayClient() *core.Client {
if s.MchPrivateKey == nil {
panic(errors.New("商户私钥未配置,请检查"))
}
mchPrivateKey, err := LoadPrivateKey(*s.MchPrivateKey)
mchPrivateKey, err := util.LoadPrivateKey(*s.MchPrivateKey)
if err != nil {
panic(errors.New("商户私钥配置错误,请检查"))
}
......
package refund
import (
"context"
"crypto/rsa"
"errors"
"fmt"
"git.168cad.top/go/wechat-client-sdk/util"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/core/option"
"github.com/wechatpay-apiv3/wechatpay-go/services/refunddomestic"
"log"
"math/big"
"strings"
)
type WechatRefundClient struct {
SpMchId *string `json:"spMchId,omitempty"` // 服务商商户号(如果服务商模式,该值需要填写)
MchId *string `json:"mchId,omitempty"` // 收款商户号/子商户号(如果是服务商模式,配置特约商户号)
MchSerialNo *string `json:"mchSerialNo,omitempty"` // 收款商户证书序号
MchPrivateKey *string `json:"mchPrivateKey,omitempty"` // 收款商户私钥
ApiKey *string `json:"apiKey,omitempty"` // apiKey
wxClient *core.Client //不需要外界传入
privateKey *rsa.PrivateKey //不需要外界传入
}
// ApplyRefund 申请退款
func (r *WechatRefundClient) ApplyRefund(param *ApplyParam) *refunddomestic.Refund {
wxClient := r.getWxRefundClient()
svc := refunddomestic.RefundsApiService{Client: wxClient}
payMoney, b := new(big.Int).SetString(new(big.Float).Mul(new(big.Float).SetFloat64(param.PayMoney), new(big.Float).SetFloat64(100)).String(), 10)
if !b {
panic(errors.New("金额错误请检查,请检查"))
}
refundMoney, b1 := new(big.Int).SetString(new(big.Float).Mul(new(big.Float).SetFloat64(param.RefundMoney), new(big.Float).SetFloat64(100)).String(), 10)
if !b1 {
panic(errors.New("金额错误请检查,请检查"))
}
resp, _, err := svc.Create(context.Background(),
refunddomestic.CreateRequest{
SubMchid: r.MchId,
OutTradeNo: core.String(param.OutTradeNo),
OutRefundNo: core.String(param.OutRefundNo),
Reason: core.String(param.Reason),
NotifyUrl: core.String(param.NotifyUrl),
Amount: &refunddomestic.AmountReq{
Currency: core.String("CNY"),
Refund: core.Int64(refundMoney.Int64()),
Total: core.Int64(payMoney.Int64()),
},
},
)
if err != nil {
panic(errors.New(getErrMessage(err.Error())))
}
log.Println(fmt.Sprintf("微信退款调用结果:%s", resp.String()))
return resp
}
func (r *WechatRefundClient) getWxRefundClient() *core.Client {
if r.wxClient != nil {
return r.wxClient
}
// 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
if r.MchPrivateKey == nil {
panic(errors.New("商户私钥未配置,请检查"))
}
mchPrivateKey, err := util.LoadPrivateKey(*r.MchPrivateKey)
if err != nil {
panic(errors.New("商户私钥配置错误,请检查"))
}
r.privateKey = mchPrivateKey
// 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力
opts := []core.ClientOption{
option.WithWechatPayAutoAuthCipher(*r.SpMchId, *r.MchSerialNo, mchPrivateKey, *r.ApiKey),
}
wc, err1 := core.NewClient(context.Background(), opts...)
if err1 != nil {
panic(err1)
}
r.wxClient = wc
return wc
}
func getErrMessage(msg string) string {
startStr := "response:["
endStr := "Header"
startIndex := strings.Index(msg, startStr)
endIndex := strings.Index(msg, endStr)
rs := msg
if startIndex >= 0 && endIndex > 0 {
rs = msg[startIndex+len(startStr) : endIndex]
}
return strings.ReplaceAll(rs, "\n", " ")
}
package refund
type ApplyParam struct {
OutTradeNo string // 原支付交易对应的商户订单号
OutRefundNo string // 商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔
Reason string // 退款原因
NotifyUrl string // 回调地址
PayMoney float64 // 原支付交易的订单总金额(元)
RefundMoney float64 // 退款金额(元),不能超过原订单支付金额
}
package refund
package test
import (
"encoding/json"
"git.168cad.top/go/wechat-client-sdk/partnerpay"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"log"
"testing"
)
func TestWxJsApiOrder(t *testing.T) {
c := &partnerpay.WechatPartnerPayClient{
AppId: core.String("wx7928e9ff9e2a55b5"),
SpMchId: core.String("1527752671"),
MchId: core.String("1530689371"),
MchSerialNo: core.String("46D40B8EA3C4899221C67B92825A2C58EA1488CC"),
MchPrivateKey: core.String("MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDhFF37v9Z724c7mVr/GE2rV+SfD9suICPsR/Ft0d+Y5/jzof68zFf907nkb/SwWdgQWn6ISZnTMZapIRSHP/BLJWA51uGJXLRc5J8BDxuxHGfMRhyRBH37VC12h4PP4Tp9+taT7rk+5tKYEG55Jm3+5vDeG1o3fGK0lh5h7o116hMp5xVJfGM79hvPOavYVqXPg0qHAac+KkSn4/7Ml+s76oUZPY11/ePCwOQnMDLBKTRyiQmHlSZSnMtDVfcUZu1w3FSDWDfSUtkp8uelcl5CmK65UbjqHduanFMivmRwtZpG4OiD9PQYO7OirNyNsfwN4iUFkiB0+CAF+nAwnNPtAgMBAAECggEBANIAqcvI6rq3Uc7GwANAzr7ui83pAmxf6oR7f4QijEfjMAFJBR9sXTDjyg6ccqXTvedMN8C7Qz2sh9CXn8qtWmsSnVx55AbAqzv8x2o6iXDPev058U9Q7KaBnMV5nP9pOqTuVCTEWKyauqTMt/ZrZ7esC9J/nMYmVQX/BqwC4pO/KPXqJj2qbokaOy663dmV6juvCswP8+Y5GENxTk1O1260aW7F/EQOypd+jX8nQAiJ1Z/oX/lR42DKis4G9L4lS1DgPsNTPkaMdRmX9Qy9NzIjCBagKTve62273lxgq73/PJLJT0RvzKaAnESy+ZSS0g5ZPUqgNiUfJey1gFedJmECgYEA+qhs6QoEQOlekkomErm2otPv2wZjtD29HRxg3nOocb0w+qZuycAWfkRmlnQ3Evbn2cyx5ax/Pr+1dKphVc4H5qbCEJ1MsBcZhxM+MTXVL/K1zxAP5ekbNBdRkElY2vM6Z5nnMxIXox3W3b2Rn2RmkFd3szGeKszO804njOCtWYUCgYEA5eBjQj23aPUOIGTGx4SnfV9JrGeoRx5mBLbQ/HlI8rzTY3UkXk9l7SOmFONDR/2xW77sKWEWcigqco6/5FX/7wEmeIScCaS2qEdXfpzahyR9pwv5Abjx+kz/oJ9ZTaB8WvJhxGz1HwN5PfxjIoCyf0e5ZLqBJ5xBy8s/ewf4KUkCgYBQwRZldd6s8wKO6uidO8vFZbZuv/47QXC+AjiLMoPgMO2osxoaUZJtl6fdbQ+ZQoarurDNp+dO1gCl14aIWFpfSvZW1/au/KIyzFZLEGbgjbdZQHl+vr0O6TxT2e2QjLASVJkR8RBAcwqYYcyap4QLmMJtrtygOV+rL1C6qF/w6QKBgQDl2wAFTWbm+RpeA8bL2/YKI8ysKp4WNuw1zIOd4Lyzk2If8hMihmvZuiqoejJdeuvsXDUSjzT9gvImyFxSOjgGyXSpT5gjAGNwUp3HSZotRayq6wra0Q6MhI+bEZsfRtjxq6lc2sIjd7q043hRGLTjFlnnwaHBdLpJx/q6z9YxmQKBgQDgHv7CcNCTTUr+go+4ivDpYY8OlNOhA5oPj7FFoYQvw10iN5ab9Mah9R5js5t/ynuV0BfTXY7Yn5v526x8ut5D1buRS8t3OiKTrbHP1T3h61zC6OcjUPaBNpCR1VhNkMjIoLyD3MUxPivxf5o2skLyuAbIQt1UiOiPaucbX+TCYw=="),
ApiKey: core.String("DCKKISDF200432324320234324324235"),
}
p := &partnerpay.PaymentJsApiParam{
OpenId: core.String("oHzrE4nL5N0NYcVufFWK-312Ysao"),
PaymentParams: partnerpay.PaymentParams{
Money: core.Float64(float64(1)),
Title: core.String("测试支付"),
OutTradeNo: core.String("CO202210281753400005001"),
CallBackUrl: core.String("https://test-go-rym-oxygen-app-service.168cad.top/payCallBack/wechat"),
},
}
r := c.WxJsApiOrder(p)
b, err := json.Marshal(r)
if err != nil {
log.Println("错误:", err.Error())
}
log.Println("返回结果:", string(b))
}
func TestPay(t *testing.T) {
}
package partnerpay
package util
import (
"crypto/rsa"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment