Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
aimuz committed Jul 23, 2018
1 parent 73bc1a6 commit c04ea3d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
12 changes: 7 additions & 5 deletions pay/redpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package pay

import (
"encoding/xml"
"github.com/aimuz/wechat-sdk/utils"
"github.com/aimuz/wechat-sdk/common"
"errors"
"fmt"
"github.com/aimuz/wechat-sdk/common"
"github.com/aimuz/wechat-sdk/utils"
)

/*
redpack 红包
*/

type (
// RedPack 发送红包接口
RedPack interface {
Send(payKey, certFile, keyFile, rootCaFile string) (*RedPackResp, error)
}

// SendRedPackReq 发送普通红包请求参数
SendRedPackReq struct {
XMLName xml.Name `xml:"xml"`
NonceStr string `xml:"nonce_str,omitempty" json:"nonce_str"` // NonceStr 随机字符串
Expand All @@ -37,6 +38,7 @@ type (
ConsumeMchID string `xml:"consume_mch_id,omitempty" json:"consume_mch_id"` // ConsumeMchID 资金授权商户号
}

// RedPackResp 发送红包返回值
RedPackResp struct {
ReturnMsg string `xml:"return_msg"`
MchID string `xml:"mch_id"`
Expand Down Expand Up @@ -98,7 +100,7 @@ func (m *WePay) sendRedPack(req *SendRedPackReq) (string, *RedPackResp, error) {
return req.MchBillNo, resp, nil
}

// SendRedPack 发送普通红包
// Send 发送普通红包
func (m *SendRedPackReq) Send(payKey string, certFile, keyFile, rootCaFile string) (*RedPackResp, error) {

tMap, err := utils.Struct2Map(m)
Expand Down Expand Up @@ -141,7 +143,7 @@ func (m *SendRedPackReq) Send(payKey string, certFile, keyFile, rootCaFile strin
// CheckErr 检查微信是否返回错误信息
func (m *RedPackResp) CheckErr() error {
if m.ResultCode != "SUCCESS" || m.ReturnCode != "SUCCESS" {
return errors.New(fmt.Sprintf("[%s,%s]%s", m.ResultCode, m.ErrCode, m.ErrCodeDes))
return fmt.Errorf("[%s,%s]%s", m.ResultCode, m.ErrCode, m.ErrCodeDes)
}

return nil
Expand Down
10 changes: 6 additions & 4 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/tls"
"crypto/x509"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"github.com/aimuz/wechat-sdk/common"
"io/ioutil"
"math/rand"
"net/http"
"sort"
"strconv"
"strings"
"time"
"crypto/tls"
"crypto/x509"
"errors"
"github.com/aimuz/wechat-sdk/common"
)

// NewRequest 请求包装
Expand Down Expand Up @@ -100,6 +100,8 @@ func NewCertRequest(certFile, keyFile, rootCaFile string) (*Request, error) {

return &Request{Client: client}, nil
}

// NewRequest 发送请求
func (m *Request) NewRequest(method, url string, data []byte) (body []byte, err error) {
if method == "GET" {
url = fmt.Sprint(url, "?", string(data))
Expand Down

0 comments on commit c04ea3d

Please sign in to comment.