// 微信委托代扣 // 在线文档: // https://pay.weixin.qq.com/wiki/doc/api/pap.php?chapter=18_17&index=6 package wechat import "encoding/xml" // PapPay 委托代扣申请扣款 type PapPay struct { XMLName xml.Name `xml:"xml"` AppID string `xml:"appid"` MchID string `xml:"mch_id"` NonceStr string `xml:"nonce_str"` // 随机字符串,不长于32位 Sign string `xml:"sign"` // 签名 Body string `xml:"body"` // 商品或支付单简要描述, max 32 Detail string `xml:"detail"` // 商品名称明细列表, 8192 Attach string `xml:"attach"` // 附加数据,在查询API和支付通知中原样返回 OutTradeNo string `xml:"out_trade_no"` // 商户系统内部的订单号, 32个字符内、可包含字母 TotalFee int `xml:"total_fee"` // 订单总金额,单位为分,只能为整数 SpbillCreateIP string `xml:"spbill_create_ip"` // 调用微信支付API的机器IP NotifyURL string `xml:"notify_url"` // 接受扣款结果异步回调通知的url ContractID string `xml:"contract_id"` // 委托代扣协议id OpenID string `xml:"openid"` // OpenID Mobile string `xml:"mobile"` // 手机号 Creid string `xml:"creid"` // 身份证号码 Timestamp int `xml:"timestamp"` // 时间戳, 10位时间戳 } // PapPayApply 委托代扣申请扣款 func PapPayApply(config WePayConfig, order PapPay) (reply WePayReply, err error) { m := make(map[string]interface{}) m["appid"] = order.AppID m["mch_id"] = order.MchID m["nonce_str"] = order.NonceStr m["body"] = order.Body m["detail"] = order.Detail m["attach"] = order.Attach m["out_trade_no"] = order.OutTradeNo m["total_fee"] = order.TotalFee m["spbill_create_ip"] = order.SpbillCreateIP m["notify_url"] = order.NotifyURL m["trade_type"] = `PAP` m["contract_id"] = order.ContractID m["openid"] = order.OpenID m["mobile"] = order.Mobile m["creid"] = order.Creid m["timestamp"] = order.Timestamp var data []byte order.Sign = Sign(m, config.Key) if data, err = xml.Marshal(order); err != nil { return } reply, err = post(WePayHost+WePayURLPapPay, data) return } /* POST 10000098 wxcbda96de0b165486 5K8264ILTKCH16CQ2502SI8ZNMTM67VS C380BEC2BFD727A4B6845133519F3AD6 水电代扣 217752501201407033233368018 888 8.8.8.8 http://yoursite.com/wxpay.html Wx15463511252015071056489715 Return // */