互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

287 lines
16 KiB

package wx
import (
"encoding/xml"
"fmt"
"hudongzhuanjia/utils/define"
)
//var (
// WxCertPath = `./cacert/apiclient_cert.pem`
// WxKeyPath = `./cacert/apiclient_key.pem`
// WxCaPath = `./cacert/rootca.pem`
// Appid = "wx7b0bcf476552c5e9"
// Secret = "f6aabdd40ea25272f4442603a7dc8028"
// Mchid = `1394404502`
// ApiKey = `2c82c64ceec6ba89ffc9f593c671a12f`
// mainHost = `https://api.mch.weixin.qq.com`
// backHost = `https://api2.mch.weixin.qq.com`
//)
var (
RedirectUri = "http://api.hudongzhuanjia.com/"
CodeUrl = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login&state=%s#wechat_redirect"
AccessTokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=%s&secret=%s&code=%s&grant_type=authorization_code "
RefreshTokenUrl = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=%s&grant_type=refresh_token&refresh_token=%s"
AuthUrl = "https://api.weixin.qq.com/sns/auth?access_token=%s&openid=%s"
UserInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s"
TicketTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"
TicketUrl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
Expired = 7200
)
var (
NotifyURL = fmt.Sprintf("%s/wechat/callback", define.HOST) // 微信回调通知
UnifiedOrderURL = fmt.Sprintf("%s/pay/unifiedorder", define.WxHost) // 统一下单url
QueryOrderURL = fmt.Sprintf("%s/pay/orderquery", define.WxHost) // 微信查询订单
CloseOrderURL = fmt.Sprintf("%s/pay/closeorder", define.WxHost) // 微信关闭订单
RefundURL = fmt.Sprintf("%s/secapi/pay/refund", define.WxHost) // 微信退款
RefundQueryURL = fmt.Sprintf("%s/pay/refundquery", define.WxHost) // 微信查询退款
DownloadBillURL = fmt.Sprintf("%s/pay/downloadbill", define.WxHost) // 微信下载账单
DownloadFundFlowURL = fmt.Sprintf("%s/pay/downloadfundflow", define.WxHost)
TransfersURL = fmt.Sprintf("%s/mmpaymkttransfers/promotion/transfers", define.WxHost)
SendRedPackURL = fmt.Sprintf("%s/mmpaymkttransfers/sendredpack", define.WxHost)
QueryRedPackURL = fmt.Sprintf("%s/mmpaymkttransfers/gethbinfo", define.WxHost)
)
type CommonReturn struct {
ReturnCode string `xml:"return_code,omitempty" json:"return_code,omitempty"`
ReturnMsg string `xml:"return_msg,omitempty" json:"return_msg,omitempty"`
}
type CommonResult struct {
ResultCode string `xml:"result_code,omitempty" json:"result_code,omitempty"`
ResultMsg string `xml:"result_msg,omitempty" json:"result_msg,omitempty"`
ErrCode string `xml:"err_code,omitempty" json:"err_code,omitempty"`
ErrCodeDes string `xml:"err_code_des,omitempty" json:"err_code_des,omitempty"`
}
type CommonParam struct {
Appid string `xml:"appid,omitempty" json:"appid,omitempty"`
MchId string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
NonceStr string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
Sign string `xml:"sign,omitempty" json:"sign,omitempty"`
SignType string `xml:"sign_type,omitempty" json:"sign_type,omitempty"`
}
// ========================================== 基础配置
type UnifiedOrderParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
DeviceInfo string `xml:"device_info,omitempty" json:"device_info,omitempty"`
Body cdata `xml:"body,omitempty" json:"body,omitempty"`
Detail cdata `xml:"detail,omitempty" json:"detail,omitempty"`
Attach string `xml:"attach,omitempty" json:"attach,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
FeeType string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
TotalFee string `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
SpbillCreateIp string `xml:"spbill_create_ip,omitempty" json:"spbill_create_ip,omitempty"`
TimeStart string `xml:"time_start,omitempty" json:"time_start,omitempty"`
TimeExpire string `xml:"time_expire,omitempty" json:"time_expire,omitempty"`
GoodsTag string `xml:"goods_tag,omitempty" json:"goods_tag,omitempty"`
NotifyUrl string `xml:"notify_url,omitempty" json:"notify_url,omitempty"`
TradeType string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
ProductId string `xml:"product_id,omitempty" json:"product_id,omitempty"`
LimitPay string `xml:"limit_pay,omitempty" json:"limit_pay,omitempty"`
Openid string `xml:"openid,omitempty" json:"openid,omitempty"`
Receipt string `xml:"receipt,omitempty" json:"receipt,omitempty"`
SceneInfo *UnifiedOrderSceneInfo `xml:"scene_info,omitempty" json:"scene_info,omitempty"`
}
type UnifiedOrderSceneInfo struct {
Id string `xml:"id,omitempty" json:"id,omitempty"`
Name string `xml:"name,omitempty" json:"name,omitempty"`
AreaCode string `xml:"area_code,omitempty" json:"area_code,omitempty"`
Address string `xml:"address,omitempty" json:"address,omitempty"`
}
type UnifiedOrderResult struct {
CommonReturn
CommonResult
CommonParam
DeviceInfo string `xml:"device_info,omitempty" json:"device_info,omitempty"`
NonceStr string `xml:"nonce_str,omitempty" json:"nonce_str,omitempty"`
TradeType string `xml:"trade_type,omitempty" json:"trade_type,omitempty"`
PrepayId string `xml:"prepay_id,omitempty" json:"prepay_id,omitempty"`
CodeUrl string `xml:"code_url,omitempty" json:"code_url,omitempty"`
}
// =================================================支付
type QueryOrderParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
}
type QueryOrderResult struct {
CommonReturn
CommonResult
CommonParam
DeviceInfo string `xml:"device_info" json:"device_info,omitempty"`
Openid string `xml:"openid" json:"openid,omitempty"`
IsSubscribe string `xml:"is_subscribe" json:"is_subscribe,omitempty"`
TradeType string `xml:"trade_type" json:"trade_type,omitempty"`
TradeState string `xml:"trade_state" json:"trade_state,omitempty"`
BankType string `xml:"bank_type" json:"bank_type,omitempty"`
TotalFee string `xml:"total_fee" json:"total_fee,omitempty"`
SettlementTotalFee string `xml:"settlement_total_fee" json:"settlement_total_fee,omitempty"`
FeeType string `xml:"fee_type" json:"fee_type,omitempty"`
CashFee string `xml:"cash_fee" json:"cash_fee,omitempty"`
CashFeeType string `xml:"cash_fee_type" json:"cash_fee_type,omitempty"`
CouponFee string `xml:"coupon_fee" json:"coupon_fee,omitempty"`
CouponCount string `xml:"coupon_count" json:"coupon_count,omitempty"`
CouponTypeN string `xml:"coupon_type_$n" json:"coupon_type_$n,omitempty"`
CouponIdN string `xml:"coupon_id_$n" json:"coupon_id_$n,omitempty"`
CouponFeeN string `xml:"coupon_fee_$n" json:"coupon_fee_$n,omitempty"`
TransactionId string `xml:"transaction_id" json:"transaction_id,omitempty"`
OutTradeNo string `xml:"out_trade_no" json:"out_trade_no,omitempty"`
Attach string `xml:"attach" json:"attach,omitempty"`
TimeEnd string `xml:"time_end" json:"time_end,omitempty"`
TradeStateDesc string `xml:"trade_state_desc" json:"trade_state_desc,omitempty"`
}
// ============================================================查询订单
type CloseOrderParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
}
type CloseOrderResult struct {
CommonReturn
CommonResult
CommonParam
}
// ======================================== 关闭订单
type RefundParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"` // 与订单号二选一
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
OutRefundNo string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
TotalFee string `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
RefundFee string `xml:"refund_fee,omitempty" json:"refund_fee,omitempty"`
RefundFeeType string `xml:"refund_fee_type,omitempty" json:"refund_fee_type,omitempty"`
RefundDesc string `xml:"refund_desc,omitempty" json:"refund_desc,omitempty"`
RefundAccount string `xml:"refund_account,omitempty" json:"refund_account,omitempty"`
NotifyUrl string `xml:"notify_url,omitempty" json:"notify_url,omitempty"`
}
type RefundResult struct {
CommonReturn
CommonResult
CommonParam
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
OutRefundNo string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
RefundId string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
RefundFee int `xml:"refund_fee,omitempty" json:"refund_fee,omitempty"`
SettlementRefundFee int `xml:"settlement_refund_fee,omitempty" json:"settlement_refund_fee,omitempty"`
TotalFee int `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
SettlementTotalFee int `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
FeeType string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
CashFee int `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
CashFeeType string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
CashRefundFee string `xml:"cash_refund_fee,omitempty" json:"cash_refund_fee,omitempty"`
CouponTypeN string `xml:"coupon_type_$n,omitempty" json:"coupon_type_$n,omitempty"`
CouponRefundFee string `xml:"coupon_refund_fee,omitempty" json:"coupon_refund_fee,omitempty"`
CouponRefundFeeN string `xml:"coupon_refund_fee_$n,omitempty" json:"coupon_refund_fee_$n,omitempty"`
CouponRefundCount string `xml:"coupon_refund_count,omitempty" json:"coupon_refund_count,omitempty"`
CouponRefundIdN string `xml:"coupon_refund_id_$n,omitempty" json:"coupon_refund_id_$n,omitempty"`
}
// ===================================================== 退款申请
type RefundQueryParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
OutRefundNo string `xml:"out_refund_no,omitempty" json:"out_refund_no,omitempty"`
RefundId string `xml:"refund_id,omitempty" json:"refund_id,omitempty"`
Offset int `xml:"offset,omitempty" json:"offset,omitempty"`
}
type RefundQueryResult struct {
CommonReturn
CommonResult
CommonParam
TransactionId string `xml:"transaction_id,omitempty" json:"transaction_id,omitempty"`
OutTradeNo string `xml:"out_trade_no,omitempty" json:"out_trade_no,omitempty"`
TotalRefundCount int `xml:"total_refund_count,omitempty" json:"total_refund_count,omitempty"`
TotalFee int `xml:"total_fee,omitempty" json:"total_fee,omitempty"`
FeeType string `xml:"fee_type,omitempty" json:"fee_type,omitempty"`
CashFee int `xml:"cash_fee,omitempty" json:"cash_fee,omitempty"`
CashFeeType string `xml:"cash_fee_type,omitempty" json:"cash_fee_type,omitempty"`
SettlementTotalFee int `xml:"settlement_total_fee,omitempty" json:"settlement_total_fee,omitempty"`
RefundCount int `xml:"refund_count,omitempty" json:"refund_count,omitempty"`
OutRefundNoN string `xml:"out_refund_no_$n,omitempty" json:"out_refund_no_$n,omitempty"`
RefundIdN string `xml:"refund_id_$n,omitempty" json:"refund_id_$n,omitempty"`
RefundChannelN string `xml:"refund_channel_$n,omitempty" json:"refund_channel_$n,omitempty"`
RefundFeeN int `xml:"refund_fee_$n,omitempty" json:"refund_fee_$n,omitempty"`
CouponRefundFeeN int `xml:"coupon_refund_fee_$n,omitempty" json:"coupon_refund_fee_$n,omitempty"`
CouponRefundCountN int `xml:"coupon_refund_count_$n,omitempty" json:"coupon_refund_count_$n,omitempty"`
CouponRefundIdNM string `xml:"coupon_refund_id_$n_$m,omitempty" json:"coupon_refund_id_$n_$m,omitempty"`
CouponTypeNM string `xml:"coupon_type_$n_$m,omitempty" json:"coupon_type_$n_$m,omitempty"`
CouponRefundFeeNM int `xml:"coupon_refund_fee_$n_$m,omitempty" json:"coupon_refund_fee_$n_$m,omitempty"`
RefundStatusN string `xml:"refund_status_$n,omitempty" json:"refund_status_$n,omitempty"`
RefundAccountN string `xml:"refund_account_$n" json:"refund_account_$n,omitempty"`
RefundRecvAccoutN string `xml:"refund_recv_accout_$n,omitempty" json:"refund_recv_accout_$n,omitempty"` // 少了n
RefundSuccessTimeN string `xml:"refund_success_time_$n,omitempty" json:"refund_success_time_$n,omitempty"`
}
// =================================================== 退款查询
type RedPackParam struct {
CommonParam
XMLName xml.Name `xml:"xml" json:"xml_name,omitempty"`
Appid string `xml:"wxappid,omitempty" json:"wxappid,omitempty"` // wxappid
MchBillno string `xml:"mch_billno,omitempty" json:"mch_billno,omitempty"`
SendName string `xml:"send_name,omitempty" json:"send_name,omitempty"`
ReOpenid string `xml:"re_openid,omitempty" json:"re_openid,omitempty"`
TotalAmount int `xml:"total_amount,omitempty" json:"total_amount,omitempty"`
TotalNum int `xml:"total_num,omitempty" json:"total_num,omitempty"`
Wishing string `xml:"wishing,omitempty" json:"wishing,omitempty"`
ClientIp string `xml:"client_ip,omitempty" json:"client_ip,omitempty"`
ActName string `xml:"act_name,omitempty" json:"act_name,omitempty"`
Remark string `xml:"remark,omitempty" json:"remark,omitempty"`
SendId string `xml:"send_id,omitempty" json:"send_id,omitempty"`
RiskInfo string `xml:"risk_info,omitempty" json:"risk_info,omitempty"`
}
type RedPackResult struct {
CommonReturn
CommonResult
MchBillno string `xml:"mch_billno,omitempty" json:"mch_billno,omitempty"`
MchId string `xml:"mch_id,omitempty" json:"mch_id,omitempty"`
Wxappid string `xml:"wxappid,omitempty" json:"wxappid,omitempty"` // wxappid
ReOpenid string `xml:"re_openid,omitempty" json:"re_openid,omitempty"`
TotalAmount int `xml:"total_amount,omitempty" json:"total_amount,omitempty"`
SendListid string `xml:"send_listid,omitempty" json:"send_listid,omitempty"`
}
type QueryRedPackResult struct {
CommonReturn
CommonResult
MchBillno string `xml:"mch_billno,omitempty" json:"mch_billno,omitempty"`
Mchid string `xml:"mchid,omitempty" json:"mchid,omitempty"`
DetailId string `xml:"detail_id,omitempty" json:"detail_id,omitempty"`
Status string `xml:"status,omitempty" json:"status,omitempty"`
SendType string `xml:"send_type,omitempty" json:"send_type,omitempty"`
HbType string `xml:"hb_type,omitempty" json:"hb_type,omitempty"`
TotalNum int `xml:"total_num,omitempty" json:"total_num,omitempty"`
TotalAmount int `xml:"total_amount,omitempty" json:"total_amount,omitempty"`
Reason string `xml:"reason,omitempty" json:"reason,omitempty"`
SendTime string `xml:"send_time,omitempty" json:"send_time,omitempty"`
RefundTime string `xml:"refund_time,omitempty" json:"refund_time,omitempty"`
RefundAmount int `xml:"refund_amount,omitempty" json:"refund_amount,omitempty"`
Wishing string `xml:"wishing,omitempty" json:"wishing,omitempty"`
Remark string `xml:"remark,omitempty" json:"remark,omitempty"`
ActName string `xml:"act_name,omitempty" json:"act_name,omitempty"`
}