|
@@ -4,6 +4,7 @@ import (
|
|
"bytes"
|
|
"bytes"
|
|
"encoding/xml"
|
|
"encoding/xml"
|
|
"errors"
|
|
"errors"
|
|
|
|
+ "fmt"
|
|
|
|
|
|
"git.chuangxin1.com/cx/util"
|
|
"git.chuangxin1.com/cx/util"
|
|
)
|
|
)
|
|
@@ -18,6 +19,8 @@ const (
|
|
WePayURLUnifiedQuery = `/pay/orderquery`
|
|
WePayURLUnifiedQuery = `/pay/orderquery`
|
|
// WePayURLPayRefund pay refund 退款
|
|
// WePayURLPayRefund pay refund 退款
|
|
WePayURLPayRefund = `/secapi/pay/refund`
|
|
WePayURLPayRefund = `/secapi/pay/refund`
|
|
|
|
+ // WePayURLPapPay 委托代扣申请扣款
|
|
|
|
+ WePayURLPapPay = `/pay/pappayapply`
|
|
|
|
|
|
// WePayTradeTypeJS JSAPI 公众号支付
|
|
// WePayTradeTypeJS JSAPI 公众号支付
|
|
WePayTradeTypeJS = `JSAPI`
|
|
WePayTradeTypeJS = `JSAPI`
|
|
@@ -32,13 +35,14 @@ const (
|
|
|
|
|
|
// WePayConfig WeChat pay configure
|
|
// WePayConfig WeChat pay configure
|
|
type WePayConfig struct {
|
|
type WePayConfig struct {
|
|
- AppID string `json:"appid"`
|
|
|
|
- MchID string `json:"mchid"`
|
|
|
|
- Key string `json:"key"`
|
|
|
|
- AppSecret string `json:"appsecret"`
|
|
|
|
- SSLCert string `json:"sslcert"`
|
|
|
|
- SSLKey string `json:"sslkey"`
|
|
|
|
- NotifyURL string `json:"notify_url"`
|
|
|
|
|
|
+ AppID string `json:"appid"`
|
|
|
|
+ MchID string `json:"mchid"`
|
|
|
|
+ Key string `json:"key"`
|
|
|
|
+ AppSecret string `json:"appsecret"`
|
|
|
|
+ SSLCert string `json:"sslcert"`
|
|
|
|
+ SSLKey string `json:"sslkey"`
|
|
|
|
+ ContractID string `json:"contractid"`
|
|
|
|
+ NotifyURL string `json:"notify_url"`
|
|
}
|
|
}
|
|
|
|
|
|
// UnifiedOrder https://api.mch.weixin.qq.com/pay/unifiedorder
|
|
// UnifiedOrder https://api.mch.weixin.qq.com/pay/unifiedorder
|
|
@@ -145,6 +149,7 @@ type FormWePayNotify struct {
|
|
|
|
|
|
TradeType string `form:"trade_type" xml:"trade_type"`
|
|
TradeType string `form:"trade_type" xml:"trade_type"`
|
|
TransactionID string `form:"transaction_id" xml:"transaction_id"`
|
|
TransactionID string `form:"transaction_id" xml:"transaction_id"`
|
|
|
|
+ ContractID string `form:"contract_id" xml:"contract_id"`
|
|
}
|
|
}
|
|
|
|
|
|
// WePayReply pay reply
|
|
// WePayReply pay reply
|
|
@@ -174,6 +179,7 @@ type WePayReply struct {
|
|
TradeState string `xml:"trade_state"`
|
|
TradeState string `xml:"trade_state"`
|
|
TradeStateDesc string `xml:"trade_state_desc"`
|
|
TradeStateDesc string `xml:"trade_state_desc"`
|
|
TransactionID string `xml:"transaction_id"`
|
|
TransactionID string `xml:"transaction_id"`
|
|
|
|
+ ContractID string `form:"contract_id" xml:"contract_id"`
|
|
}
|
|
}
|
|
|
|
|
|
var (
|
|
var (
|
|
@@ -244,8 +250,8 @@ func Pay(config WePayConfig, order UnifiedOrder) (reply WePayReply, err error) {
|
|
m := make(map[string]interface{})
|
|
m := make(map[string]interface{})
|
|
|
|
|
|
m["appid"] = order.AppID
|
|
m["appid"] = order.AppID
|
|
- m["body"] = order.Body
|
|
|
|
m["mch_id"] = order.MchID
|
|
m["mch_id"] = order.MchID
|
|
|
|
+ m["body"] = order.Body
|
|
m["notify_url"] = order.NotifyURL
|
|
m["notify_url"] = order.NotifyURL
|
|
m["trade_type"] = order.TradeType
|
|
m["trade_type"] = order.TradeType
|
|
m["spbill_create_ip"] = order.SpbillCreateIP
|
|
m["spbill_create_ip"] = order.SpbillCreateIP
|
|
@@ -280,9 +286,9 @@ func post(url string, data []byte) (reply WePayReply, err error) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
|
|
- //fmt.Println("************Response************")
|
|
|
|
- //fmt.Println(string(msg.Body))
|
|
|
|
- //fmt.Println("************ResponseEnd************")
|
|
|
|
|
|
+ fmt.Println("************Response************")
|
|
|
|
+ fmt.Println(string(msg.Body))
|
|
|
|
+ fmt.Println("************ResponseEnd************")
|
|
err = xml.Unmarshal(msg.Body, &reply)
|
|
err = xml.Unmarshal(msg.Body, &reply)
|
|
|
|
|
|
return
|
|
return
|