package wechat import ( "crypto/aes" "crypto/cipher" "encoding/base64" "encoding/json" "strings" "git.chuangxin1.com/cx/myth/util" ) // DecryptAES256GCM 使用 AEAD_AES_256_GCM 算法进行解密 func DecryptAES256GCM(aesKey, associatedData, nonce, ciphertext string) (dataBytes []byte, err error) { var ( decodedCiphertext []byte c cipher.Block gcm cipher.AEAD ) decodedCiphertext, err = base64.StdEncoding.DecodeString(ciphertext) if err != nil { return } c, err = aes.NewCipher([]byte(aesKey)) if err != nil { return } gcm, err = cipher.NewGCM(c) if err != nil { return } dataBytes, err = gcm.Open(nil, []byte(nonce), decodedCiphertext, []byte(associatedData)) return } // Unmarshal 解析结构 func (r *PayResultNotifyV3) Unmarshal(body []byte) (err error) { err = json.Unmarshal(body, &r) return } // IsEntranceStateChange 是否微信支付分停车 状态变更通知 func (r *PayResultNotifyV3) IsEntranceStateChange() bool { return strings.Compare(r.EventType, "VEHICLE.ENTRANCE_STATE_CHANGE") == 0 } // IsTransactionSuccess 是否支付到账通知 func (r *PayResultNotifyV3) IsTransactionSuccess() bool { return strings.Compare(r.EventType, "TRANSACTION.SUCCESS") == 0 } // IsTradeSuccess 是否支付成功 func (r *PayOrderInfoV3) IsTradeSuccess() bool { return strings.Compare(r.TradeState, "SUCCESS") == 0 } // Unmarshal 解析结构 func (r *PayScoreParkingNotifyV3Result) Unmarshal(body []byte) (err error) { err = json.Unmarshal(body, &r) return } // Unmarshal 解析结构 func (r *PayScoreParkingNotifyV3Result) String() (s string) { bs, _ := json.Marshal(r) s = util.BytesToString(bs) return } // Unmarshal 解析结构 func (r *PayRefundInfoV3) Unmarshal(body []byte) (err error) { err = json.Unmarshal(body, &r) return } // Unmarshal 解析结构 func (r *PayOrderInfoV3) Unmarshal(body []byte) (err error) { err = json.Unmarshal(body, &r) return }