core

package
v0.0.0-...-3b54ddd Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2019 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WAIT_BUYER_PAY  = "WAIT_BUYER_PAY"
	TRADE_CLOSED    = "TRADE_CLOSED"
	TRADE_SUCCESS   = "TRADE_SUCCESS"
	TRADE_FINISHED  = "TRADE_FINISHED"
	REFUND_SUCCESS  = "REFUND_SUCCESS"
	REFUND_CLOSED   = "REFUND_CLOSED"
	TRADE_NOT_EXIST = "TRADE_NOT_EXIST"
)

TradeStatus

View Source
const (
	TRADE_TYPE_JSAPI  = "JSAPI"
	TRADE_TYPE_NATIVE = "NATIVE"
	TRADE_TYPE_APP    = "APP"
)

支付类型

View Source
const (
	NO_CHECK     = "NO_CHECK"     //不校验真实姓名
	FORCE_CHECK  = "FORCE_CHECK"  //强制校验
	OPTION_CHECK = "OPTION_CHECK" //有则校验
)

转账校验

View Source
const (
	FAIL       = "FAIL"
	NOTPAY     = "NOTPAY"
	SUCCESS    = "SUCCESS"
	USERPAYING = "USERPAYING"
)

返回字符串

View Source
const (
	//公众号
	WX_API_HOST = "https://api.weixin.qq.com"
	//支付
	WX_PAY_HOST = "https://api.mch.weixin.qq.com"
)

主机地址

View Source
const (
	WX_BASE_SCOPE = "snsapi_base"     //只能获得openid,不需要用户确认
	WX_INFO_SCOPE = "snsapi_userinfo" //需要用户确认,能够获得用户信息
)

应用授权作用域

View Source
const (
	MSG_TEXT  = "text"
	MSG_IMAGE = "image"
	MSG_NEW   = "news"
)

发送消息

View Source
const (
	BbnResponse_Success = "SUCCESS"
)
View Source
const (
	//如果异步订单处理成功返回
	DO_SUCCESS = "success"
)

Variables

View Source
var (
	AP_PAY_CONFIG       APKeyConfig     = APKeyConfig{}
	PARTNET_PRIVATE_KEY *rsa.PrivateKey = nil
	ALIPAY_PUBLIC_KEY   *rsa.PublicKey  = nil
)
View Source
var (
	NET_ERROR            = errors.New("net error")
	DATA_UNMARSHAL_ERROR = errors.New("data unmarshal error")
)
View Source
var (
	UNION_CONFIG      UnionKeyConfig  = UnionKeyConfig{}
	UNION_MCH_PRIVATE *rsa.PrivateKey = nil
	UNION_MCH_PUBLIC  *rsa.PublicKey  = nil
	UNION_PUBLIC_KEY  *rsa.PublicKey  = nil
)

Functions

func APMD5Sign

func APMD5Sign(v interface{}) string

func APParseSignFields

func APParseSignFields(src interface{}) xweb.HTTPValues

func APRSAVerify

func APRSAVerify(src string, sign string) error

校验来自阿里的数据

func APSHA1Sign

func APSHA1Sign(v interface{}) string

func InitAPKey

func InitAPKey(conf APKeyConfig)

func InitUnionKey

func InitUnionKey(conf UnionKeyConfig)

func RandStr

func RandStr() string

获得随机字符串

func TimeNow

func TimeNow() int64

获得当前时间戳

func TimeNowString

func TimeNowString() string

获得当前时间戳

func TimeString

func TimeString(d int64) string

func UnionParseFields

func UnionParseFields(src interface{}, isSign bool) xweb.HTTPValues

func UnionParseQuery

func UnionParseQuery(query string) (m url.Values, err error)

func UnionRSAVerify

func UnionRSAVerify(src string, sign string) error

校验来自银联的数据

func UnionSHA1Sign

func UnionSHA1Sign(v interface{}) string

func UnionSHA1SignValues

func UnionSHA1SignValues(http xweb.HTTPValues) string

func WXParseSignFields

func WXParseSignFields(src interface{}) xweb.HTTPValues

Types

type APKeyConfig

type APKeyConfig struct {
	PARTNER_ID          string //商户id
	SELLER_EMAIL        string //商户支付email
	SIGN_TYPE           string //签名类型 RSA
	ALIPAY_KEY          string //阿里支付密钥
	PARTNET_PRIVATE_KEY string //商户私钥
	ALIPAY_PUBLIC_KEY   string //阿里支付公钥
}

alipay

type APPayQueryOrder

type APPayQueryOrder struct {
	Service      string `json:"service" sign:"true"`
	Partner      string `json:"partner" sign:"true"`
	InputCharset string `json:"_input_charset" sign:"true"`
	OutTradeNo   string `json:"out_trade_no" sign:"true"`
}

https://mapi.alipay.com/gateway.do? _input_charset=utf-8&out_trade_no=1201604242253410295&partner=2088121797205248& service=single_trade_query&sign=283e436499a7fbfe5e6bccdf72946ec5&sign_type=md5

func (APPayQueryOrder) Get

<alipay>

<is_success>T</is_success>
<request>
	<param name="_input_charset">utf-8</param>
	<param name="service">single_trade_query</param>
	<param name="partner">2088121797205248</param>
	<param name="out_trade_no">1201604242253410295</param>
</request>
<response>
	<trade>
		<body>订单支付</body>
		<buyer_email>cxuhua@gmail.com</buyer_email>
		<buyer_id>2088002003565555</buyer_id>
		<discount>0.00</discount>
		<flag_trade_locked>0</flag_trade_locked>
		<gmt_create>2016-04-24 22:54:05</gmt_create>
		<gmt_last_modified_time>2016-04-24 22:54:06</gmt_last_modified_time>
		<gmt_payment>2016-04-24 22:54:06</gmt_payment>
		<is_total_fee_adjust>F</is_total_fee_adjust>
		<operator_role>B</operator_role>
		<out_trade_no>1201604242253410295</out_trade_no>
		<payment_type>1</payment_type>
		<price>2.12</price>
		<quantity>1</quantity>
		<seller_email>57730141@qq.com</seller_email>
		<seller_id>2088121797205248</seller_id>
		<subject>订单支付</subject>
		<time_out>2016-07-24 22:54:06</time_out>
		<time_out_type>finishFPAction</time_out_type>
		<to_buyer_fee>0.00</to_buyer_fee>
		<to_seller_fee>2.12</to_seller_fee>
		<total_fee>2.12</total_fee>
		<trade_no>2016042421001004550217245009</trade_no>
		<trade_status>TRADE_SUCCESS</trade_status>
		<use_coupon>F</use_coupon>
	</trade>
</response>
<sign>ecc83e462668b8a7bc695e24249e2db6</sign>
<sign_type>MD5</sign_type>

</alipay>

type APPayQueryOrderResponse

type APPayQueryOrderResponse struct {
	XMLName      struct{} `xml:"alipay" sign:"false"`
	IsSuccess    string   `xml:"is_success" sign:"false"`
	Body         string   `xml:"response>trade>body" sign:"true"`
	BuyerEmail   string   `xml:"response>trade>buyer_email" sign:"true"`
	BuyerId      string   `xml:"response>trade>buyer_id" sign:"true"`
	Discount     string   `xml:"response>trade>discount" sign:"true"`
	Locked       string   `xml:"response>trade>flag_trade_locked" sign:"true"`
	GMTCreate    string   `xml:"response>trade>gmt_create" sign:"true"`
	GMTLast      string   `xml:"response>trade>gmt_last_modified_time" sign:"true"`
	GMTPayment   string   `xml:"response>trade>gmt_payment" sign:"true"`
	IsTotalFee   string   `xml:"response>trade>is_total_fee_adjust" sign:"true"`
	OperatorRole string   `xml:"response>trade>operator_role" sign:"true"`
	OutTradeNo   string   `xml:"response>trade>out_trade_no" sign:"true"`
	PaymentType  string   `xml:"response>trade>payment_type" sign:"true"`
	Price        string   `xml:"response>trade>price" sign:"true"`
	Quantity     string   `xml:"response>trade>quantity" sign:"true"`
	SellerEmail  string   `xml:"response>trade>seller_email" sign:"true"`
	SellerId     string   `xml:"response>trade>seller_id" sign:"true"`
	Subject      string   `xml:"response>trade>subject" sign:"true"`
	Timeout      string   `xml:"response>trade>time_out" sign:"true"`
	TimeoutType  string   `xml:"response>trade>time_out_type" sign:"true"`
	ToBuyerFee   string   `xml:"response>trade>to_buyer_fee" sign:"true"`
	ToSellerFee  string   `xml:"response>trade>to_seller_fee" sign:"true"`
	TotalFee     string   `xml:"response>trade>total_fee" sign:"true"`
	TradeNo      string   `xml:"response>trade>trade_no" sign:"true"`
	TradeStatus  string   `xml:"response>trade>trade_status" sign:"true"`
	UseCoupon    string   `xml:"response>trade>use_coupon" sign:"true"`
	Sign         string   `xml:"sign" sign:"false"`
	SignType     string   `xml:"sign_type" sign:"false"`
	Error        string   `xml:"error" sign:"false"`
}

func (APPayQueryOrderResponse) IsPaySuccess

func (this APPayQueryOrderResponse) IsPaySuccess() bool

type APPayReqForApp

type APPayReqForApp struct {
	Service      string `json:"service,omitempty" sign:"true"`
	Partner      string `json:"partner,omitempty" sign:"true"`
	InputCharset string `json:"_input_charset,omitempty" sign:"true"`
	SignType     string `json:"sign_type,omitempty" sign:"false"`
	Sign         string `json:"sign,omitempty" sign:"false"`
	NotifyURL    string `json:"notify_url,omitempty" sign:"true"`
	OutTradeNO   string `json:"out_trade_no,omitempty" sign:"true"`
	Subject      string `json:"subject,omitempty" sign:"true"`
	PaymentType  string `json:"payment_type,omitempty" sign:"true"`
	SellerId     string `json:"seller_id,omitempty" sign:"true"`
	TotalFee     string `json:"total_fee,omitempty" sign:"true"`
	Body         string `json:"body,omitempty" sign:"true"`
}

阿里支付请求参数

func NewAPPayReqForApp

func NewAPPayReqForApp() APPayReqForApp

func (APPayReqForApp) String

func (this APPayReqForApp) String() string

type APPayResultNotifyArgs

type APPayResultNotifyArgs struct {
	NotifyTime   string `form:"notify_time" sign:"true"`
	NotifyType   string `form:"notify_type" sign:"true"`
	NotifyId     string `form:"notify_id" sign:"true"`
	SignType     string `form:"sign_type" sign:"false"` //RSA
	Sign         string `form:"sign" sign:"false"`
	OutTradeNO   string `form:"out_trade_no" sign:"true"`
	Subject      string `form:"subject" sign:"true"`
	PaymentType  string `form:"payment_type" sign:"true"` //1
	TradeNO      string `form:"trade_no" sign:"true"`
	TradeStatus  string `form:"trade_status" sign:"true"`
	SellerId     string `form:"seller_id" sign:"true"`
	SellerEmail  string `form:"seller_email" sign:"true"`
	BuyerId      string `form:"buyer_id" sign:"true"`
	BuyerEmail   string `form:"buyer_email" sign:"true"`
	TotalFee     string `form:"total_fee" sign:"true"`
	Quantity     string `form:"quantity" sign:"true"`
	Price        string `form:"price" sign:"true"`
	Body         string `form:"body" sign:"true"`
	GMTCreate    string `form:"gmt_create" sign:"true"`
	GMTPayment   string `form:"gmt_payment" sign:"true"`
	FeeAdjust    string `form:"is_total_fee_adjust" sign:"true"`
	UseCoupon    string `form:"use_coupon" sign:"true"`
	Discount     string `form:"discount" sign:"true"`
	RefundStatus string `form:"refund_status" sign:"true"`
	GMTRefund    string `form:"gmt_refund" sign:"true"`
	GMTClose     string `form:"gmt_close" sign:"true"`
}

支付宝服务器异步通知参数说明

func NewAPPayResultNotifyArgs

func NewAPPayResultNotifyArgs(request []byte) (APPayResultNotifyArgs, error)

func (APPayResultNotifyArgs) GetTotalFee

func (this APPayResultNotifyArgs) GetTotalFee() float32

func (APPayResultNotifyArgs) IsError

func (this APPayResultNotifyArgs) IsError() error

func (APPayResultNotifyArgs) IsFromAlipay

func (this APPayResultNotifyArgs) IsFromAlipay() bool

是否来自支付宝

func (APPayResultNotifyArgs) IsSuccess

func (this APPayResultNotifyArgs) IsSuccess() bool

func (APPayResultNotifyArgs) IsValid

func (this APPayResultNotifyArgs) IsValid() bool

签名校验

func (APPayResultNotifyArgs) String

func (this APPayResultNotifyArgs) String() string

type BbnPay

type BbnPay struct {
	BbnPayConfig
}

H5网页收银台 第三方支付

func NewBbnPay

func NewBbnPay(config BbnPayConfig) *BbnPay

func (*BbnPay) Notify

func (p *BbnPay) Notify(data, sign string) (resp BbnPayNotify, err error)

func (*BbnPay) PlaceOrder

func (p *BbnPay) PlaceOrder(i *BbnPayPlaceOrder) (transId string, err error)

下单

type BbnPayConfig

type BbnPayConfig struct {
	AppId, Key string
}

type BbnPayNotify

type BbnPayNotify struct {
	Appid      string `json:"appid,omitempty"`
	Goodsid    string `json:"goodsid,omitempty"`
	TransType  int8   `json:"transtype,omitempty"`    // 交易类型:0–支付交易;
	Cporderid  string `json:"cporderid,omitempty"`    // 商户订单号
	Transid    string `json:"transid,omitempty"`      // 交易流水号
	Pcuserid   string `json:"pcuserid,omitempty"`     // 用户在商户应用 的唯一标识
	Feetype    int8   `json:"feetype,omitempty"`      // 计费方式
	Money      int    `json:"money,omitempty"`        // 本次交易的金额(请务必严格校验商品金额与交易的金额是否一致)
	FactMoney  int    `json:"fact_money,omitempty"`   // 实际付款金额
	Result     int    `json:"result,omitempty"`       // 交易结果: 1–支付成功 2–支付失败
	Paytype    string `json:"paytype,omitempty"`      // 支付方式
	Currency   string `json:"currency,omitempty"`     // 货币类型
	Transtime  string `json:"transtime,omitempty"`    // 交易完成时间
	PcPrivInfo string `json:"pc_priv_info,omitempty"` // 商户私有信息
	// contains filtered or unexported fields
}

func (BbnPayNotify) IsError

func (p BbnPayNotify) IsError() error

type BbnPayPlaceOrder

type BbnPayPlaceOrder struct {
	AppId     string `json:"appid"`
	GoodsId   int    `json:"goodsid"`   // 应用中的商品编号
	PcorderId string `json:"pcorderid"` // 商户生成的订单号,需要保证系统唯一
	Money     int    `json:"money"`     // 支付金额
	Currency  string `json:"currency"`  // 货币类型以及单位: CHY – 人民币(单位:分)
	PcuserId  string `json:"pcuserid"`  // 用户在商户应用的唯一标识,建议为用户帐号。
	NotifyUrl string `json:"notifyurl"` // 商户服务端接收支付结果通知的地址
	GoodsName string `json:"goodsname"`
}

type CustomMsg

type CustomMsg struct {
	ToUser  string        `json:"touser"`
	MsgType string        `json:"msgtype"`
	Text    CustomMsgText `json:"text"`
}

func (CustomMsg) ToReader

func (this CustomMsg) ToReader() (io.Reader, error)

type CustomMsgText

type CustomMsgText struct {
	Content string `json:"content"`
}

type EncryptedInfo

type EncryptedInfo struct {
	OpenId    string `json:"openId"`
	UnionId   string `json:"unionId"`
	NickName  string `json:"nickName"`
	Gender    int    `json:"gender"`
	Language  string `json:"language"`
	City      string `json:"city"`
	Province  string `json:"province"`
	Country   string `json:"country"`
	AvatarUrl string `json:"avatarUrl"`
}

func WXAppDecodeEncryptedData

func WXAppDecodeEncryptedData(skey string, siv string, sdata string) (EncryptedInfo, error)

解密用户信息

type PayNotify

type PayNotify struct {
	xweb.XMLArgs  `xml:"-"`
	XMLName       struct{} `xml:"xml"` //root node name
	AppId         string   `xml:"appid" sign:"true"`
	Attach        string   `xml:"attach" sign:"true"`
	BankType      string   `xml:"bank_type" sign:"true"`
	CashFee       string   `xml:"cash_fee" sign:"true"`
	CashFeeType   string   `xml:"cash_fee_type" sign:"true"`
	CouponCount   string   `xml:"coupon_count" sign:"true"`
	CouponFee     string   `xml:"coupon_fee" sign:"true"`
	DeviceInfo    string   `xml:"device_info" sign:"true"`
	ErrCode       string   `xml:"err_code" sign:"true"`
	ErrCodeDes    string   `xml:"err_code_des" sign:"true"`
	FeeType       string   `xml:"fee_type" sign:"true"`
	IsSubScribe   string   `xml:"is_subscribe" sign:"true"` //Y or N
	MchId         string   `xml:"mch_id" sign:"true"`
	NonceStr      string   `xml:"nonce_str" sign:"true"`
	OpenId        string   `xml:"openid" sign:"true"`
	OutTradeNo    string   `xml:"out_trade_no" sign:"true"`
	ResultCode    string   `xml:"result_code" sign:"true"` //SUCCESS or FAIL
	ReturnCode    string   `xml:"return_code" sign:"true"` //SUCCESS or FAIL
	ReturnMsg     string   `xml:"return_msg" sign:"true"`  //返回信息,如非空,为错误原因
	Sign          string   `xml:"sign" sign:"false"`       //sign=false表示不参与签名
	TimeEnd       string   `xml:"time_end" sign:"true"`
	TotalFee      string   `xml:"total_fee" sign:"true"`
	TradeType     string   `xml:"trade_type" sign:"true"` //JSAPI、NATIVE、APP
	TransactionId string   `xml:"transaction_id" sign:"true"`
	// contains filtered or unexported fields
}

支付结果通用通知 微信服务器将会根据统一下单的NotifyURL POST以下数据到商机服务器处理

func (PayNotify) IsError

func (r PayNotify) IsError() error

nil表示没有错误

func (PayNotify) SignValid

func (r PayNotify) SignValid() bool

签名校验

type UnionConsumeRequest

type UnionConsumeRequest struct {
	//基本字段
	Version     string `form:"version" sign:"true"`     //版本号固定填写5.0.0
	Encoding    string `form:"encoding" sign:"true"`    //编码方式	支持UTF-8与GBK
	CertId      string `form:"certId" sign:"true"`      //证书ID,填写签名私钥证书的Serial Number
	SignMethod  string `form:"signMethod" sign:"true"`  //01:表示采用RSA	固定填写01
	Signature   string `form:"signature" sign:"false"`  //签名
	TxnType     string `form:"txnType" sign:"true"`     //交易类型 01:消费 固定填写01
	TxnSubType  string `form:"txnSubType" sign:"true"`  //交易子类		固定填写01
	BizType     string `form:"bizType" sign:"true"`     //8	产品类型 固定填写000201
	ChannelType string `form:"channelType" sign:"true"` //9	渠道类型	固定填写08
	//商户信息
	AccessType string `form:"accessType" sign:"true"` //固定填写0
	MerId      string `form:"merId" sign:"true"`      //商户ID
	BackUrl    string `form:"backUrl" sign:"true"`    //通知url
	//订单信息
	OrderId      string `form:"orderId" sign:"true"`      //商户订单号,仅能用大小写字母与数字,不能用特殊字符
	CurrencyCode string `form:"currencyCode" sign:"true"` // 固定156
	TxnAmt       string `form:"txnAmt" sign:"true"`       //单位为分,不能带小数点例:1元填写100
	TxnTime      string `form:"txnTime" sign:"true"`      //YYYYMMDDHHmmss	,样例:20151123152540,北京时间	取当前时间,例:20151118100505
	PayTimeout   string `form:"payTimeout" sign:"true"`   //YYYYMMDDHHmmss
	AccNo        string `form:"accNo" sign:"true"`        //银行卡号。
	ReqReserved  string `form:"reqReserved" sign:"true"`  //ANS1..1024	O	商户自定义保留域,交易应答时会原样返回	商户自定义保留域,交易应答时会原样返回
	OrderDesc    string `form:"orderDesc" sign:"true"`    //ANS1..32
}

消费请求

func (UnionConsumeRequest) Post

type UnionConsumeResponse

type UnionConsumeResponse struct {
	MerId      string `form:"merId" sign:"true"`
	OrderId    string `form:"orderId" sign:"true"`
	Version    string `form:"version" sign:"true"`
	CertId     string `form:"certId" sign:"true"`
	Encoding   string `form:"encoding" sign:"true"`
	Signature  string `form:"signature" sign:"false"`
	RespMsg    string `form:"respMsg" sign:"true"`
	TxnType    string `form:"txnType" sign:"true"`
	RespCode   string `form:"respCode" sign:"true"`
	SignMethod string `form:"signMethod" sign:"true"`
	TxnTime    string `form:"txnTime" sign:"true"`
	AccessType string `form:"accessType" sign:"true"`
	BizType    string `form:"bizType" sign:"true"`
	TN         string `form:"tn" sign:"true"`
	TxnSubType string `form:"txnSubType" sign:"true"`
}

func (UnionConsumeResponse) IsError

func (this UnionConsumeResponse) IsError() error

type UnionKeyConfig

type UnionKeyConfig struct {
	UNION_HOST   string
	MCH_ID       string //商户号 测试用: 777290058130633
	MCH_PRIVATE  string //商户私钥,用于加密发给银联的数据
	MCH_PUBLIC   string //商户公钥,用于银联验证发过去的数据
	MCH_CERTID   string //商户公钥证书ID
	UNION_PUBLIC string //银联公钥,用于研制银联过来的数据
	UNION_CERTID string //银联公钥证书ID
}

union

type UnionQueryOrderRequest

type UnionQueryOrderRequest struct {
	//基本字段
	Version    string `form:"version" sign:"true"`    //版本号固定填写5.0.0
	Encoding   string `form:"encoding" sign:"true"`   //编码方式	支持UTF-8与GBK
	CertId     string `form:"certId" sign:"true"`     //证书ID,填写签名私钥证书的Serial Number
	SignMethod string `form:"signMethod" sign:"true"` //01:表示采用RSA	固定填写01
	Signature  string `form:"signature" sign:"false"` //签名
	TxnType    string `form:"txnType" sign:"true"`    //固定填写00
	TxnSubType string `form:"txnSubType" sign:"true"` //交易子类		固定填写01
	BizType    string `form:"bizType" sign:"true"`    //8	产品类型 000000
	//商户信息
	AccessType string `form:"accessType" sign:"true"` //固定填写0
	MerId      string `form:"merId" sign:"true"`      //商户ID
	//订单信息
	OrderId string `form:"orderId" sign:"true"` //订单id
	TxnTime string `form:"txnTime" sign:"true"` //订单时间

}

银联交易状态查询

func (UnionQueryOrderRequest) Post

type UnionQueryOrderResponse

type UnionQueryOrderResponse struct {
	Version      string `form:"version" sign:"true"`      //版本号固定填写5.0.0
	Encoding     string `form:"encoding" sign:"true"`     //编码方式	支持UTF-8与GBK
	CertId       string `form:"certId" sign:"true"`       //证书ID,填写签名私钥证书的Serial Number
	SignMethod   string `form:"signMethod" sign:"true"`   //01:表示采用RSA	固定填写01
	Signature    string `form:"signature" sign:"false"`   //签名
	TxnType      string `form:"txnType" sign:"true"`      //固定填写00
	TxnSubType   string `form:"txnSubType" sign:"true"`   //交易子类		固定填写01
	BizType      string `form:"bizType" sign:"true"`      //8	产品类型 000000
	AccessType   string `form:"accessType" sign:"true"`   //固定填写0
	MerId        string `form:"merId" sign:"true"`        //商户ID
	OrderId      string `form:"orderId" sign:"true"`      //订单id
	TxnTime      string `form:"txnTime" sign:"true"`      //订单时间
	CurrencyCode string `form:"currencyCode" sign:"true"` // 固定156
	TxnAmt       string `form:"txnAmt" sign:"true"`       //单位为分,不能带小数点例:1元填写100
	PayType      string `form:"payType" sign:"true"`      //支付类型
	AccNo        string `form:"accNo" sign:"true"`        //卡号
	PayCardType  string `form:"payCardType" sign:"true"`  //支付卡类型
	BindId       string `form:"bindId" sign:"true"`       //绑定关系标识号
	ReqReserved  string `form:"reqReserved" sign:"true"`  //请求方自定义域
	Reserved     string `form:"reserved" sign:"true"`     //保留域
	RespMsg      string `form:"respMsg" sign:"true"`
	RespCode     string `form:"respCode" sign:"true"`
}

func (UnionQueryOrderResponse) IsError

func (this UnionQueryOrderResponse) IsError() error

type WXConfigForJS

type WXConfigForJS struct {
	Debug     bool     `json:"debug" sign:"false"`
	AppId     string   `json:"appId" sign:"false"`
	Timestamp string   `json:"timestamp" sign:"true"`
	NonceStr  string   `json:"nonceStr" sign:"true"`
	Signature string   `json:"signature" sign:"false"`
	JSApiList []string `json:"jsApiList" sign:"false"`
	// contains filtered or unexported fields
}

恶心的微信签名用noncestr,脚本里用nonceStr

func (WXConfigForJS) ToScript

func (r WXConfigForJS) ToScript(jsticket string, url string) (template.JS, error)

type WXError

type WXError struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

func AuthGet

func AuthGet(token, openid string) WXError

检验授权凭证(access_token,openid)是否有效 GET https://api.weixin.qq.com/sns/auth?access_token=ACCESS_TOKEN&openid=OPENID

func (WXError) Error

func (this WXError) Error() error

type WXGetAccessTokenResponse

type WXGetAccessTokenResponse struct {
	WXError
	AccessToken string `json:"access_token"`
	Expires     int    `json:"expires_in"`
}

type WXKeyConfig

type WXKeyConfig struct {
	APP_ID     string
	APP_SECRET string
	MCH_ID     string
	MCH_KEY    string
	CRT_PATH   string
	KEY_PATH   string
	CA_PATH    string
	TLSConfig  *tls.Config
}

type WXOAuth2RefreshTokenRequest

type WXOAuth2RefreshTokenRequest struct {
	AppId        string `json:"appid,omitempty" sign:"true"`
	RefreshToken string `json:"refresh_token,omitempty" sign:"true"`
	GrantType    string `json:"grant_type,omitempty" sign:"true"`
}

刷新网页授权凭证 https://api.weixin.qq.com/sns/oauth2/refresh_token

type WXOAuth2RefreshTokenResponse

type WXOAuth2RefreshTokenResponse struct {
	WXError
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	OpenId       string `json:"openid"`
	Scope        string `json:"scope"`
}

type WXPayQueryOrder

type WXPayQueryOrder struct {
	XMLName    struct{} `xml:"xml"`
	AppId      string   `xml:"appid" sign:"true"`
	MchId      string   `xml:"mch_id" sign:"true"`
	OutTradeNo string   `xml:"out_trade_no" sign:"true"`
	NonceStr   string   `xml:"nonce_str" sign:"true"`
	Sign       string   `xml:"sign" sign:"false"` //sign=false表示不参与签名
}

2201604122135130001 https://api.mch.weixin.qq.com/pay/orderquery

func (WXPayQueryOrder) ToXML

func (this WXPayQueryOrder) ToXML() string

type WXPayQueryOrderResponse

type WXPayQueryOrderResponse struct {
	XMLName        struct{} `xml:"xml"`
	AppId          string   `xml:"appid" sign:"true"`
	Attach         string   `xml:"attach" sign:"true"`
	BankType       string   `xml:"bank_type" sign:"true"`
	CashFee        string   `xml:"cash_fee" sign:"true"`
	ErrCode        string   `xml:"err_code" sign:"true"`
	ErrCodeDes     string   `xml:"err_code_des" sign:"true"`
	FeeType        string   `xml:"fee_type" sign:"true"`
	IsSubScribe    string   `xml:"is_subscribe" sign:"true"`
	MchId          string   `xml:"mch_id" sign:"true"`
	NonceStr       string   `xml:"nonce_str" sign:"true"`
	OpenId         string   `xml:"openid" sign:"true"`
	OutTradeNo     string   `xml:"out_trade_no" sign:"true"`
	ResultCode     string   `xml:"result_code" sign:"true"`
	ReturnCode     string   `xml:"return_code" sign:"true"`
	ReturnMsg      string   `xml:"return_msg" sign:"true"`
	Sign           string   `xml:"sign" sign:"false"`
	TimeEnd        string   `xml:"time_end" sign:"true"`
	TotalFee       string   `xml:"total_fee" sign:"true"`
	TradeState     string   `xml:"trade_state" sign:"true"`
	TradeStateDesc string   `xml:"trade_state_desc" sign:"true"`
	TradeType      string   `xml:"trade_type" sign:"true"`
	TransactionId  string   `xml:"transaction_id" sign:"true"`
}

func (WXPayQueryOrderResponse) IsPaySuccess

func (this WXPayQueryOrderResponse) IsPaySuccess() bool

支付成功

func (WXPayQueryOrderResponse) IsPaying

func (this WXPayQueryOrderResponse) IsPaying() bool

正在支付

type WXPayReqForApp

type WXPayReqForApp struct {
	AppId     string `json:"appid,omitempty" sign:"true"`
	NonceStr  string `json:"noncestr,omitempty" sign:"true"`
	Package   string `json:"package,omitempty" sign:"true"` //APP支付固定(Sign=WXPay)
	PartnerId string `json:"partnerid,omitempty" sign:"true"`
	PrepayId  string `json:"prepayid,omitempty" sign:"true"` //统一下单返回
	Sign      string `json:"sign,omitempty" sign:"false"`
	Timestamp int64  `json:"timestamp,omitempty" sign:"true"`
}

为app支付返回给客户端用于客户端发起支付

func (WXPayReqForApp) String

func (this WXPayReqForApp) String() string

type WXPayReqForJS

type WXPayReqForJS struct {
	AppId     string `json:"appId,omitempty" sign:"true"`
	Timestamp int64  `json:"timeStamp,omitempty" sign:"true"`
	Package   string `json:"package,omitempty" sign:"true"`
	NonceStr  string `json:"nonceStr,omitempty" sign:"true"`
	SignType  string `json:"signType,omitempty" sign:"true"`
	PaySign   string `json:"paySign,omitempty" sign:"false"`
}

为jsapi支付返回给客户端用于客户端发起支付

func (WXPayReqForJS) ToScript

func (this WXPayReqForJS) ToScript() (template.JS, error)

type WXPayReqScript

type WXPayReqScript struct {
	Timestamp int64  `json:"timestamp,omitempty"`
	Package   string `json:"package,omitempty"`
	NonceStr  string `json:"nonceStr,omitempty"`
	SignType  string `json:"signType,omitempty"`
	PaySign   string `json:"paySign,omitempty"`
}

type WXPayResultResponse

type WXPayResultResponse struct {
	xweb.XMLModel `xml:"-"`
	XMLName       struct{} `xml:"xml"`                   //root node name
	ReturnCode    string   `xml:"return_code,omitempty"` //SUCCESS or FAIL
	ReturnMsg     string   `xml:"return_msg,omitempty"`  //OK
}

商户处理后返回格式

func (WXPayResultResponse) ToXML

func (r WXPayResultResponse) ToXML() string

type WXQRCodeCreateRequest

type WXQRCodeCreateRequest struct {
	ActionName string `json:"action_name"`
	ActionInfo struct {
		Scene struct {
			SceneStr string `json:"scene_str"`
		} `json:"scene"`
	} `json:"action_info"`
}

二维码生产

func (WXQRCodeCreateRequest) Post

func (WXQRCodeCreateRequest) ToReader

func (this WXQRCodeCreateRequest) ToReader() (io.Reader, error)

type WXQRCodeCreateResponse

type WXQRCodeCreateResponse struct {
	WXError
	Ticket        string `json:"ticket"`
	ExpireSeconds int    `json:"expire_seconds"`
	URL           string `json:"url"`
}

type WXRedPackageRequest

type WXRedPackageRequest struct {
	MchBillno   string `xml:"mch_billno" sign:"true"`
	NonceStr    string `xml:"nonce_str" sign:"true"`
	MchId       string `xml:"mch_id" sign:"true"`
	AppId       string `xml:"wxappid" sign:"true"`
	SendName    string `xml:"send_name" sign:"true"`
	ReOpenId    string `xml:"re_openid" sign:"true"`
	TotalAmount int    `xml:"total_amount" sign:"true"`
	TotalNum    int    `xml:"total_num" sign:"true"`
	Wishing     string `xml:"wishing" sign:"true"`
	ClientIp    string `xml:"client_ip" sign:"true"`
	ActName     string `xml:"act_name" sign:"true"`
	Remark      string `xml:"remark" sign:"true"`
	Sign        string `xml:"sign" sign:"false"`
}

微信红包发送

func (WXRedPackageRequest) ToXml

func (this WXRedPackageRequest) ToXml() string

type WXRedPackageResponse

type WXRedPackageResponse struct {
	ReturnCode string `xml:"return_code"`
	ReturnMsg  string `xml:"return_msg"`
	ResultCode string `xml:"result_code"`
	ErrCodeDes string `xml:"err_code_des"`
}

type WXRefundRequest

type WXRefundRequest struct {
	XMLName       struct{} `xml:"xml"`
	AppId         string   `xml:"appid,omitempty" sign:"true"`
	MchId         string   `xml:"mch_id,omitempty" sign:"true"`
	NonceStr      string   `xml:"nonce_str,omitempty" sign:"true"`
	OPUserId      string   `xml:"op_user_id,omitempty" sign:"true"`
	OutRefundNO   string   `xml:"out_refund_no,omitempty" sign:"true"`
	OutTradeNO    string   `xml:"out_trade_no,omitempty" sign:"true"`
	RefundFee     string   `xml:"refund_fee,omitempty" sign:"true"`
	Sign          string   `xml:"sign,omitempty" sign:"false"`
	TotalFee      string   `xml:"total_fee,omitempty" sign:"true"`
	TransactionId string   `xml:"transaction_id,omitempty" sign:"true"`
	// contains filtered or unexported fields
}

https://api.mch.weixin.qq.com/secapi/pay/refund 微信退款发起请求

func (WXRefundRequest) Post

func (WXRefundRequest) ToXML

func (r WXRefundRequest) ToXML() string

type WXRefundResponse

type WXRefundResponse struct {
	XMLName            struct{} `xml:"xml"`
	AppId              string   `xml:"appid,omitempty" sign:"true"`
	CashFee            string   `xml:"cash_fee,omitempty" sign:"true"`
	CashRefundFee      string   `xml:"cash_refund_fee,omitempty" sign:"true"`
	DeviceInfo         string   `xml:"device_info,omitempty" sign:"true"`
	ErrCode            string   `xml:"err_code,omitempty" sign:"true"`
	ErrCodeDes         string   `xml:"err_code_des,omitempty" sign:"true"`
	FeeType            string   `xml:"fee_type,omitempty" sign:"true"`
	MchId              string   `xml:"mch_id,omitempty" sign:"true"`
	NonceStr           string   `xml:"nonce_str,omitempty" sign:"true"`
	OutRefundNO        string   `xml:"out_refund_no,omitempty" sign:"true"`
	OutTradeNO         string   `xml:"out_trade_no,omitempty" sign:"true"`
	RefundChannel      string   `xml:"refund_channel,omitempty" sign:"true"`
	RefundFee          string   `xml:"refund_fee,omitempty" sign:"true"`
	RefundId           string   `xml:"refund_id,omitempty" sign:"true"`
	ResultCode         string   `xml:"result_code,omitempty" sign:"true"`
	ReturnCode         string   `xml:"return_code,omitempty" sign:"true"`
	ReturnMsg          string   `xml:"return_msg,omitempty" sign:"true"`
	SettlementTotalFee string   `xml:"settlement_total_fee,omitempty" sign:"true"`
	Sign               string   `xml:"sign" sign:"false"`
	TotalFee           string   `xml:"total_fee,omitempty" sign:"true"`
	TransactionId      string   `xml:"transaction_id,omitempty" sign:"true"`
	CouponRefundFee    string   `xml:"coupon_refund_fee,omitempty" sign:"true"`
	CouponRefundCount  string   `xml:"coupon_refund_count,omitempty" sign:"true"`
	// contains filtered or unexported fields
}

func (WXRefundResponse) SignValid

func (r WXRefundResponse) SignValid() bool

type WXTransfersRequest

type WXTransfersRequest struct {
	AppId          string `xml:"mch_appid" sign:"true"`
	MchId          string `xml:"mchid" sign:"true"`
	NonceStr       string `xml:"nonce_str" sign:"true"`
	Sign           string `xml:"sign" sign:"false"`
	PartnerTradeNo string `xml:"partner_trade_no" sign:"true"`
	OpenId         string `xml:"openid" sign:"true"`
	CheckName      string `xml:"check_name" sign:"true"`
	Amount         int    `xml:"amount" sign:"true"`
	Desc           string `xml:"desc" sign:"true"`
	SpbillCreateIp string `xml:"spbill_create_ip" sign:"true"`
}

微信转账

func (WXTransfersRequest) ToXml

func (r WXTransfersRequest) ToXml() string

type WXTransfersResponse

type WXTransfersResponse struct {
	ReturnCode string `xml:"return_code"`
	ReturnMsg  string `xml:"return_msg"`
	ResultCode string `xml:"result_code"`
	ErrCodeDes string `xml:"err_code_des"`
}

type WXUnifiedOrderRequest

type WXUnifiedOrderRequest struct {
	XMLName        struct{} `xml:"xml"` //root node name
	AppId          string   `xml:"appid,omitempty" sign:"true"`
	Attach         string   `xml:"attach,omitempty" sign:"true"`
	Body           string   `xml:"body,omitempty" sign:"true"`
	Detail         string   `xml:"detail,omitempty" sign:"true"`
	DeviceInfo     string   `xml:"device_info,omitempty" sign:"true"`
	FeeType        string   `xml:"fee_type,omitempty" sign:"true"`
	GoodsTag       string   `xml:"goods_tag,omitempty" sign:"true"`
	LimitPay       string   `xml:"limit_pay,omitempty" sign:"true"`
	MchId          string   `xml:"mch_id,omitempty" sign:"true"`
	NonceStr       string   `xml:"nonce_str,omitempty" sign:"true"`
	NotifyURL      string   `xml:"notify_url,omitempty" sign:"true"`
	OpenId         string   `xml:"openid,omitempty" sign:"true"` //TradeType=TRADE_TYPE_JSAPI 必须
	OutTradeNo     string   `xml:"out_trade_no,omitempty" sign:"true"`
	ProductId      string   `xml:"product_id,omitempty" sign:"true"` //TradeType=TRADE_TYPE_NATIVE 必须
	Sign           string   `xml:"sign,omitempty"  sign:"false"`     //sign=false表示不参与签名
	SpBillCreateIp string   `xml:"spbill_create_ip,omitempty" sign:"true"`
	TimeExpire     string   `xml:"time_expire,omitempty" sign:"true"`
	TimeStart      string   `xml:"time_start,omitempty" sign:"true"`
	TotalFee       string   `xml:"total_fee,omitempty" sign:"true"`
	TradeType      string   `xml:"trade_type,omitempty" sign:"true"`
	// contains filtered or unexported fields
}

微信支付:统一下单 https://api.mch.weixin.qq.com/pay/unifiedorder

func (WXUnifiedOrderRequest) Post

func (WXUnifiedOrderRequest) ToXML

func (r WXUnifiedOrderRequest) ToXML() string

type WXUnifiedOrderResponse

type WXUnifiedOrderResponse struct {
	XMLName    struct{} `xml:"xml"` //root node name
	AppId      string   `xml:"appid,omitempty" sign:"true"`
	CodeURL    string   `xml:"code_url,omitempty" sign:"true"` //trade_type=NATIVE返回code url
	DeviceInfo string   `xml:"device_info,omitempty" sign:"true"`
	ErrCode    string   `xml:"err_code,omitempty" sign:"true"`
	ErrCodeDes string   `xml:"err_code_des,omitempty" sign:"true"`
	MchId      string   `xml:"mch_id,omitempty" sign:"true"`
	NonceStr   string   `xml:"nonce_str,omitempty" sign:"true"`
	PrePayId   string   `xml:"prepay_id,omitempty" sign:"true"`
	ResultCode string   `xml:"result_code,omitempty" sign:"true"` //SUCCESS or FAIL
	ReturnCode string   `xml:"return_code,omitempty" sign:"true"` //SUCCESS or FAIL
	ReturnMsg  string   `xml:"return_msg,omitempty" sign:"true"`  //返回信息,如非空,为错误原因
	Sign       string   `xml:"sign,omitempty"  sign:"false"`      //sign=false表示不参与签名
	TradeType  string   `xml:"trade_type,omitempty" sign:"true"`
}

微信支付:统一下单返回数据

func (WXUnifiedOrderResponse) Error

func (r WXUnifiedOrderResponse) Error() error

type WXUserInfoRequest

type WXUserInfoRequest struct {
	AccessToken string `json:"access_token" sign:"true"`
	OpenId      string `json:"openid" sign:"true"`
	Lang        string `json:"lang" sign:"true"`
}

拉取用户信息 AccessToken并非网页授权token https://api.weixin.qq.com/cgi-bin/user/info

func (WXUserInfoRequest) Get

type WXUserInfoResponse

type WXUserInfoResponse struct {
	WXError
	SubscribeTime int64  `json:"subscribe_time"` //关注时间
	Subscribe     int    `json:"subscribe"`      //是否关注
	OpenId        string `json:"openid"`
	NickName      string `json:"nickname"`
	Language      string `json:"language"`
	Sex           int    `json:"sex"`
	Province      string `json:"province"`
	City          string `json:"city"`
	Remark        string `json:"remark"` //备注
	Country       string `json:"country"`
	HeadImgURL    string `json:"headimgurl"`
	UnionId       string `json:"unionid"`
	GroupId       int    `json:"groupid"`
	TagIdList     []int  `json:"tagid_list"`
}

type WxPay

type WxPay struct {
	// contains filtered or unexported fields
}

func NewWxPay

func NewWxPay(conf WXKeyConfig) *WxPay

func (*WxPay) NewConfigForJS

func (p *WxPay) NewConfigForJS() (r *WXConfigForJS, err error)

func (*WxPay) NewRefundRequest

func (p *WxPay) NewRefundRequest() (r *WXRefundRequest, err error)

func (*WxPay) NewUnifiedOrderRequest

func (p *WxPay) NewUnifiedOrderRequest() (r *WXUnifiedOrderRequest)

func (*WxPay) NewWXPayNotify

func (p *WxPay) NewWXPayNotify(body []byte) (n *PayNotify, err error)

func (*WxPay) NewWXPayReqForApp

func (p *WxPay) NewWXPayReqForApp(prepayid string) WXPayReqForApp

新建APP支付返回

func (*WxPay) NewWXPayReqForJS

func (p *WxPay) NewWXPayReqForJS(prepayid string) WXPayReqForJS

新建jsapi支付返回

func (*WxPay) NewWXPayReqScript

func (p *WxPay) NewWXPayReqScript(prepayid string) WXPayReqScript

func (*WxPay) OAuth2RefreshTokenRequest

func (p *WxPay) OAuth2RefreshTokenRequest(r WXOAuth2RefreshTokenRequest) (WXOAuth2RefreshTokenResponse, error)

func (*WxPay) PostPayQueryOrder

func (p *WxPay) PostPayQueryOrder(r WXPayQueryOrder) (WXPayQueryOrderResponse, error)

func (*WxPay) RedPackageRequest

func (p *WxPay) RedPackageRequest(q WXRedPackageRequest) (WXRedPackageResponse, error)

func (*WxPay) SignValidPayQueryOrderResponse

func (p *WxPay) SignValidPayQueryOrderResponse(r WXPayQueryOrderResponse) bool

func (*WxPay) WXSign

func (p *WxPay) WXSign(v interface{}) string

func (*WxPay) WxTransfersRequest

func (p *WxPay) WxTransfersRequest(q WXTransfersRequest) (WXTransfersResponse, error)

Jump to

Keyboard shortcuts

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