Skip to content

Commit

Permalink
调整合并的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
royalrick committed Jul 21, 2019
1 parent cd97f8a commit 8c73ce4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,19 @@ err := payment.HandlePaidNotify(w http.ResponseWriter, req *http.Request, func(
[官方文档](https://pay.weixin.qq.com/wiki/doc/api/wxa/wxa_api.php?chapter=9_3)

```go
import "github.com/medivhzhan/weapp/close"
import "github.com/medivhzhan/weapp/payment"

// 新建关闭订单
close := Close{
closer := payment.Closer{
AppID: "APPID",
MchID: "商户号",
OutTradeNo: "商户订单号",
}

res, err := close.Close("支付密钥")
res, err := closer.Close("支付密钥")
if err != nil {
// handle error
return
return
}

fmt.Printf("返回结果: %#v", res)
Expand Down
16 changes: 8 additions & 8 deletions payment/close.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ const (
closeAPI = "/pay/closeorder"
)

// Close 关闭订单
type Close struct {
// Closer 关闭订单
type Closer struct {
// 必填 ...
AppID string `xml:"appid"` // 小程序ID
MchID string `xml:"mch_id"` // 商户号
OutTradeNo string `xml:"out_trade_no"` // 商户订单号
}

type close struct {
type closer struct {
XMLName xml.Name `xml:"xml"`
Close
Closer
Sign string `xml:"sign"` // 签名
NonceStr string `xml:"nonce_str"` // 随机字符串
SignType string `xml:"sign_type,omitempty"` // 签名类型: 目前支持HMAC-SHA256和MD5,默认为MD5
Expand All @@ -39,9 +39,9 @@ type closeResponse struct {
CloseResponse
}

func (c *Close) prepare(key string) (close, error) {
clo := close{
Close: *c,
func (c *Closer) prepare(key string) (closer, error) {
clo := closer{
Closer: *c,
SignType: "MD5",
NonceStr: util.RandomString(32),
}
Expand All @@ -64,7 +64,7 @@ func (c *Close) prepare(key string) (close, error) {
}

// Close 发起关闭支付请求
func (c Close) Close(key string) (cres CloseResponse, err error) {
func (c Closer) Close(key string) (cres CloseResponse, err error) {
data, err := c.prepare(key)
if err != nil {
return
Expand Down
2 changes: 1 addition & 1 deletion util/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// SignByMD5 多参数通过MD5签名
func SignByMD5(data map[string]string, key string) (string, error) {

var query []string
query := make([]string, 0)
for k, v := range data {
query = append(query, k+"="+v)
}
Expand Down

0 comments on commit 8c73ce4

Please sign in to comment.