Documentation ¶
Index ¶
- Constants
- type Color
- type GetWxACodeUnLimitReq
- type NotifyCode
- type NotifyRes
- type PaySignData
- type PaymentNotifyCode
- type PaymentNotifyReq
- type PaymentNotifyRes
- type RefundNotifyReq
- type RefundReq
- type RefundStatus
- type SignType
- type SubscribeSendDataItem
- type SubscribeSendReq
- type TradeType
- type UnifiedOrderReq
- type Wechat
- func (wx *Wechat) DecodeRefundReqInfo(reqInfo, apiKey string) (*refundReqInfo, error)
- func (wx *Wechat) GenPaySignPackage(prepayID string) string
- func (wx *Wechat) GenSign(body interface{}, apiKey string) string
- func (wx *Wechat) GetAccessToken() (*accessTokenRes, error)
- func (wx *Wechat) GetWxACodeUnLimit(accessToken string, req *GetWxACodeUnLimitReq) (*getWxACodeUnLimitRes, error)
- func (wx *Wechat) JsCode2Session(code string) (*jsCode2SessionRes, error)
- func (wx *Wechat) Refund(req *RefundReq, certKey, cert string) (*refundRes, error)
- func (wx *Wechat) SubscribeSend(accessToken string, req *SubscribeSendReq) (*subscribeSendRes, error)
- func (wx *Wechat) UnifiedOrder(req *UnifiedOrderReq) (*unifiedOrderRes, error)
- func (wx *Wechat) ZeroValueProcess(res []byte)
Constants ¶
View Source
const ( SignTypeMD5 = SignType("MD5") SignTypeHmacSha256 = SignType("HMAC-SHA256") )
View Source
const ( TradeTypeJsapi = TradeType("JSAPI") // JSAPI/小程序 TradeTypeNative = TradeType("NATIVE") // Native TradeTypeApp = TradeType("APP") // app TradeTypeMWeb = TradeType("MWEB") // H5 )
View Source
const ( PaymentNotifySuccessReturnCode = PaymentNotifyCode("SUCCESS") PaymentNotifySuccessReturnMsg = "OK" PaymentNotifyFailReturnCode = PaymentNotifyCode("FAIL") )
View Source
const ( RefundStatusSuccess = RefundStatus("SUCCESS") RefundStatusChange = RefundStatus("CHANGE") RefundStatusRefundClose = RefundStatus("REFUNDCLOSE") )
View Source
const ( NotifySuccessReturnCode = NotifyCode("SUCCESS") NotifySuccessReturnMsg = "OK" NotifyFailReturnCode = NotifyCode("FAIL") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GetWxACodeUnLimitReq ¶ added in v0.1.9
type GetWxACodeUnLimitReq struct { Scene string `json:"scene"` /* 是 最大32个可见字符,只支持数字, 大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~, 其它字符请自行编码为合法字符(因不支持%,中文无法使用 urlencode 处理, 请使用其他编码方式) */ Page string `json:"page"` /* 否 必须是已经发布的小程序存在的页面(否则报错), 例如 pages/index/index, 根路径前不要填加 /, 不能携带参数(参数请放在scene字段里), 如果不填写这个字段,默认跳主页面 */ Width int64 `json:"width"` // 否 二维码的宽度,单位 px,最小 280px,最大 1280px AutoColor bool `json:"auto_color"` // 否 自动配置线条颜色,如果颜色依然是黑色,则说明不建议配置主色调,默认 false LineColor Color `json:"line_color"` // 否 auto_color 为 false 时生效,使用 rgb 设置颜色 例如 {"r":"xxx","g":"xxx","b":"xxx"} 十进制表示 IsHyaline bool `json:"is_hyaline"` // 否 是否需要透明底色,为 true 时,生成透明底色的小程序 }
==================== 获取二维码 ====================
type NotifyCode ¶ added in v0.1.4
type NotifyCode string
type NotifyRes ¶ added in v0.1.4
type NotifyRes struct { XMLName xml.Name `xml:"xml"` ReturnCode NotifyCode `xml:"return_code"` ReturnMsg string `xml:"return_msg"` }
type PaySignData ¶ added in v0.0.3
type PaymentNotifyCode ¶ added in v0.0.3
type PaymentNotifyCode string
type PaymentNotifyReq ¶ added in v0.0.3
type PaymentNotifyReq struct { ReturnCode string `xml:"return_code" validate:"required"` ReturnMsg string `xml:"return_msg"` AppID string `xml:"appid" validate:"required"` MchID string `xml:"mch_id" validate:"required"` DeviceInfo string `xml:"device_info"` NonceStr string `xml:"nonce_str" validate:"required"` Sign string `xml:"sign" validate:"required"` SignType SignType `xml:"sign_type"` ResultCode string `xml:"result_code" validate:"required"` ErrCode string `xml:"err_code"` ErrCodeDes string `xml:"err_code_des"` OpenID string `xml:"openid" validate:"required"` IsSubscribe string `xml:"is_subscribe" validate:"required"` TradeType TradeType `xml:"trade_type" validate:"required"` BankType string `xml:"bank_type" validate:"required"` TotalFee int64 `xml:"total_fee" validate:"required"` SettlementTotalFee int64 `xml:"settlement_total_fee"` FeeType string `xml:"fee_type"` CashFee int64 `xml:"cash_fee"` CashFeeType string `xml:"cash_fee_type"` CouponFee int64 `xml:"coupon_fee"` CouponCount int64 `xml:"coupon_count"` TransactionID string `xml:"transaction_id" validate:"required"` OutTradeNo string `xml:"out_trade_no" validate:"required"` Attach string `xml:"attach"` TimeEnd string `xml:"time_end" validate:"required"` }
==================== 支付通知 ====================
type PaymentNotifyRes ¶ added in v0.0.3
type PaymentNotifyRes struct { XMLName xml.Name `xml:"xml"` ReturnCode PaymentNotifyCode `xml:"return_code"` ReturnMsg string `xml:"return_msg"` }
type RefundNotifyReq ¶ added in v0.1.4
type RefundNotifyReq struct { ReturnCode string `xml:"return_code" validate:"required"` ReturnMsg string `xml:"return_msg"` AppID string `xml:"appid" validate:"required"` MchID string `xml:"mch_id" validate:"required"` NonceStr string `xml:"nonce_str" validate:"required"` ReqInfo string `xml:"req_info" validate:"required"` }
==================== 退款通知 ====================
type RefundReq ¶ added in v0.1.4
type RefundReq struct { XMLName xml.Name `xml:"xml"` AppID string `xml:"appid"` // 是,微信分配的小程序ID MchID string `xml:"mch_id"` // 是,微信支付分配的商户号 NonceStr string `xml:"nonce_str"` // 是,随机字符串,长度要求在32位以内。推荐随机数生成算法 Sign string `xml:"sign"` // 是,通过签名算法计算得出的签名值,详见签名生成算法 SignType SignType `xml:"sign_type"` // 否,通过签名算法计算得出的签名值,详见签名生成算法 //TransactionID string `xml:"transaction_id"` // 微信生成的订单号,在支付通知中有返回 OutTradeNo string `xml:"out_trade_no"` /* 是,商户系统内部订单号,要求32个字符内, 只能是数字、大小写字母_-|*@ ,且在同一个商户号下唯一。 transaction_id、out_trade_no二选一, 如果同时存在优先级:transaction_id > out_trade_no */ OutRefundNo string `xml:"out_refund_no"` // 是,商户系统内部的退款单号,商户系统内部唯一,只能是数字、大小写字母_-|*@ ,同一退款单号多次请求只退一笔。 TotalFee int64 `xml:"total_fee"` // 是,订单总金额,单位为分,只能为整数,详见支付金额 RefundFee int64 `xml:"refund_fee"` // 是,退款总金额,订单总金额,单位为分,只能为整数,详见支付金额 RefundFeeType string `xml:"refund_fee_type"` // 否,货币类型,符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型 RefundDesc string `xml:"refund_desc"` /* 否,若商户传入,会在下发给用户的退款消息中体现退款原因 注意:若订单退款金额≤1元,且属于部分退款,则不会在退款消息中体现退款原因 */ RefundAccount string `xml:"refund_account"` /* 否,仅针对老资金流商户使用 REFUND_SOURCE_UNSETTLED_FUNDS---未结算资金退款(默认使用未结算资金退款) REFUND_SOURCE_RECHARGE_FUNDS---可用余额退款 */ NotifyUrl string `xml:"notify_url"` }
==================== 退款 ====================
type RefundStatus ¶ added in v0.1.4
type RefundStatus string
type SubscribeSendDataItem ¶ added in v0.1.12
type SubscribeSendDataItem struct {
Value string `json:"value"`
}
type SubscribeSendReq ¶ added in v0.1.12
type SubscribeSendReq struct { ToUser string `json:"touser"` // 是 接收者(用户)的 openid TemplateID string `json:"template_id"` // 是 所需下发的订阅模板id Page string `json:"page"` // 否 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。 Data map[string]SubscribeSendDataItem `json:"data"` // 是 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } } MiniprogramState string `json:"miniprogram_state"` // 否 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版 Lang string `json:"lang"` // 否 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN }
==================== 发送订阅通知 ====================
type TradeType ¶ added in v0.0.3
type TradeType string
==================== 统一下单 ====================
type UnifiedOrderReq ¶ added in v0.0.2
type UnifiedOrderReq struct { XMLName xml.Name `xml:"xml"` AppID string `xml:"appid"` // 是,微信分配的小程序ID MchID string `xml:"mch_id"` // 是,微信支付分配的商户号 DeviceInfo string `xml:"device_info"` // 否,自定义参数,可以为终端设备号(门店号或收银设备ID),PC网页或公众号内支付可以传"WEB" NonceStr string `xml:"nonce_str"` // 是,随机字符串,长度要求在32位以内。推荐随机数生成算法 Sign string `xml:"sign"` // 是,通过签名算法计算得出的签名值,详见签名生成算法 SignType SignType `xml:"sign_type"` // 否,通过签名算法计算得出的签名值,详见签名生成算法 Body string `xml:"body"` // 是,通过签名算法计算得出的签名值,详见签名生成算法 Detail string `xml:"detail"` // 否,商品详细描述,对于使用单品优惠的商户,该字段必须按照规范上传,详见“单品优惠参数说明” Attach string `xml:"attach"` // 否,附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。 OutTradeNo string `xml:"out_trade_no"` // 是,商户系统内部订单号,要求32个字符内,只能是数字、大小写字母_-|*且在同一个商户号下唯一。详见商户订单号 FeeType string `xml:"fee_type"` // 否,符合ISO 4217标准的三位字母代码,默认人民币:CNY,详细列表请参见货币类型 TotalFee string `xml:"total_fee"` // 是,订单总金额,单位为分,详见支付金额 SpbillCreateIP string `xml:"spbill_create_ip"` // 是,支持IPV4和IPV6两种格式的IP地址。调用微信支付API的机器IP TimeStart string `xml:"time_start"` // 否,订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则 TimeExpire string `xml:"time_expire"` /* 否,订单失效时间, 格式为yyyyMMddHHmmss, 如2009年12月27日9点10分10秒表示为20091227091010。 订单失效时间是针对订单号而言的, 由于在请求支付的时候有一个必传参数prepay_id只有两小时的有效期, 所以在重入时间超过2小时的时候需要重新请求下单接口获取新的prepay_id。 其他详见时间规则 建议:最短失效时间间隔大于1分钟 */ GoodsTag string `xml:"goods_tag"` // 否,订单优惠标记,使用代金券或立减优惠功能时需要的参数,说明详见代金券或立减优惠 NotifyUrl string `xml:"notify_url"` // 是,异步接收微信支付结果通知的回调地址,通知url必须为外网可访问的url,不能携带参数。公网域名必须为https,如果是走专线接入,使用专线NAT IP或者私有回调域名可使用http。 TradeType TradeType `xml:"trade_type"` // 是,小程序取值如下:JSAPI,详细说明见参数规定 ProductID string `xml:"product_id"` // 否,trade_type=NATIVE时,此参数必传。此参数为二维码中包含的商品ID,商户自行定义。 LimitPay string `xml:"limit_pay"` // 否,上传此参数no_credit--可限制用户不能使用信用卡支付 OpenID string `xml:"openid"` // 否,trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。openid如何获取,可参考【获取openid】。 Receipt string `xml:"receipt"` // 否,Y,传入Y时,支付成功消息和支付详情页将出现开票入口。需要在微信支付商户平台或微信公众平台开通电子发票功能,传此字段才可生效 ProfitSharing string `xml:"profit_sharing"` /* 否,Y-是,需要分账 N-否,不分账 字母要求大写,不传默认不分账 */ SceneInfo string `xml:"scene_info"` }
type Wechat ¶ added in v0.0.2
type Wechat struct { AppID string AppSecret string ZeroValueMap map[string]interface{} // use for gen sign }
func (*Wechat) DecodeRefundReqInfo ¶ added in v0.1.4
func (*Wechat) GenPaySignPackage ¶ added in v0.0.3
func (*Wechat) GetAccessToken ¶ added in v0.1.9
func (*Wechat) GetWxACodeUnLimit ¶ added in v0.1.9
func (wx *Wechat) GetWxACodeUnLimit(accessToken string, req *GetWxACodeUnLimitReq) (*getWxACodeUnLimitRes, error)
func (*Wechat) JsCode2Session ¶ added in v0.0.2
func (*Wechat) SubscribeSend ¶ added in v0.1.12
func (wx *Wechat) SubscribeSend(accessToken string, req *SubscribeSendReq) (*subscribeSendRes, error)
func (*Wechat) UnifiedOrder ¶ added in v0.0.2
func (wx *Wechat) UnifiedOrder(req *UnifiedOrderReq) (*unifiedOrderRes, error)
func (*Wechat) ZeroValueProcess ¶ added in v0.1.6
==================== 零值处理 ====================
Click to show internal directories.
Click to hide internal directories.