Skip to content

Commit 82d27e5

Browse files
committed
添加发现金红包
1 parent f939a7b commit 82d27e5

File tree

4 files changed

+90
-1
lines changed

4 files changed

+90
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
10. 交易保障
1717
11. 退款结果通知
1818
12. 拉取订单评价数据
19-
13. 发红包
19+
13. 现金红包 ✅

client.go

+31
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,34 @@ func (c *Client) UnifiedOrder(req *UnifiedOrderRequest) (resp *UnifiedOrderRespo
114114
}
115115
return
116116
}
117+
118+
// SendredPack 发现金红包
119+
func (c *Client) SendredPack(req *SendredPackRequest) (resp *SendredPackResponse, err error) {
120+
req.MchID = c.conf.MchID
121+
err = req.SignMD5(c.conf.APIKey)
122+
if err != nil {
123+
return
124+
}
125+
126+
var body []byte
127+
body, err = c.execute("/mmpaymkttransfers/sendredpack", req)
128+
if err != nil {
129+
return
130+
}
131+
132+
resp = new(SendredPackResponse)
133+
err = xml.Unmarshal(body, resp)
134+
if err != nil {
135+
resp = nil
136+
return
137+
}
138+
if resp.ReturnCode == "FAIL" {
139+
err = fmt.Errorf("通信错误:%s", resp.ReturnMsg)
140+
return
141+
}
142+
if resp.ResultCode == "FAIL" {
143+
err = fmt.Errorf("业务错误:%s", resp.ErrCodeDes)
144+
return
145+
}
146+
return
147+
}

sendred_pack.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package wxpay
2+
3+
import (
4+
"encoding/xml"
5+
6+
"github.com/nilorg/sdk/random"
7+
)
8+
9+
// https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
10+
11+
// SendredPackRequest 发红包
12+
type SendredPackRequest struct {
13+
XMLName xml.Name `xml:"xml"`
14+
NonceStr string `xml:"nonce_str"`
15+
Sign string `xml:"sign"`
16+
MchBillno string `xml:"mch_billno"`
17+
MchID string `xml:"mch_id"`
18+
SendName string `xml:"send_name"`
19+
ReOpenID string `xml:"re_openid"`
20+
TotalAmount uint `xml:"total_amount"`
21+
TotalNum uint `xml:"total_num"`
22+
Wishing string `xml:"wishing"`
23+
ClientIP string `xml:"client_ip"`
24+
ActName string `xml:"act_name"`
25+
Remark string `xml:"remark"`
26+
SceneID string `xml:"scene_id"`
27+
RiskInfo string `xml:"risk_info"`
28+
}
29+
30+
// NewSendredPackRequest 创建现金红包
31+
func NewSendredPackRequest() *SendredPackRequest {
32+
return &SendredPackRequest{
33+
NonceStr: random.AZaz09(32),
34+
}
35+
}
36+
37+
// SignMD5 md5
38+
func (req *SendredPackRequest) SignMD5(apiKey string) error {
39+
params, err := SignStructToParameter(*req)
40+
if err != nil {
41+
return err
42+
}
43+
params["key"] = apiKey
44+
value := SignMD5(params)
45+
req.Sign = value
46+
return nil
47+
}
48+
49+
// SendredPackResponse ...
50+
type SendredPackResponse struct {
51+
ResponseStatus
52+
MchBillno string `xml:"mch_billno"`
53+
MchID string `xml:"mch_id"`
54+
WxAppID string `xml:"wxappid"`
55+
ReOpenID string `xml:"re_openid"`
56+
TotalAmount uint `xml:"total_amount"`
57+
SendListID uint `xml:"send_listid"`
58+
}

unifiedorder.go unifie_dorder.go

File renamed without changes.

0 commit comments

Comments
 (0)