@@ -5,13 +5,15 @@ import (
5
5
"crypto"
6
6
"crypto/aes"
7
7
"crypto/cipher"
8
+ "crypto/md5"
8
9
"crypto/rand"
9
10
"crypto/rsa"
10
11
"crypto/sha256"
11
12
"crypto/x509"
12
13
"encoding/base64"
13
14
"encoding/json"
14
15
"encoding/pem"
16
+ "encoding/xml"
15
17
"fmt"
16
18
"io/ioutil"
17
19
"net/url"
@@ -58,6 +60,24 @@ type StWxPayResp struct {
58
60
} `json:"amount"`
59
61
}
60
62
63
+ type StWxRefundCb struct {
64
+ XMLName xml.Name `xml:"root"`
65
+ Text string `xml:",chardata"`
66
+ OutRefundNo string `xml:"out_refund_no"`
67
+ OutTradeNo string `xml:"out_trade_no"`
68
+ RefundAccount string `xml:"refund_account"`
69
+ RefundFee string `xml:"refund_fee"`
70
+ RefundID string `xml:"refund_id"`
71
+ RefundRecvAccout string `xml:"refund_recv_accout"`
72
+ RefundRequestSource string `xml:"refund_request_source"`
73
+ RefundStatus string `xml:"refund_status"`
74
+ SettlementRefundFee string `xml:"settlement_refund_fee"`
75
+ SettlementTotalFee string `xml:"settlement_total_fee"`
76
+ SuccessTime string `xml:"success_time"`
77
+ TotalFee string `xml:"total_fee"`
78
+ TransactionID string `xml:"transaction_id"`
79
+ }
80
+
61
81
// RsaSign 签名
62
82
func RsaSign (signContent string , privateKey * rsa.PrivateKey , hash crypto.Hash ) (string , error ) {
63
83
shaNew := hash .New ()
@@ -322,3 +342,36 @@ func WxPayV3DecodePayResp(v3Key string, body []byte, mchid, appid string) (*StWx
322
342
}
323
343
return & finalResp , nil
324
344
}
345
+
346
+ // WxPayCheckRefundCb 验证回调
347
+ func WxPayCheckRefundCb (mchKey string , body []byte ) (* StWxRefundCb , error ) {
348
+ mchKeyMd5 := md5 .Sum ([]byte (mchKey ))
349
+ bodyMap , err := XMLWalk (body )
350
+ if err != nil {
351
+ // 返回数据
352
+ return nil , err
353
+ }
354
+ reqInfo , ok := bodyMap ["req_info" ]
355
+ if ! ok {
356
+ return nil , fmt .Errorf ("no key req_info %s" , body )
357
+ }
358
+ reqInfoStr , ok := reqInfo .(string )
359
+ if ! ok {
360
+ return nil , fmt .Errorf ("error format req_info: %s" , body )
361
+ }
362
+ reqInfoBytes , err := base64 .StdEncoding .DecodeString (reqInfoStr )
363
+ if err != nil {
364
+ return nil , err
365
+ }
366
+ reqInfoFull , err := DecryptAesEcb (reqInfoBytes , mchKeyMd5 [:])
367
+ if err != nil {
368
+ return nil , err
369
+ }
370
+ Log .Debugf ("reqInfoFull: %s" , reqInfoFull )
371
+ var bodyXML StWxRefundCb
372
+ err = xml .Unmarshal (reqInfoFull , & bodyXML )
373
+ if err != nil {
374
+ return nil , err
375
+ }
376
+ return & bodyXML , nil
377
+ }
0 commit comments