-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from mailbaoer/master
add waxNotify support
- Loading branch information
Showing
3 changed files
with
92 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,69 @@ | ||
package pay | ||
|
||
//// 验证支付回调 | ||
//func () { | ||
// | ||
//} | ||
import ( | ||
"github.com/aimuz/wechat-sdk/utils" | ||
"strconv" | ||
) | ||
|
||
type ( | ||
WaxPayNotifyReq struct { | ||
AppID string `xml:"appid"` | ||
MchID string `xml:"mch_id"` | ||
BankType string `xml:"bank_type"` | ||
CashFee float64 `xml:"cash_fee"` | ||
FeeType string `xml:"fee_type"` | ||
IsSubscribe string `xml:"is_subscribe"` | ||
|
||
NonceStr string `xml:"nonce_str"` | ||
OpenID string `xml:"openid"` | ||
OutTradeNo string `xml:"out_trade_no"` | ||
ResultCode string `xml:"result_code"` | ||
ReturnCode string `xml:"return_code"` | ||
Sign string `xml:"sign"` | ||
TimeEnd string `xml:"time_end"` | ||
TotalFee float64 `xml:"total_fee"` | ||
TradeType string `xml:"trade_type"` | ||
TransactionID string `xml:"transaction_id"` | ||
} | ||
|
||
WaxPayNotifyResp struct { | ||
ReturnCode string `xml:"return_code"` | ||
ReturnMsg string `xml:"return_msg"` | ||
} | ||
) | ||
|
||
/** | ||
* 微信通知验证 | ||
*/ | ||
|
||
// 微信小程序待验证参数 | ||
func WaxVerifyParams(req WaxPayNotifyReq) map[string]string { | ||
verifyParams := make(map[string]string) | ||
|
||
verifyParams["appid"] = req.AppID | ||
verifyParams["bank_type"] = req.BankType | ||
verifyParams["cash_fee"] = strconv.FormatFloat(req.CashFee, 'f', 0, 64) | ||
verifyParams["fee_type"] = req.FeeType | ||
verifyParams["is_subscribe"] = req.IsSubscribe | ||
verifyParams["mch_id"] = req.MchID | ||
verifyParams["nonce_str"] = req.NonceStr | ||
verifyParams["openid"] = req.OpenID | ||
verifyParams["out_trade_no"] = req.OutTradeNo | ||
verifyParams["result_code"] = req.ResultCode | ||
verifyParams["return_code"] = req.ReturnCode | ||
verifyParams["time_end"] = req.TimeEnd | ||
verifyParams["total_fee"] = strconv.FormatFloat(req.TotalFee, 'f', 0, 64) | ||
verifyParams["trade_type"] = req.TradeType | ||
verifyParams["transaction_id"] = req.TransactionID | ||
|
||
return verifyParams | ||
} | ||
|
||
// 微信小程序支付签名验证 | ||
func WaxpayVerifySign(verifyParams map[string]string, signKey string, sign string) bool { | ||
signCalc, _ := utils.GenWeChatPaySign(verifyParams, signKey) | ||
if sign == signCalc { | ||
return true | ||
} | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters