Documentation ¶
Index ¶
- type BlockReasonEnum
- type BusSceneInfo
- type CreateTransactionRequest
- type MetroSceneInfo
- type OrderAmount
- type PromotionDetail
- type PromotionType
- type QueryOrderAmount
- type QueryTransactionRequest
- type QueryUserServiceRequest
- type TradeScene
- type TradeState
- type TransactionsApiService
- func (a *TransactionsApiService) CreateTransaction(ctx context.Context, req CreateTransactionRequest) (resp *TransactionsEntity, result *core.APIResult, err error)
- func (a *TransactionsApiService) QueryTransaction(ctx context.Context, req QueryTransactionRequest) (resp *TransactionsEntity, result *core.APIResult, err error)
- type TransactionsEntity
- type UserRepayState
- type UserServiceEntity
- type UserServiceStateEnum
- type UserServicesApiService
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockReasonEnum ¶
type BlockReasonEnum string
BlockReasonEnum
const ( BLOCKREASONENUM_DELETED BlockReasonEnum = "DELETED" BLOCKREASONENUM_ACCOUNT_FROZEN BlockReasonEnum = "ACCOUNT_FROZEN" BLOCKREASONENUM_OVERDUE BlockReasonEnum = "OVERDUE" )
Enums of BlockReasonEnum
func (BlockReasonEnum) Ptr ¶
func (e BlockReasonEnum) Ptr() *BlockReasonEnum
type BusSceneInfo ¶
type BusSceneInfo struct { // 用户乘车时间(上车),按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE StartTime *string `json:"start_time"` // 乘车路线 路线名称的展示规则:\\^[A-Za-z0-9]{1,10}路$ 如line_name符合上述的规则,扣款凭证将增加展示乘车路线的字段 LineName *string `json:"line_name,omitempty"` // 车牌号。仅包括省份+车牌,不包括特殊字符。 PlateNumber *string `json:"plate_number,omitempty"` }
BusSceneInfo
func (BusSceneInfo) Clone ¶
func (o BusSceneInfo) Clone() *BusSceneInfo
func (BusSceneInfo) MarshalJSON ¶
func (o BusSceneInfo) MarshalJSON() ([]byte, error)
func (BusSceneInfo) String ¶
func (o BusSceneInfo) String() string
type CreateTransactionRequest ¶
type CreateTransactionRequest struct { // 商户在微信申请公众号或移动应用成功后分配的账号ID,登录平台为mp.weixin.qq.com或open.weixin.qq.com Appid *string `json:"appid"` // 子公众账号ID,服务商模式下选传,用于扣费信息的商户信息展示, SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的子商户号,服务商模式下必传 SubMchid *string `json:"sub_mchid,omitempty"` // 商户自定义字段,用于交易账单中对扣费服务的描述。该字段长度限制为字节长度限制 Description *string `json:"description"` // 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用,该字段长度限制为字节长度限制 Attach *string `json:"attach,omitempty"` // 商户系统内部订单号,只能是数字、大小写字母,且在同一个商户号下唯一。该字段长度限制为字节长度限制 OutTradeNo *string `json:"out_trade_no"` // 交易场景值,现在支持公交和地铁的场景值 TradeScene *TradeScene `json:"trade_scene"` // 代金券或立减优惠功能的参数,说明详见代金券或立减优惠 GoodsTag *string `json:"goods_tag,omitempty"` // 签约成功后,微信返回代扣签约ID 查用户是否能继续使用乘车卡时必传,此时,才会返回签约信息,如contract_state ContractId *string `json:"contract_id"` // 接受扣款结果异步回调通知的URL,注意回调URL只接受HTTPS NotifyUrl *string `json:"notify_url"` // 订单金额信息 Amount *OrderAmount `json:"amount"` // 请求受理扣费 tradescene为BUS时,传入该参数 BusInfo *BusSceneInfo `json:"bus_info,omitempty"` // 请求受理扣费 tradescene为METRO时,传入该参数 MetroInfo *MetroSceneInfo `json:"metro_info,omitempty"` }
CreateTransactionRequest
func (CreateTransactionRequest) Clone ¶
func (o CreateTransactionRequest) Clone() *CreateTransactionRequest
func (CreateTransactionRequest) MarshalJSON ¶
func (o CreateTransactionRequest) MarshalJSON() ([]byte, error)
func (CreateTransactionRequest) String ¶
func (o CreateTransactionRequest) String() string
type MetroSceneInfo ¶
type MetroSceneInfo struct { // 用户乘车时间(上车),按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE StartTime *string `json:"start_time"` // 用户下车时间,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE EndTime *string `json:"end_time,omitempty"` // 乘车起始站,该值催缴时会向微信用户进行展示 StartStation *string `json:"start_station,omitempty"` // 乘车终点站,该值催缴时会向微信用户进行展示 EndStation *string `json:"end_station,omitempty"` }
MetroSceneInfo
func (MetroSceneInfo) Clone ¶
func (o MetroSceneInfo) Clone() *MetroSceneInfo
func (MetroSceneInfo) MarshalJSON ¶
func (o MetroSceneInfo) MarshalJSON() ([]byte, error)
func (MetroSceneInfo) String ¶
func (o MetroSceneInfo) String() string
type OrderAmount ¶
type OrderAmount struct { // 订单总金额,单位为分,只能为整数,详见支付金额 Total *int64 `json:"total"` // 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY Currency *string `json:"currency,omitempty"` }
OrderAmount
func (OrderAmount) Clone ¶
func (o OrderAmount) Clone() *OrderAmount
func (OrderAmount) MarshalJSON ¶
func (o OrderAmount) MarshalJSON() ([]byte, error)
func (OrderAmount) String ¶
func (o OrderAmount) String() string
type PromotionDetail ¶
type PromotionDetail struct { // 券或者立减优惠ID CouponId *string `json:"coupon_id"` // 优惠名称 Name *string `json:"name,omitempty"` // GLOBAL-全场代金券,SINGLE-单品优惠 Scope *string `json:"scope,omitempty"` // 优惠类型,枚举值有: Type *PromotionType `json:"type,omitempty"` // 在微信商户后台配置的批次ID StockId *string `json:"stock_id,omitempty"` // 用户享受优惠的金额 Amount *int64 `json:"amount"` // 特指由微信支付商户平台创建的优惠,出资金额等于本项优惠总金额,单位为分 WechatpayContribute *int64 `json:"wechatpay_contribute,omitempty"` // 特指商户自己创建的优惠,出资金额等于本项优惠总金额,单位为分 MerchantContribute *int64 `json:"merchant_contribute,omitempty"` // 其他出资方出资金额,单位为分 OtherContribute *int64 `json:"other_contribute,omitempty"` // CNY:人民币,境内商户号仅支持人民币。 Currency *string `json:"currency,omitempty"` }
PromotionDetail
func (PromotionDetail) Clone ¶
func (o PromotionDetail) Clone() *PromotionDetail
func (PromotionDetail) MarshalJSON ¶
func (o PromotionDetail) MarshalJSON() ([]byte, error)
func (PromotionDetail) String ¶
func (o PromotionDetail) String() string
type PromotionType ¶
type PromotionType string
PromotionType
const ( PROMOTIONTYPE_CASH PromotionType = "CASH" PROMOTIONTYPE_NOCASH PromotionType = "NOCASH" )
Enums of PromotionType
func (PromotionType) Ptr ¶
func (e PromotionType) Ptr() *PromotionType
type QueryOrderAmount ¶
type QueryOrderAmount struct { // 订单总金额,单位为分,只能为整数,详见支付金额 Total *int64 `json:"total,omitempty"` // 用户实际支付金额,单位为分,只能为整数,详见支付金额 PayerTotal *int64 `json:"payer_total,omitempty"` // CNY:人民币,境内商户号仅支持人民币。 Currency *string `json:"currency,omitempty"` }
QueryOrderAmount
func (QueryOrderAmount) Clone ¶
func (o QueryOrderAmount) Clone() *QueryOrderAmount
func (QueryOrderAmount) MarshalJSON ¶
func (o QueryOrderAmount) MarshalJSON() ([]byte, error)
func (QueryOrderAmount) String ¶
func (o QueryOrderAmount) String() string
type QueryTransactionRequest ¶
type QueryTransactionRequest struct { // 商户系统内部订单号,只能是数字、大小写字母,且在同一个商户号下唯一。该字段长度限制为字节长度限制 OutTradeNo *string `json:"out_trade_no"` // 微信支付分配的子商户号,服务商模式下必传 SubMchid *string `json:"sub_mchid,omitempty"` }
QueryTransactionRequest
func (QueryTransactionRequest) Clone ¶
func (o QueryTransactionRequest) Clone() *QueryTransactionRequest
func (QueryTransactionRequest) MarshalJSON ¶
func (o QueryTransactionRequest) MarshalJSON() ([]byte, error)
func (QueryTransactionRequest) String ¶
func (o QueryTransactionRequest) String() string
type QueryUserServiceRequest ¶
type QueryUserServiceRequest struct { // 商户在微信申请公众号或移动应用成功后分配的账号ID,登录平台为mp.weixin.qq.com或open.weixin.qq.com Appid *string `json:"appid"` // 子公众账号ID,服务商模式下选传 SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的子商户号,服务商模式下必传 SubMchid *string `json:"sub_mchid,omitempty"` // 签约成功后,微信返回代扣签约ID 查用户是否能继续使用乘车卡时必传 ContractId *string `json:"contract_id"` }
QueryUserServiceRequest
func (QueryUserServiceRequest) Clone ¶
func (o QueryUserServiceRequest) Clone() *QueryUserServiceRequest
func (QueryUserServiceRequest) MarshalJSON ¶
func (o QueryUserServiceRequest) MarshalJSON() ([]byte, error)
func (QueryUserServiceRequest) String ¶
func (o QueryUserServiceRequest) String() string
type TradeScene ¶
type TradeScene string
TradeScene
const ( TRADESCENE_BUS TradeScene = "BUS" TRADESCENE_METRO TradeScene = "METRO" )
Enums of TradeScene
func (TradeScene) Ptr ¶
func (e TradeScene) Ptr() *TradeScene
type TradeState ¶
type TradeState string
TradeState
const ( TRADESTATE_SUCCESS TradeState = "SUCCESS" TRADESTATE_ACCEPTED TradeState = "ACCEPTED" TRADESTATE_PAY_FAIL TradeState = "PAY_FAIL" TRADESTATE_REFUND TradeState = "REFUND" )
Enums of TradeState
func (TradeState) Ptr ¶
func (e TradeState) Ptr() *TradeState
type TransactionsApiService ¶
func (*TransactionsApiService) CreateTransaction ¶
func (a *TransactionsApiService) CreateTransaction(ctx context.Context, req CreateTransactionRequest) (resp *TransactionsEntity, result *core.APIResult, err error)
CreateTransaction 扣费受理
商户请求扣费受理接口,会完成订单受理。微信支付进行异步扣款,支付完成后,会将订单支付结果发送给商户。
Example ¶
package main import ( "context" "log" "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core/option" "github.com/wechatpay-apiv3/wechatpay-go/services/weixinpayscanandride" "github.com/wechatpay-apiv3/wechatpay-go/utils" ) func main() { var ( mchID string = "190000****" // 商户号 mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号 mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥 ) // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem") if err != nil { log.Printf("load merchant private key error:%s", err) return } ctx := context.Background() // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力 opts := []core.ClientOption{ option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key), } client, err := core.NewClient(ctx, opts...) if err != nil { log.Printf("new wechat pay client err:%s", err) return } svc := weixinpayscanandride.TransactionsApiService{Client: client} resp, result, err := svc.CreateTransaction(ctx, weixinpayscanandride.CreateTransactionRequest{ Appid: core.String("wxcbda96de0b165486"), SubAppid: core.String("wxcbda96de0b165486"), SubMchid: core.String("1900000109"), Description: core.String("地铁扣费"), Attach: core.String("深圳分店"), OutTradeNo: core.String("20150806125346"), TradeScene: weixinpayscanandride.TRADESCENE_BUS.Ptr(), GoodsTag: core.String("WXG"), ContractId: core.String("Wx15463511252015071056489715"), NotifyUrl: core.String("https://yoursite.com/wxpay.html"), Amount: &weixinpayscanandride.OrderAmount{ Total: core.Int64(600), Currency: core.String("CNY"), }, BusInfo: &weixinpayscanandride.BusSceneInfo{ StartTime: core.String("2017-08-26T10:43:39+08:00"), LineName: core.String("1路公车"), PlateNumber: core.String("粤B888888"), }, MetroInfo: &weixinpayscanandride.MetroSceneInfo{ StartTime: core.String("2017-08-26T10:43:39+08:00"), EndTime: core.String("2017-08-26T10:43:39+08:00"), StartStation: core.String("西单"), EndStation: core.String("天安门西"), }, }, ) if err != nil { // 处理错误 log.Printf("call CreateTransaction err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*TransactionsApiService) QueryTransaction ¶
func (a *TransactionsApiService) QueryTransaction(ctx context.Context, req QueryTransactionRequest) (resp *TransactionsEntity, result *core.APIResult, err error)
QueryTransaction 查询订单
商户通过商户订单号,来查询订单信息
Example ¶
package main import ( "context" "log" "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core/option" "github.com/wechatpay-apiv3/wechatpay-go/services/weixinpayscanandride" "github.com/wechatpay-apiv3/wechatpay-go/utils" ) func main() { var ( mchID string = "190000****" // 商户号 mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号 mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥 ) // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem") if err != nil { log.Printf("load merchant private key error:%s", err) return } ctx := context.Background() // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力 opts := []core.ClientOption{ option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key), } client, err := core.NewClient(ctx, opts...) if err != nil { log.Printf("new wechat pay client err:%s", err) return } svc := weixinpayscanandride.TransactionsApiService{Client: client} resp, result, err := svc.QueryTransaction(ctx, weixinpayscanandride.QueryTransactionRequest{ OutTradeNo: core.String("20150806125346"), SubMchid: core.String("1900000109"), }, ) if err != nil { // 处理错误 log.Printf("call QueryTransaction err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type TransactionsEntity ¶
type TransactionsEntity struct { // 商户在微信申请公众号或移动应用成功后分配的账号ID,登录平台为mp.weixin.qq.com或open.weixin.qq.com Appid *string `json:"appid"` // 子商户申请的公众号或移动应用AppID,需要在服务商的商户平台为子商户绑定 SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的商户号 SpMchid *string `json:"sp_mchid"` // 微信支付分配的子商户号 SubMchid *string `json:"sub_mchid,omitempty"` // 商户自定义字段,用于交易账单中对扣费服务的描述。 Description *string `json:"description"` // 订单成功创建时返回,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE CreateTime *string `json:"create_time"` // 商户系统内部订单号,只能是数字、大小写字母,且在同一个商户号下唯一 OutTradeNo *string `json:"out_trade_no"` // 微信支付订单号 TransactionId *string `json:"transaction_id,omitempty"` // 交易状态,枚举值: TradeState *TradeState `json:"trade_state"` // 对当前订单状态的描述和下一步操作的指引 TradeStateDescription *string `json:"trade_state_description,omitempty"` // 订单支付完成时间,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE SuccessTime *string `json:"success_time,omitempty"` // 银行类型,采用字符串类型的银行标识,详细可参考 微信支付银行类型标识(https://pay.weixin.qq.com/wiki/doc/apiv3/terms_definition/chapter1_1_3.shtml)。 特殊标识 BPA:该笔订单由微信进行垫付 BankType *string `json:"bank_type,omitempty"` // 该字段标识对应的垫资单是否已还款或者已撤销。注意,使用此字段前需先确认bank_type字段值为BPA 以及 trade_state字段值为SUCCESS或者REFUND。枚举值如下: UserRepayState *UserRepayState `json:"user_repay_state,omitempty"` // 用户还款成功的微信支付订单号。用户已还款会返回该字段。 RepayTransactionId *string `json:"repay_transaction_id,omitempty"` // 垫资还款时间,该笔订单发生过垫资,并且用户还款成功后,会返回该字段信息,按照使用rfc3339所定义的格式,格式为yyyy-MM-DDThh:mm:ss+TIMEZONE RepayTime *string `json:"repay_time,omitempty"` // 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用 Attach *string `json:"attach,omitempty"` // 签约成功后,微信返回的代扣签约ID ContractId *string `json:"contract_id,omitempty"` // 交易场景值,枚举值: TradeScene *TradeScene `json:"trade_scene"` // 返回信息中的trade_scene为BUS,返回该场景信息 BusInfo *BusSceneInfo `json:"bus_info,omitempty"` // 返回信息中的trade_scene为METRO,返回该场景信息 MetroInfo *MetroSceneInfo `json:"metro_info,omitempty"` // 订单金额信息 Amount *QueryOrderAmount `json:"amount"` // 优惠信息 PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"` }
TransactionsEntity
func (TransactionsEntity) Clone ¶
func (o TransactionsEntity) Clone() *TransactionsEntity
func (TransactionsEntity) MarshalJSON ¶
func (o TransactionsEntity) MarshalJSON() ([]byte, error)
func (TransactionsEntity) String ¶
func (o TransactionsEntity) String() string
type UserRepayState ¶
type UserRepayState string
UserRepayState
const ( USERREPAYSTATE_NOT_REPAY UserRepayState = "NOT_REPAY" USERREPAYSTATE_REPAID UserRepayState = "REPAID" USERREPAYSTATE_ALL_REFUND UserRepayState = "ALL_REFUND" )
Enums of UserRepayState
func (UserRepayState) Ptr ¶
func (e UserRepayState) Ptr() *UserRepayState
type UserServiceEntity ¶
type UserServiceEntity struct { // 签约成功后,微信返回代扣签约ID ContractId *string `json:"contract_id"` // 用户服务可用状态,枚举值有: UserServiceState *UserServiceStateEnum `json:"user_service_state"` // blocked服务状态描述,返回用户状态为BLOCKED,会返回该字段,具体描述的枚举值如下: BlockReason *BlockReasonEnum `json:"block_reason,omitempty"` }
UserServiceEntity
func (UserServiceEntity) Clone ¶
func (o UserServiceEntity) Clone() *UserServiceEntity
func (UserServiceEntity) MarshalJSON ¶
func (o UserServiceEntity) MarshalJSON() ([]byte, error)
func (UserServiceEntity) String ¶
func (o UserServiceEntity) String() string
type UserServiceStateEnum ¶
type UserServiceStateEnum string
UserServiceStateEnum
const ( USERSERVICESTATEENUM_NORMAL UserServiceStateEnum = "NORMAL" USERSERVICESTATEENUM_BLOCKED UserServiceStateEnum = "BLOCKED" )
Enums of UserServiceStateEnum
func (UserServiceStateEnum) Ptr ¶
func (e UserServiceStateEnum) Ptr() *UserServiceStateEnum
type UserServicesApiService ¶
func (*UserServicesApiService) QueryUserService ¶
func (a *UserServicesApiService) QueryUserService(ctx context.Context, req QueryUserServiceRequest) (resp *UserServiceEntity, result *core.APIResult, err error)
QueryUserService 查询用户服务可用信息
在商户生成乘车码前,商户请求查询用户服务可用信息接口,查询 用户服务可用信息,通过用户服务可用信息中的服务可用状态,来判断是否可以正常使用公共出行代扣服务
Example ¶
package main import ( "context" "log" "github.com/wechatpay-apiv3/wechatpay-go/core" "github.com/wechatpay-apiv3/wechatpay-go/core/option" "github.com/wechatpay-apiv3/wechatpay-go/services/weixinpayscanandride" "github.com/wechatpay-apiv3/wechatpay-go/utils" ) func main() { var ( mchID string = "190000****" // 商户号 mchCertificateSerialNumber string = "3775************************************" // 商户证书序列号 mchAPIv3Key string = "2ab9****************************" // 商户APIv3密钥 ) // 使用 utils 提供的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 mchPrivateKey, err := utils.LoadPrivateKeyWithPath("/path/to/merchant/apiclient_key.pem") if err != nil { log.Printf("load merchant private key error:%s", err) return } ctx := context.Background() // 使用商户私钥等初始化 client,并使它具有自动定时获取微信支付平台证书的能力 opts := []core.ClientOption{ option.WithWechatPayAutoAuthCipher(mchID, mchCertificateSerialNumber, mchPrivateKey, mchAPIv3Key), } client, err := core.NewClient(ctx, opts...) if err != nil { log.Printf("new wechat pay client err:%s", err) return } svc := weixinpayscanandride.UserServicesApiService{Client: client} resp, result, err := svc.QueryUserService(ctx, weixinpayscanandride.QueryUserServiceRequest{ Appid: core.String("wxcbda96de0b165486"), SubAppid: core.String("wxcbda96de0b165486"), SubMchid: core.String("1900000109"), ContractId: core.String("Wx15463511252015071056489715"), }, ) if err != nil { // 处理错误 log.Printf("call QueryUserService err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output: