|
| 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 | +} |
0 commit comments