wexinpayscoreparking

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CreateParkingRequest

type CreateParkingRequest struct {
	// 微信支付分配的子商户号,服务商模式下必传
	SubMchid *string `json:"sub_mchid,omitempty"`
	// 商户侧入场标识id,在同一个商户号下唯一
	OutParkingNo *string `json:"out_parking_no"`
	// 车牌号,仅包括省份+车牌,不包括特殊字符。
	PlateNumber *string `json:"plate_number"`
	// 车牌颜色
	PlateColor *PlateColor `json:"plate_color"`
	// 接受入场状态变更回调通知的url,注意回调url只接受https
	NotifyUrl *string `json:"notify_url"`
	// 入场时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	StartTime *time.Time `json:"start_time"`
	// 所在停车位车场的名称
	ParkingName *string `json:"parking_name"`
	// 停车场的免费停车时长,单位为秒
	FreeDuration *int64 `json:"free_duration"`
}

CreateParkingRequest

func (CreateParkingRequest) Clone

func (CreateParkingRequest) MarshalJSON

func (o CreateParkingRequest) MarshalJSON() ([]byte, error)

func (CreateParkingRequest) String

func (o CreateParkingRequest) String() string

type CreateTransactionRequest

type CreateTransactionRequest struct {
	// appid是商户在微信申请公众号或移动应用成功后分配的帐号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"`
	// 交易场景值,目前支持 :PARKING:车场停车场景
	TradeScene *string `json:"trade_scene"`
	// 代金券或立减优惠功能的参数,说明详见[代金券或立减优惠](https://pay.weixin.qq.com/wiki/doc/apiv3/open/pay/chapter5_1_2.shtml)
	GoodsTag *string `json:"goods_tag,omitempty"`
	// 接受扣款结果异步回调通知的url,注意回调url只接受https
	NotifyUrl *string `json:"notify_url"`
	// Y:是,需要分账 N:否,不分账 字母要求大写,不传默认不分账,分账详细说明见[直连分账API](https://pay.weixin.qq.com/wiki/doc/api/allocation.php?chapter=26_1)、[服务商分账API文档](https://pay.weixin.qq.com/wiki/doc/api/allocation_sl.php?chapter=24_1&index=1)
	ProfitSharing *string `json:"profit_sharing,omitempty"`
	// 订单金额信息
	Amount *OrderAmount `json:"amount"`
	// 当交易场景为PARKING时,需要在该字段添加停车场景信息
	ParkingInfo *ParkingTradeScene `json:"parking_info,omitempty"`
}

CreateTransactionRequest

func (CreateTransactionRequest) Clone

func (CreateTransactionRequest) MarshalJSON

func (o CreateTransactionRequest) MarshalJSON() ([]byte, error)

func (CreateTransactionRequest) String

func (o CreateTransactionRequest) 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 Parking

type Parking struct {
	// 车主服务为商户分配的入场id
	Id *string `json:"id"`
	// 商户侧入场标识id,在同一个商户号下唯一
	OutParkingNo *string `json:"out_parking_no"`
	// 车牌号,仅包括省份+车牌,不包括特殊字符。
	PlateNumber *string `json:"plate_number"`
	// 车牌颜色
	PlateColor *PlateColor `json:"plate_color"`
	// 入场时间,按照使用rfc3339所定义的格式,格式为YYYY-MM-DDThh:mm:ss+TIMEZONE
	StartTime *string `json:"start_time"`
	// 所在停车位车场的名称
	ParkingName *string `json:"parking_name"`
	// 停车场的免费停车时长,单位为秒
	FreeDuration *int64 `json:"free_duration"`
	// 本次入场车牌的服务状态, NORMAL:正常状态,可以使用微信支付分停车服务, BLOCKED 不可用状态,暂时不可以使用微信支付分停车服务
	State *string `json:"state"`
	// block服务状态描述,返回车牌状态为BLOCKED,会返回该字段,描述具体BLOCKED的原因, PAUSE:已暂停微信支付分停车服务; OVERDUE:已授权签约但欠费,不能提供服务, OUT_SERVICE : 车牌未开通微信支付分停车服务, EVALUATION_FAILED 综合评估未通过,用户支付分不可用的情况,会返回该状态。
	BlockReason *string `json:"block_reason,omitempty"`
}

Parking

func (Parking) Clone

func (o Parking) Clone() *Parking

func (Parking) MarshalJSON

func (o Parking) MarshalJSON() ([]byte, error)

func (Parking) String

func (o Parking) String() string

type ParkingTradeScene

type ParkingTradeScene struct {
	// 微信支付分停车服务为商户分配的入场id,商户通过入场通知接口获取入场id
	ParkingId *string `json:"parking_id"`
	// 车牌号,仅包括省份+车牌,不包括特殊字符。
	PlateNumber *string `json:"plate_number"`
	// 车牌颜色
	PlateColor *PlateColor `json:"plate_color"`
	// 用户入场时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	StartTime *time.Time `json:"start_time"`
	// 用户出场时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	EndTime *time.Time `json:"end_time"`
	// 所在停车位车场的名称
	ParkingName *string `json:"parking_name"`
	// 计费的时间长,单位为秒
	ChargingDuration *int64 `json:"charging_duration"`
	// 停车场设备id
	DeviceId *string `json:"device_id"`
}

ParkingTradeScene

func (ParkingTradeScene) Clone

func (ParkingTradeScene) MarshalJSON

func (o ParkingTradeScene) MarshalJSON() ([]byte, error)

func (ParkingTradeScene) String

func (o ParkingTradeScene) String() string

type ParkingsApiService

type ParkingsApiService services.Service

func (*ParkingsApiService) CreateParking

func (a *ParkingsApiService) CreateParking(ctx context.Context, req CreateParkingRequest) (resp *Parking, result *core.APIResult, err error)

CreateParking 创建停车入场

车辆入场以后,商户调用该接口,创建停车入场信息。

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/rjm521/wechatpay-go/core"
	"github.com/rjm521/wechatpay-go/core/option"
	"github.com/rjm521/wechatpay-go/services/wexinpayscoreparking"
	"github.com/rjm521/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 := wexinpayscoreparking.ParkingsApiService{Client: client}
	resp, result, err := svc.CreateParking(ctx,
		wexinpayscoreparking.CreateParkingRequest{
			SubMchid:     core.String("1900000109"),
			OutParkingNo: core.String("1231243"),
			PlateNumber:  core.String("粤B888888"),
			PlateColor:   wexinpayscoreparking.PLATECOLOR_BLUE.Ptr(),
			NotifyUrl:    core.String("https://yoursite.com/wxpay.html"),
			StartTime:    core.Time(time.Now()),
			ParkingName:  core.String("欢乐海岸停车场"),
			FreeDuration: core.Int64(3600),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call CreateParking err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}
Output:

type Payer

type Payer struct {
	// 用户在appid下的唯一标识
	Openid *string `json:"openid"`
	// 用户在sub_appid下的标识,商户扣费时传入了sub_appid,则会返回该用户在sub_appid下的标识
	SubOpenid *string `json:"sub_openid,omitempty"`
}

Payer

func (Payer) Clone

func (o Payer) Clone() *Payer

func (Payer) MarshalJSON

func (o Payer) MarshalJSON() ([]byte, error)

func (Payer) String

func (o Payer) String() string

type PlateColor

type PlateColor string

PlateColor

const (
	PLATECOLOR_BLUE      PlateColor = "BLUE"
	PLATECOLOR_GREEN     PlateColor = "GREEN"
	PLATECOLOR_YELLOW    PlateColor = "YELLOW"
	PLATECOLOR_BLACK     PlateColor = "BLACK"
	PLATECOLOR_WHITE     PlateColor = "WHITE"
	PLATECOLOR_LIMEGREEN PlateColor = "LIMEGREEN"
)

Enums of PlateColor

func (PlateColor) Ptr

func (e PlateColor) Ptr() *PlateColor

type PlateService

type PlateService struct {
	// 车牌号,仅包括省份+车牌,不包括特殊字符。
	PlateNumber *string `json:"plate_number"`
	// 车牌颜色
	PlateColor *PlateColor `json:"plate_color"`
	// 车牌服务开通时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	ServiceOpenTime *time.Time `json:"service_open_time,omitempty"`
	// 用户在商户对应appid下的唯一标识,此处返回商户请求中的openid
	Openid *string `json:"openid"`
	// 车牌服务开通状态, NORMAL 正常服务 PAUSE 暂停服务 OUT_SERVICE 未开通 商户根据状态带用户跳转至对应的微信支付分停车服务小程序页面。 其中NORMAL 和 PAUSE状态,可跳转至车牌管理页,进行车牌服务状态管理。OUT_SERVICE状态,可跳转至服务开通页面。
	ServiceState *string `json:"service_state"`
}

PlateService

func (PlateService) Clone

func (o PlateService) Clone() *PlateService

func (PlateService) MarshalJSON

func (o PlateService) MarshalJSON() ([]byte, error)

func (PlateService) String

func (o PlateService) 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"`
	// 枚举值: CASH:充值型代金券 NOCASH:免充值型代金券
	Type *string `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 QueryOrderAmount

type QueryOrderAmount struct {
	// 订单总金额,单位为分,只能为整数,详见支付金额
	Total *int64 `json:"total"`
	// 符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY
	Currency *string `json:"currency,omitempty"`
	// 用户实际支付金额,单位为分,只能为整数,详见支付金额
	PayerTotal *int64 `json:"payer_total,omitempty"`
	// 订单折扣
	DiscountTotal *int64 `json:"discount_total,omitempty"`
}

QueryOrderAmount

func (QueryOrderAmount) Clone

func (QueryOrderAmount) MarshalJSON

func (o QueryOrderAmount) MarshalJSON() ([]byte, error)

func (QueryOrderAmount) String

func (o QueryOrderAmount) String() string

type QueryPlateServiceRequest

type QueryPlateServiceRequest struct {
	// appid是商户在微信申请公众号或移动应用成功后分配的帐号ID,登录平台为mp.weixin.qq.com或open.weixin.qq.com
	Appid *string `json:"appid"`
	// 微信支付分配的子商户号,服务商模式下必传
	SubMchid *string `json:"sub_mchid,omitempty"`
	// 车牌号,仅包括省份+车牌,不包括特殊字符。
	PlateNumber *string `json:"plate_number"`
	// 用户在商户对应appid下的唯一标识
	Openid *string `json:"openid"`
	// 车牌颜色
	PlateColor *PlateColor `json:"plate_color"`
}

QueryPlateServiceRequest

func (QueryPlateServiceRequest) Clone

func (QueryPlateServiceRequest) MarshalJSON

func (o QueryPlateServiceRequest) MarshalJSON() ([]byte, error)

func (QueryPlateServiceRequest) String

func (o QueryPlateServiceRequest) String() string

type QueryTransactionRequest

type QueryTransactionRequest struct {
	// 微信支付分配的子商户号,服务商模式下必传
	SubMchid *string `json:"sub_mchid,omitempty"`
	// 商户系统内部订单号,只能是数字、大小写字母,且在同一个商户号下唯一
	OutTradeNo *string `json:"out_trade_no"`
}

QueryTransactionRequest

func (QueryTransactionRequest) Clone

func (QueryTransactionRequest) MarshalJSON

func (o QueryTransactionRequest) MarshalJSON() ([]byte, error)

func (QueryTransactionRequest) String

func (o QueryTransactionRequest) String() string

type ServicesApiService

type ServicesApiService services.Service

func (*ServicesApiService) QueryPlateService

func (a *ServicesApiService) QueryPlateService(ctx context.Context, req QueryPlateServiceRequest) (resp *PlateService, result *core.APIResult, err error)

QueryPlateService 查询车牌服务开通信息

该接口仅支持停车场景,商户首先请求查询车牌服务开通信息接口,确认该车牌,是否被该用户开通车主服务,以及车牌具体服务开通状态,包括正常服务,和暂停服务,以及未开通三个状态。

Example
package main

import (
	"context"
	"log"

	"github.com/rjm521/wechatpay-go/core"
	"github.com/rjm521/wechatpay-go/core/option"
	"github.com/rjm521/wechatpay-go/services/wexinpayscoreparking"
	"github.com/rjm521/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 := wexinpayscoreparking.ServicesApiService{Client: client}
	resp, result, err := svc.QueryPlateService(ctx,
		wexinpayscoreparking.QueryPlateServiceRequest{
			Appid:       core.String("wxcbda96de0b165486"),
			SubMchid:    core.String("1900000109"),
			PlateNumber: core.String("粤B888888"),
			Openid:      core.String("oUpF8uMuAJOM2pxb1Q"),
			PlateColor:  wexinpayscoreparking.PLATECOLOR_BLUE.Ptr(),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call QueryPlateService err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}
Output:

type Transaction

type Transaction struct {
	// appid是商户在微信申请公众号或移动应用成功后分配的帐号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](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	CreateTime *time.Time `json:"create_time"`
	// 商户系统内部订单号,只能是数字、大小写字母_-*且在同一个商户号下唯一
	OutTradeNo *string `json:"out_trade_no"`
	// 微信支付订单号
	TransactionId *string `json:"transaction_id,omitempty"`
	// SUCCESS—支付成功 ACCEPTED—已接收,等待扣款 PAY_FAIL–支付失败(其他原因,如银行返回失败) REFUND—转入退款
	TradeState *string `json:"trade_state"`
	// 对当前订单状态的描述和下一步操作的指引
	TradeStateDescription *string `json:"trade_state_description,omitempty"`
	// 订单支付完成时间,遵循[rfc3339](https://datatracker.ietf.org/doc/html/rfc3339)标准格式,格式为yyyy-MM-DDTHH:mm:ss+TIMEZONE,yyyy-MM-DD表示年月日,T出现在字符串中,表示time元素的开头,HH:mm:ss表示时分秒,TIMEZONE表示时区(+08:00表示东八区时间,领先UTC 8小时,即北京时间)。例如:2015-05-20T13:29:35+08:00表示,北京时间2015年5月20日 13点29分35秒。
	SuccessTime *time.Time `json:"success_time,omitempty"`
	// 银行类型,采用字符串类型的银行标识。BPA:该笔订单由微信进行垫付
	BankType *string `json:"bank_type,omitempty"`
	// 枚举值: Y:用户已还款 N:用户未还款 注意:使用此字段前需先确认bank_type字段值为BPA以及 trade_state字段值为SUCCESS。
	UserRepaid *string `json:"user_repaid,omitempty"`
	// 附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用
	Attach *string `json:"attach,omitempty"`
	// 交易场景值,目前支持 :PARKING:车场停车场景
	TradeScene *string `json:"trade_scene"`
	// 返回信息中的trade_scene为PARKING,返回该场景信息
	ParkingInfo *ParkingTradeScene `json:"parking_info,omitempty"`
	// 支付者信息
	Payer *Payer `json:"payer"`
	// 订单金额信息
	Amount *QueryOrderAmount `json:"amount"`
	// 优惠信息
	PromotionDetail []PromotionDetail `json:"promotion_detail,omitempty"`
}

Transaction

func (Transaction) Clone

func (o Transaction) Clone() *Transaction

func (Transaction) MarshalJSON

func (o Transaction) MarshalJSON() ([]byte, error)

func (Transaction) String

func (o Transaction) String() string

type TransactionsApiService

type TransactionsApiService services.Service

func (*TransactionsApiService) CreateTransaction

func (a *TransactionsApiService) CreateTransaction(ctx context.Context, req CreateTransactionRequest) (resp *Transaction, result *core.APIResult, err error)

CreateTransaction 扣费受理

商户请求扣费受理接口,会完成订单受理。微信支付进行异步扣款,支付完成后,会将订单支付结果发送给商户。

Example
package main

import (
	"context"
	"log"
	"time"

	"github.com/rjm521/wechatpay-go/core"
	"github.com/rjm521/wechatpay-go/core/option"
	"github.com/rjm521/wechatpay-go/services/wexinpayscoreparking"
	"github.com/rjm521/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 := wexinpayscoreparking.TransactionsApiService{Client: client}
	resp, result, err := svc.CreateTransaction(ctx,
		wexinpayscoreparking.CreateTransactionRequest{
			Appid:         core.String("wxcbda96de0b165486"),
			SubAppid:      core.String("wxcbda96de0b165486"),
			SubMchid:      core.String("1900000109"),
			Description:   core.String("停车场扣费"),
			Attach:        core.String("深圳分店"),
			OutTradeNo:    core.String("20150806125346"),
			TradeScene:    core.String("PARKING"),
			GoodsTag:      core.String("WXG"),
			NotifyUrl:     core.String("https://yoursite.com/wxpay.html"),
			ProfitSharing: core.String("Y"),
			Amount: &wexinpayscoreparking.OrderAmount{
				Total:    core.Int64(888),
				Currency: core.String("CNY"),
			},
			ParkingInfo: &wexinpayscoreparking.ParkingTradeScene{
				ParkingId:        core.String("5K8264ILTKCH16CQ250"),
				PlateNumber:      core.String("粤B888888"),
				PlateColor:       wexinpayscoreparking.PLATECOLOR_BLUE.Ptr(),
				StartTime:        core.Time(time.Now()),
				EndTime:          core.Time(time.Now()),
				ParkingName:      core.String("欢乐海岸停车场"),
				ChargingDuration: core.Int64(3600),
				DeviceId:         core.String("12313"),
			},
		},
	)

	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 *Transaction, result *core.APIResult, err error)

QueryTransaction 查询订单

商户通过商户订单号,来查询订单信息

Example
package main

import (
	"context"
	"log"

	"github.com/rjm521/wechatpay-go/core"
	"github.com/rjm521/wechatpay-go/core/option"
	"github.com/rjm521/wechatpay-go/services/wexinpayscoreparking"
	"github.com/rjm521/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 := wexinpayscoreparking.TransactionsApiService{Client: client}
	resp, result, err := svc.QueryTransaction(ctx,
		wexinpayscoreparking.QueryTransactionRequest{
			SubMchid:   core.String("1900000109"),
			OutTradeNo: core.String("20150806125346"),
		},
	)

	if err != nil {
		// 处理错误
		log.Printf("call QueryTransaction err:%s", err)
	} else {
		// 处理返回结果
		log.Printf("status=%d resp=%s", result.Response.StatusCode, resp)
	}
}
Output:

Jump to

Keyboard shortcuts

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