mirror of
https://github.com/silenceper/wechat.git
synced 2026-03-01 00:35:26 +08:00
fix golint
This commit is contained in:
28
pay/pay.go
28
pay/pay.go
@@ -1,9 +1,10 @@
|
||||
package pay
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/silenceper/wechat/context"
|
||||
"github.com/silenceper/wechat/util"
|
||||
)
|
||||
@@ -15,9 +16,9 @@ type Pay struct {
|
||||
*context.Context
|
||||
}
|
||||
|
||||
// Params was NEEDED when request unifiedorder
|
||||
// 传入的参数,用于生成 prepay_id 的必需参数
|
||||
// PayParams was NEEDED when request unifiedorder
|
||||
type PayParams struct {
|
||||
type Params struct {
|
||||
TotalFee string
|
||||
CreateIP string
|
||||
Body string
|
||||
@@ -25,8 +26,8 @@ type PayParams struct {
|
||||
OpenID string
|
||||
}
|
||||
|
||||
// PayConfig 是传出用于 jsdk 用的参数
|
||||
type PayConfig struct {
|
||||
// Config 是传出用于 jsdk 用的参数
|
||||
type Config struct {
|
||||
Timestamp int64
|
||||
NonceStr string
|
||||
PrePayID string
|
||||
@@ -64,13 +65,13 @@ type payRequest struct {
|
||||
OutTradeNo string `xml:"out_trade_no"` //商户订单号
|
||||
FeeType string `xml:"fee_type,omitempty"` //标价币种
|
||||
TotalFee string `xml:"total_fee"` //标价金额
|
||||
SpbillCreateIp string `xml:"spbill_create_ip"` //终端IP
|
||||
SpbillCreateIP string `xml:"spbill_create_ip"` //终端IP
|
||||
TimeStart string `xml:"time_start,omitempty"` //交易起始时间
|
||||
TimeExpire string `xml:"time_expire,omitempty"` //交易结束时间
|
||||
GoodsTag string `xml:"goods_tag,omitempty"` //订单优惠标记
|
||||
NotifyUrl string `xml:"notify_url"` //通知地址
|
||||
NotifyURL string `xml:"notify_url"` //通知地址
|
||||
TradeType string `xml:"trade_type"` //交易类型
|
||||
ProductId string `xml:"product_id,omitempty"` //商品ID
|
||||
ProductID string `xml:"product_id,omitempty"` //商品ID
|
||||
LimitPay string `xml:"limit_pay,omitempty"` //
|
||||
OpenID string `xml:"openid,omitempty"` //用户标识
|
||||
SceneInfo string `xml:"scene_info,omitempty"` //场景信息
|
||||
@@ -82,8 +83,8 @@ func NewPay(ctx *context.Context) *Pay {
|
||||
return &pay
|
||||
}
|
||||
|
||||
// PrePayId will request wechat merchant api and request for a pre payment order id
|
||||
func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
||||
// PrePayID will request wechat merchant api and request for a pre payment order id
|
||||
func (pcf *Pay) PrePayID(p *Params) (prePayID string, err error) {
|
||||
nonceStr := util.RandomStr(32)
|
||||
tradeType := "JSAPI"
|
||||
template := "appid=%s&body=%s&mch_id=%s&nonce_str=%s¬ify_url=%s&openid=%s&out_trade_no=%s&spbill_create_ip=%s&total_fee=%s&trade_type=%s&key=%s"
|
||||
@@ -97,8 +98,8 @@ func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
||||
Body: p.Body,
|
||||
OutTradeNo: p.OutTradeNo,
|
||||
TotalFee: p.TotalFee,
|
||||
SpbillCreateIp: p.CreateIP,
|
||||
NotifyUrl: pcf.PayNotifyURL,
|
||||
SpbillCreateIP: p.CreateIP,
|
||||
NotifyURL: pcf.PayNotifyURL,
|
||||
TradeType: tradeType,
|
||||
OpenID: p.OpenID,
|
||||
}
|
||||
@@ -117,7 +118,6 @@ func (pcf *Pay) PrePayId(p *PayParams) (prePayID string, err error) {
|
||||
return payRet.PrePayID, nil
|
||||
}
|
||||
return "", errors.New(payRet.ErrCode + payRet.ErrCodeDes)
|
||||
} else {
|
||||
return "", errors.New("[msg : xmlUnmarshalError] [rawReturn : " + string(rawRet) + "] [params : " + str + "] [sign : " + sign + "]")
|
||||
}
|
||||
return "", errors.New("[msg : xmlUnmarshalError] [rawReturn : " + string(rawRet) + "] [params : " + str + "] [sign : " + sign + "]")
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"bufio"
|
||||
"bytes"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"crypto/md5"
|
||||
@@ -186,7 +186,7 @@ func decodeNetworkByteOrder(orderBytes []byte) (n uint32) {
|
||||
uint32(orderBytes[3])
|
||||
}
|
||||
|
||||
// 计算 32 位长度的 MD5 sum
|
||||
// MD5Sum 计算 32 位长度的 MD5 sum
|
||||
func MD5Sum(txt string) (sum string) {
|
||||
h := md5.New()
|
||||
buf := bufio.NewWriterSize(h, 128)
|
||||
|
||||
Reference in New Issue
Block a user