mch

package
v0.0.0-...-78ab787 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 16, 2019 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnterprisePaymentSuccess    = "SUCCESS"
	EnterprisePaymentFailed     = "FAILED"
	EnterprisePaymentProcessing = "PROCESSING"
)
View Source
const (
	ReturnCodeSuccess = "SUCCESS"
	ReturnCodeFail    = "FAIL"
)
View Source
const (
	ResultCodeSuccess = "SUCCESS"
	ResultCodeFail    = "FAIL"
)
View Source
const (
	ErrCodeSYSTEMERROR = "SYSTEMERROR" // 系统异常,请用相同参数重新调用

	ErrCodeORDERPAID     = "ORDERPAID"     // 订单已支付,请当作已支付的正常交易
	ErrCodeORDERCLOSED   = "ORDERCLOSED"   // 订单已关闭
	ErrCodeNOTENOUGH     = "NOTENOUGH"     // 用户帐号余额不足,请用户充值或更换支付卡后再支付
	ErrCodeORDERNOTEXIST = "ORDERNOTEXIST" // 查询系统中不存在此交易订单号

	ErrCodeBIZERR_NEED_RETRY     = "BIZERR_NEED_RETRY"     // 并发情况下业务被拒绝,商户重试即可解决
	ErrCodeERROR                 = "ERROR"                 // 申请退款业务发生错误
	ErrCodeUSER_ACCOUNT_ABNORMAL = "USER_ACCOUNT_ABNORMAL" // 退款请求失败,用户帐号注销
	ErrCodeINVALID_REQ_TOO_MUCH  = "INVALID_REQ_TOO_MUCH"  // 连续错误请求数过多被系统短暂屏蔽,请在1分钟后再来重试
	ErrCodeFREQUENCY_LIMITED     = "FREQUENCY_LIMITED"     // 2个月之前的订单申请退款有频率限制,请降低频率后重试
	ErrCodeREFUNDNOTEXIST        = "REFUNDNOTEXIST"        // 请检查订单号是否有误以及订单状态是否正确,如:未支付、已支付未退款

	ErrCodeNOAUTH                = "NOAUTH" // 商户未开通此接口权限	请商户前往申请此接口权限
	ErrCodeAPPID_NOT_EXIST       = "APPID_NOT_EXIST"
	ErrCodeMCHID_NOT_EXIST       = "MCHID_NOT_EXIST"
	ErrCodeAPPID_MCHID_NOT_MATCH = "APPID_MCHID_NOT_MATCH"
	ErrCodeLACK_PARAMS           = "LACK_PARAMS"
	ErrCodeOUT_TRADE_NO_USED     = "OUT_TRADE_NO_USED" // 商户订单号重复,同一笔交易不能多次提交,请核实商户订单号是否重复提交
	ErrCodeSIGNERROR             = "SIGNERROR"
	ErrCodeXML_FORMAT_ERROR      = "XML_FORMAT_ERROR"
	ErrCodeREQUIRE_POST_METHOD   = "REQUIRE_POST_METHOD"
	ErrCodePOST_DATA_EMPTY       = "POST_DATA_EMPTY"
	ErrCodeNOT_UTF8              = "NOT_UTF8"
	ErrCodeTRADE_OVERDUE         = "TRADE_OVERDUE"         // 订单已经超过可退款的最大期限(支付后一年内可退款)
	ErrCodeINVALID_TRANSACTIONID = "INVALID_TRANSACTIONID" // 检查原交易号是否存在或发起支付交易接口返回失败
	ErrCodePARAM_ERROR           = "PARAM_ERROR"

	ErrCodeNO_AUTH               = "NO_AUTH"               // 没有授权请求此api
	ErrCodeAMOUNT_LIMIT          = "AMOUNT_LIMIT"          // 付款金额不能小于最低限额	每次付款金额必须大于1元
	ErrCodeOPENID_ERROR          = "OPENID_ERROR"          // Openid格式错误或者不属于商家公众账号
	ErrCodeSEND_FAILED           = "SEND_FAILED"           // 付款失败,请换单号重试
	ErrCodeNAME_MISMATCH         = "NAME_MISMATCH"         // 请求参数里填写了需要检验姓名,但是输入了错误的姓名
	ErrCodeFREQ_LIMIT            = "FREQ_LIMIT"            // 接口请求频率超时接口限制
	ErrCodeMONEY_LIMIT           = "MONEY_LIMIT"           // 已经达到今日付款总额上限/已达到付款给此用户额度上限
	ErrCodeV2_ACCOUNT_SIMPLE_BAN = "V2_ACCOUNT_SIMPLE_BAN" // 无法给非实名用户付款
	ErrCodeNOT_FOUND             = "NOT_FOUND"
)
View Source
const (
	SignTypeMD5         = "MD5"
	SignTypeSHA1        = "SHA1"
	SignTypeHMAC_SHA256 = "HMAC-SHA256"
)
View Source
const API_URL = "https://api.mch.weixin.qq.com"

Variables

View Source
var BeijingLocation = time.FixedZone("Asia/Shanghai", 8*60*60)

Functions

func AndroidAppSceneInfo

func AndroidAppSceneInfo(appName, packageName string) string

func DecodeXML

func DecodeXML(r io.Reader) (m map[string]string, err error)

DecodeXML decodes xml from io.Reader and returns the first-level sub-node key-value set. If the first-level sub-node contains child nodes, skip it.

func EncodeXML

func EncodeXML(w io.Writer, m map[string]string) (err error)

EncodeXML encodes map[string]string to io.Writer with xml format.

func FormatTime

func FormatTime(t time.Time) string

FormatTime 将参数 t 格式化成北京时间 yyyyMMddHHmmss 字符串.

func H5SceneInfo

func H5SceneInfo(wapName, wapURL string) string

func IOSAppSceneInfo

func IOSAppSceneInfo(appName, bundleID string) string

func JSAPISign

func JSAPISign(appId, timeStamp, nonceStr, packageStr, signType string, apiKey string) string

func ParseTime

func ParseTime(value string) (time.Time, error)

ParseTime 将北京时间 yyyyMMddHHmmss 字符串解析到 time.Time.

func RandString

func RandString(length int) string

func SceneInfo

func SceneInfo(shopID, shopName, shopAreaCode, shopAddress string) string

func Sign

func Sign(params map[string]string, apiKey string, h hash.Hash) string

Types

type BillType

type BillType string
const (
	BillTypeALL             BillType = "ALL"             // 返回当日所有订单信息,默认值
	BillTypeSUCCESS         BillType = "SUCCESS"         // 返回当日成功支付的订单
	BillTypeREFUND          BillType = "REFUND"          // 返回当日退款订单
	BillTypeRECHARGE_REFUND BillType = "RECHARGE_REFUND" // 返回当日充值退款订单(相比其他对账单多一栏“返还手续费”)
)

type BizError

type BizError struct {
	ResultCode  string
	ErrCode     string
	ErrCodeDesc string
}

func (*BizError) Error

func (e *BizError) Error() string

type Client

type Client struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

func New

func New(appID, mchID, apiKey string, timeout ...time.Duration) *Client

func NewWithSubMch

func NewWithSubMch(appID, mchID, apiKey, subAppID, subMchID string, timeout ...time.Duration) *Client

func (*Client) CloseOrder

func (client *Client) CloseOrder(req *CloseOrderRequest) (err error)

以下情况需要调用关单接口: 商户订单支付失败需要生成新单号重新发起支付,要对原订单号调用关单,避免重复支付; 系统下单后,用户支付超时,系统退出不再受理,避免用户继续,请调用关单接口。

func (*Client) DownloadBill

func (client *Client) DownloadBill(req *DownloadBillRequest, filename string) (err error)

func (*Client) DownloadBillToWriter

func (client *Client) DownloadBillToWriter(req *DownloadBillRequest, writer io.Writer) error

func (*Client) EnterprisePay

func (client *Client) EnterprisePay(req *EnterprisePayRequst) (*EnterprisePayResponse, error)

func (*Client) MakeJSAPIArgs

func (client *Client) MakeJSAPIArgs(prepayID string) map[string]string

func (*Client) PostXML

func (client *Client) PostXML(relativeURL string, req map[string]string) (rep map[string]string, err error)

func (*Client) PostXMLWithCert

func (client *Client) PostXMLWithCert(relativeURL string, req map[string]string) (rep map[string]string, err error)

func (*Client) QueryEnterprisePayment

func (client *Client) QueryEnterprisePayment(outTradeNo string) (*QueryEnterprisePaymentResponse, error)

func (*Client) QueryOrder

func (client *Client) QueryOrder(req *QueryOrderRequest) (rep *QueryOrderResponse, err error)

func (*Client) QueryRefund

func (client *Client) QueryRefund(req *QueryRefundRequest) (rep *QueryRefundResponse, err error)

func (*Client) Refund

func (client *Client) Refund(req *RefundRequest) (rep *RefundResponse, err error)

func (*Client) SetCert

func (client *Client) SetCert(certPEMBlock, keyPEMBlock []byte) error

func (*Client) SetCertFromFile

func (client *Client) SetCertFromFile(certFile, keyFile string) error

func (*Client) SetSignType

func (client *Client) SetSignType(signType string) error

func (*Client) UnifiedOrder

func (client *Client) UnifiedOrder(req *UnifiedOrderRequest) (rep *UnifiedOrderResponse, err error)

type CloseOrderRequest

type CloseOrderRequest struct {
	OutTradeNo string `xml:"out_trade_no"` // 商户系统内部订单号
}

type DownloadBillRequest

type DownloadBillRequest struct {
	// 必选参数
	BillDate string   // 下载对账单的日期,格式:20140603
	BillType BillType // 账单类型

	// 可选参数
	DeviceInfo string // 微信支付分配的终端设备号,填写此字段,只下载该设备号的对账单
	TarType    bool   // 是否压缩账单
}

type EnterprisePayRequst

type EnterprisePayRequst struct {
	// 必选参数
	OutTradeNo  string // 商户订单号,需保持唯一性(只能是字母或者数字,不能包含有符号)
	Amount      int    // 企业付款金额,单位为分
	Desc        string // 企业付款操作说明信息
	FromIP      string // 调用接口的机器Ip地址
	OpenID      string // 商户appid下,某用户的openid
	IsCheckName bool   // 是否校验真实姓名

	// 可选参数
	UserName   string // 收款用户真实姓名,如果check_name设置为FORCE_CHECK,则必填用户真实姓名
	DeviceInfo string // 微信支付分配的终端设备号
}

type EnterprisePayResponse

type EnterprisePayResponse struct {
	PaymentNo   string // 企业付款成功,返回的微信订单号
	PaymentTime string // 企业付款成功时间
	OutTradeNo  string // 商户订单号
	DeviceInfo  string // 调用接口提交的终端设备号
}

type Error

type Error struct {
	ReturnCode string
	ReturnMsg  string
}

func (*Error) Error

func (e *Error) Error() string

type NotifyHandler

type NotifyHandler struct {
	*zap.SugaredLogger
	// contains filtered or unexported fields
}

func NewNotifyHandler

func NewNotifyHandler(appID, mchID, apiKey string, payNofityHandler func(*NotifyMsg) error, refundNotifyHandler func(*RefundNotifyMsg) error) *NotifyHandler

func (*NotifyHandler) Serve

func (nm *NotifyHandler) Serve(w io.Writer, r *http.Request, payNotifyHandler func(*NotifyMsg) error, refundNotifyHandler func(*RefundNotifyMsg) error)

func (*NotifyHandler) ServeHTTP

func (nm *NotifyHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type NotifyMsg

type NotifyMsg struct {
	AppID    string
	MchID    string
	SubAppID string
	SubMchID string

	OrderInfo
}

type OrderInfo

type OrderInfo struct {
	DeviceInfo     string // 终端设备号
	OpenID         string // 用户在商户appid下的唯一标识
	IsSubscribe    bool   // 用户是否关注公众账号,仅在公众账号类型支付有效
	SubOpenID      string // 用户在子商户appid下的唯一标识
	SubIsSubscribe bool   // 用户是否关注子公众账号,仅在公众账号类型支付有效

	TradeType string
	BankType  string // 银行类型,采用字符串类型的银行标识

	TotalFee           int    // 订单总金额,单位为分
	FeeType            string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFee            int    // 订单现金支付金额,单位为分
	CashFeeType        string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	SettlementTotalFee int    // 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额
	CouponFee          int    // 代金券或立减优惠金额<=订单总金额,订单总金额-代金券或立减优惠金额=现金支付金额
	CouponCount        int    // 代金券或立减优惠使用数量

	TransactionID string    // 微信支付订单号
	OutTradeNo    string    // 商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一
	Attach        string    // 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
	TimeEnd       time.Time // 支付完成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010
}

type QueryEnterprisePaymentResponse

type QueryEnterprisePaymentResponse struct {
	Status      string // 转账状态
	Reason      string // 如果失败则有失败原因
	PaymentNo   string // 微信订单号
	Amount      int    // 付款金额单位分
	Desc        string // 付款时候的描述
	PaymentTime string // 发起转账的时间
	OpenID      string // 商户appid下用户的openid
	UserName    string // 收款用户真实姓名
}

type QueryOrderRequest

type QueryOrderRequest struct {
	TransactionID string // 微信的订单号,优先使用
	OutTradeNo    string // 商户系统内部的订单号,当没提供transaction_id时需要传这个
}

type QueryOrderResponse

type QueryOrderResponse struct {
	TradeState            // 交易状态
	TradeStateDesc string // 对当前查询订单状态的描述和下一步操作的指引

	OrderInfo

	Detail string // TODO: 商品详细列表
}

type QueryRefundRequest

type QueryRefundRequest struct {
	// 必选参数, 四选一
	TransactionId string // 微信订单号
	OutTradeNo    string // 商户订单号
	OutRefundNo   string // 商户退款单号
	RefundId      string // 微信退款单号
}

type QueryRefundResponse

type QueryRefundResponse struct {
	// 必选返回
	TransactionId string // 微信订单号
	OutTradeNo    string // 商户系统内部的订单号

	RefundItems []RefundItem

	// 可选返回
	TotalFee           int    // 订单总金额,单位为分,只能为整数
	CashFee            int    // 现金支付金额,单位为分,只能为整数
	SettlementTotalFee int    // 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额
	FeeType            string // 订单金额货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFeeType        string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
}

type RefundItem

type RefundItem struct {
	OutRefundNo  string       // 商户退款单号
	RefundId     string       // 微信退款单号
	RefundFee    int          // 申请退款金额
	RefundStatus RefundStatus // 退款状态

	// 可选返回
	RefundChannel       string    // 退款渠道
	SettlementRefundFee int       // 退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	RefundAccount       string    // 退款资金来源
	RefundRecvAccout    string    // 退款入账账户
	RefundSuccessTime   time.Time // 退款成功时间

}

type RefundNotifyMsg

type RefundNotifyMsg struct {
	TransactionID string
	OutTradeNO    string
	RefundID      string
	OutRefundNO   string
	TotalFee      int
	RefundFee     int
	RefundStatus  RefundStatus
	SuccessTime   time.Time
}

type RefundRequest

type RefundRequest struct {
	// TransactionId 和 OutTradeNo 二选一即可
	TransactionId string // 微信生成的订单号,在支付通知中有返回
	OutTradeNo    string // 商户侧传给微信的订单号

	// 必选参数
	OutRefundNo string // 商户系统内部的退款单号,商户系统内部唯一,同一退款单号多次请求只退一笔
	TotalFee    int    // 订单总金额,单位为分,只能为整数
	RefundFee   int    // 退款总金额,单位为分,只能为整数

	// 可选参数
	RefundFeeType string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	RefundDesc    string // 若商户传入,会在下发给用户的退款消息中体现退款原因
}

type RefundResponse

type RefundResponse struct {
	// 必选返回
	TransactionId string // 微信订单号
	OutTradeNo    string // 商户系统内部的订单号
	OutRefundNo   string // 商户退款单号
	RefundId      string // 微信退款单号

	RefundFee int // 退款总金额,单位为分,可以做部分退款
	TotalFee  int // 订单总金额,单位为分,只能为整数
	CashFee   int // 现金支付金额,单位为分,只能为整数

	// 可选返回
	SettlementRefundFee int    // 退款金额=申请退款金额-非充值代金券退款金额,退款金额<=申请退款金额
	SettlementTotalFee  int    // 应结订单金额=订单金额-非充值代金券金额,应结订单金额<=订单金额
	FeeType             string // 订单金额货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashFeeType         string // 货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY
	CashRefundFee       int    // 现金退款金额,单位为分,只能为整数
	CouponRefundFee     int    // 代金券退款金额<=退款金额,退款金额-代金券或立减优惠退款金额为现金
	CouponRefundCount   int    // 退款代金券使用数量

}

type RefundStatus

type RefundStatus string
const (
	RefundStatusSUCCESS     RefundStatus = "SUCCESS"     // 退款成功
	RefundStatusREFUNDCLOSE RefundStatus = "REFUNDCLOSE" // 退款关闭
	RefundStatusPROCESSING  RefundStatus = "PROCESSING"  // 退款处理中
	RefundStatusCHANGE      RefundStatus = "CHANGE"      // 退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往商户平台交易中心,手动处理此笔退款
)

type TradeState

type TradeState string
const (
	TradeStateSUCCESS    TradeState = "SUCCESS"    // 支付成功
	TradeStateREFUND     TradeState = "REFUND"     // 转入退款
	TradeStateNOTPAY     TradeState = "NOTPAY"     // 未支付
	TradeStateCLOSED     TradeState = "CLOSED"     // 已关闭
	TradeStateREVOKED    TradeState = "REVOKED"    // 已撤销(刷卡支付)
	TradeStateUSERPAYING TradeState = "USERPAYING" // 用户支付中
	TradeStatePAYERROR   TradeState = "PAYERROR"   // 支付失败(其他原因,如银行返回失败)
)

type TradeType

type TradeType string
const (
	TradeTypeMWEB     TradeType = "MWEB"     // H5支付
	TradeTypeJSAPI    TradeType = "JSAPI"    // 公众号支付/小程序支付
	TradeTypeAPP      TradeType = "APP"      // APP支付
	TradeTypeNATIVE   TradeType = "NATIVE"   // 原生扫码支付
	TradeTypeMICROPAY TradeType = "MICROPAY" // 刷卡支付
)

type UnifiedOrderRequest

type UnifiedOrderRequest struct {
	// 必选参数
	Body           string    // 商品或支付单简要描述
	OutTradeNo     string    // 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
	TotalFee       int       // 订单总金额,单位为分,详见支付金额
	SpbillCreateIP string    // APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
	NotifyURL      string    // 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
	TradeType      TradeType // 取值如下:JSAPI,NATIVE,APP,详细说明见参数规定

	// 可选参数
	DeviceInfo string    // 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB"
	Detail     string    // 商品名称明细列表
	Attach     string    // 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
	FeeType    string    // 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
	TimeStart  time.Time // 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
	TimeExpire time.Time // 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
	GoodsTag   string    // 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
	ProductId  string    // trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
	LimitPay   string    // no_credit--指定不能使用信用卡支付
	OpenId     string    // rade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。
	SubOpenId  string    // trade_type=JSAPI,此参数必传,用户在子商户appid下的唯一标识。openid和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid。
	SceneInfo  string    // 该字段用于上报支付的场景信息,针对H5支付有以下三种场景,请根据对应场景上报,H5支付不建议在APP端使用,针对场景1,2请接入APP支付,不然可能会出现兼容性问题
}

type UnifiedOrderResponse

type UnifiedOrderResponse struct {
	PrepayId  string // 微信生成的预支付回话标识,用于后续接口调用中使用,该值有效期为2小时
	TradeType string // 调用接口提交的交易类型,取值如下:JSAPI,NATIVE,APP,详细说明见参数规定

	// 下面字段都是可选返回的(详细见微信支付文档), 为空值表示没有返回, 程序逻辑里需要判断
	DeviceInfo string // 调用接口提交的终端设备号
	CodeURL    string // trade_type 为 NATIVE 时有返回,可将该参数值生成二维码展示出来进行扫码支付
	MWebURL    string // trade_type 为 MWEB 时有返回
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL