Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mailbaoer committed Jun 23, 2018
1 parent 5468fc2 commit bf9e510
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
62 changes: 31 additions & 31 deletions pay/check.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package pay

import (
"strconv"
"github.com/mailbaoer/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"`
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"`
Expand All @@ -27,43 +27,43 @@ type (
}

WaxPayNotifyResp struct {
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
}
)

/**
* 微信通知验证
*/

// 微信小程序待验证参数
func WaxVerifyParams(req WaxPayNotifyReq) ( map[string]string){
// 微信小程序待验证参数
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
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
signCalc, _ := utils.GenWeChatPaySign(verifyParams, signKey)
if sign == signCalc {
return true
}
return false
}
return false
}
2 changes: 1 addition & 1 deletion pay/pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func (m *WePay) WaxPay(totalFee int, openID string) (results *WaxPayRet, outTrad
Timestamp: fmt.Sprintf("%d", time.Now().Unix()),
NonceStr: unifiedOrderResp.NonceStr,
},
AppID: m.AppID,
AppID: m.AppID,
Package: "prepay_id=" + unifiedOrderResp.PrepayID,
SignType: "MD5",
}
Expand Down
4 changes: 2 additions & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"encoding/json"
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"math/rand"
Expand Down Expand Up @@ -98,7 +98,7 @@ func GenWeChatPaySign(m map[string]string, payKey string) (string, error) {
return "", err
}

sign:= strings.ToUpper(hex.EncodeToString(signByte))
sign := strings.ToUpper(hex.EncodeToString(signByte))
return sign, nil
}

Expand Down

0 comments on commit bf9e510

Please sign in to comment.