Documentation ¶
Index ¶
- type AddReceiverRequest
- type AddReceiverResponse
- type BillShipmentApiService
- type CreateOrderReceiver
- type CreateOrderRequest
- type CreateReturnOrderRequest
- type DeleteReceiverRequest
- type DeleteReceiverResponse
- type DetailFailReason
- type DetailStatus
- type MerchantsApiService
- type OrderReceiverDetail
- type OrderStatus
- type OrdersApiService
- func (a *OrdersApiService) CreateOrder(ctx context.Context, req CreateOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
- func (a *OrdersApiService) QueryOrder(ctx context.Context, req QueryOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
- func (a *OrdersApiService) UnfreezeOrder(ctx context.Context, req UnfreezeOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
- type OrdersEntity
- type QueryMerchantRatioRequest
- type QueryMerchantRatioResponse
- type QueryOrderAmountRequest
- type QueryOrderAmountResponse
- type QueryOrderRequest
- type QueryReturnOrderRequest
- type ReceiverRelationType
- type ReceiverType
- type ReceiversApiService
- func (a *ReceiversApiService) AddReceiver(ctx context.Context, req AddReceiverRequest) (resp *AddReceiverResponse, result *core.APIResult, err error)
- func (a *ReceiversApiService) DeleteReceiver(ctx context.Context, req DeleteReceiverRequest) (resp *DeleteReceiverResponse, result *core.APIResult, err error)
- type ReturnOrderFailReason
- type ReturnOrderStatus
- type ReturnOrdersApiService
- func (a *ReturnOrdersApiService) CreateReturnOrder(ctx context.Context, req CreateReturnOrderRequest) (resp *ReturnOrdersEntity, result *core.APIResult, err error)
- func (a *ReturnOrdersApiService) QueryReturnOrder(ctx context.Context, req QueryReturnOrderRequest) (resp *ReturnOrdersEntity, result *core.APIResult, err error)
- type ReturnOrdersEntity
- type SplitBillHashType
- type SplitBillRequest
- type SplitBillResponse
- type SplitBillTarType
- type TransactionsApiService
- type UnfreezeOrderRequest
Examples ¶
- BillShipmentApiService.SplitBill
- MerchantsApiService.QueryMerchantRatio
- OrdersApiService.CreateOrder
- OrdersApiService.QueryOrder
- OrdersApiService.UnfreezeOrder
- ReceiversApiService.AddReceiver
- ReceiversApiService.DeleteReceiver
- ReturnOrdersApiService.CreateReturnOrder
- ReturnOrdersApiService.QueryReturnOrder
- TransactionsApiService.QueryOrderAmount
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddReceiverRequest ¶
type AddReceiverRequest struct { // 类型是MERCHANT_ID时,是商户号 类型是PERSONAL_OPENID时,是个人openid 类型是PERSONAL_SUB_OPENID时,是个人sub_openid Account *string `json:"account"` // 微信分配的公众账号ID Appid *string `json:"appid"` // 子商户与接收方具体的关系,本字段最多10个字。 当字段relation_type的值为CUSTOM时,本字段必填 当字段relation_type的值不为CUSTOM时,本字段无需填写 CustomRelation *string `json:"custom_relation,omitempty"` // 分账接收方类型是MERCHANT_ID时,是商户全称(必传),当商户是小微商户或个体户时,是开户人姓名 分账接收方类型是PERSONAL_OPENID时,是个人姓名(选传,传则校验) 分账接收方类型是PERSONAL_SUB_OPENID时,是个人姓名(选传,传则校验) 1、此字段需要加密,的加密方法详见:敏感信息加密说明 2、使用微信支付平台证书中的公钥 3、使用RSAES-OAEP算法进行加密 4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号 Name *string `json:"name,omitempty" encryption:"EM_APIV3"` // 子商户与接收方的关系。 本字段值为枚举: SERVICE_PROVIDER:服务商 STORE:门店 STAFF:员工 STORE_OWNER:店主 PARTNER:合作伙伴 HEADQUARTER:总部 BRAND:品牌方 DISTRIBUTOR:分销商 USER:用户 SUPPLIER:供应商 CUSTOM:自定义 * `SERVICE_PROVIDER` - 服务商, * `STORE` - 门店, * `STAFF` - 员工, * `STORE_OWNER` - 店主, * `PARTNER` - 合作伙伴, * `HEADQUARTER` - 总部, * `BRAND` - 品牌方, * `DISTRIBUTOR` - 分销商, * `USER` - 用户, * `SUPPLIER` - 供应商, * `CUSTOM` - 自定义, RelationType *ReceiverRelationType `json:"relation_type"` // 子商户的公众账号ID,分账接收方类型包含PERSONAL_SUB_OPENID时必填。(直连商户不需要,服务商需要) SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 枚举值: MERCHANT_ID:商户ID PERSONAL_OPENID:个人openid(由父商户APPID转换得到) PERSONAL_SUB_OPENID:个人sub_openid(由子商户APPID转换得到) * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要), Type *ReceiverType `json:"type"` }
AddReceiverRequest
func (AddReceiverRequest) Clone ¶
func (o AddReceiverRequest) Clone() *AddReceiverRequest
func (AddReceiverRequest) MarshalJSON ¶
func (o AddReceiverRequest) MarshalJSON() ([]byte, error)
func (AddReceiverRequest) String ¶
func (o AddReceiverRequest) String() string
type AddReceiverResponse ¶
type AddReceiverResponse struct { // 参考请求参数 Account *string `json:"account"` // 参考请求参数 CustomRelation *string `json:"custom_relation,omitempty"` // 参考请求参数。使用APIv3敏感信息加密方式 Name *string `json:"name,omitempty" encryption:"EM_APIV3"` // 参考请求参数 * `SERVICE_PROVIDER` - 服务商, * `STORE` - 门店, * `STAFF` - 员工, * `STORE_OWNER` - 店主, * `PARTNER` - 合作伙伴, * `HEADQUARTER` - 总部, * `BRAND` - 品牌方, * `DISTRIBUTOR` - 分销商, * `USER` - 用户, * `SUPPLIER` - 供应商, * `CUSTOM` - 自定义, RelationType *ReceiverRelationType `json:"relation_type"` // 参考请求参数 SubMchid *string `json:"sub_mchid,omitempty"` // 参考请求参数 * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要), Type *ReceiverType `json:"type"` }
AddReceiverResponse
func (AddReceiverResponse) Clone ¶
func (o AddReceiverResponse) Clone() *AddReceiverResponse
func (AddReceiverResponse) MarshalJSON ¶
func (o AddReceiverResponse) MarshalJSON() ([]byte, error)
func (AddReceiverResponse) String ¶
func (o AddReceiverResponse) String() string
type BillShipmentApiService ¶
func (*BillShipmentApiService) SplitBill ¶
func (a *BillShipmentApiService) SplitBill(ctx context.Context, req SplitBillRequest) (resp *SplitBillResponse, result *core.APIResult, err error)
SplitBill 获取分账账单文件下载地址
下载接口说明: 微信支付按天提供分账账单文件,商户可以通过该接口获取账单文件的下载地址。文件内包含分账相关的金额、时间等信息,供商户核对到账等情况。 注意: - 微信侧未成功的分账单不会出现在对账单中。 - 对账单中涉及金额的字段单位为“元”; - 对账单接口只能下载三个月以内的账单。
文件格式说明: - 账单文件包括明细数据和汇总数据两部分,每一部分都包含一行表头和若干行具体数据。 - 明细数据每一行对应一笔分账或一笔回退,同时每一个数据前加入了字符`,以避免数据被Excel按科学计数法处理。如需汇总金额等数据,可以批量替换掉该字符。
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|日期格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用| |RATELIMIT_EXCEED|429|商户发起获取账单的频率过高|接口有频率限制|请降低频率后重试| |INVALID_REQUEST|400|服务商和分账方无受理关系|服务商和分账方无受理关系|请检查子商户号是否正确 |INVALID_REQUEST|400|请求的账单日期已过期|请求的账单日期已过期|请调整账单日期 |INVALID_REQUEST|400|请求的账单正在生成中|账单尚未生成|请确认账单时间是否正确,当日的账单会在次日上午10点以后可供下载 |NO_STATEMENT_EXIST|400|账单文件不存在|账单尚未生成|请确认账单时间是否正确,当日的账单会在次日上午10点以后可供下载
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.BillShipmentApiService{Client: client} resp, result, err := svc.SplitBill(ctx, profitsharing.SplitBillRequest{ BillDate: core.String("2019-06-11"), SubMchid: core.String("19000000001"), TarType: profitsharing.SPLITBILLTARTYPE_GZIP.Ptr(), }, ) if err != nil { // 处理错误 log.Printf("call SplitBill err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type CreateOrderReceiver ¶
type CreateOrderReceiver struct { // 1、类型是MERCHANT_ID时,是商户号 2、类型是PERSONAL_OPENID时,是个人openid 3、类型是PERSONAL_SUB_OPENID时,是个人sub_openid Account *string `json:"account"` // 分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额 Amount *int64 `json:"amount"` // 分账的原因描述,分账账单中需要体现 Description *string `json:"description"` // 可选项,在接收方类型为个人的时可选填,若有值,会检查与 name 是否实名匹配,不匹配会拒绝分账请求 1、分账接收方类型是PERSONAL_OPENID或PERSONAL_SUB_OPENID时,是个人姓名的密文(选传,传则校验) 此字段的加密的方式为:敏感信息加密说明 2、使用微信支付平台证书中的公钥 3、使用RSAES-OAEP算法进行加密 4、将请求中HTTP头部的Wechatpay-Serial设置为证书序列号 Name *string `json:"name,omitempty" encryption:"EM_APIV3"` // 1、MERCHANT_ID:商户号 2、PERSONAL_OPENID:个人openid(由父商户APPID转换得到) 3、PERSONAL_SUB_OPENID: 个人sub_openid(由子商户APPID转换得到) Type *string `json:"type"` }
CreateOrderReceiver
func (CreateOrderReceiver) Clone ¶
func (o CreateOrderReceiver) Clone() *CreateOrderReceiver
func (CreateOrderReceiver) MarshalJSON ¶
func (o CreateOrderReceiver) MarshalJSON() ([]byte, error)
func (CreateOrderReceiver) String ¶
func (o CreateOrderReceiver) String() string
type CreateOrderRequest ¶
type CreateOrderRequest struct { // 微信分配的服务商appid Appid *string `json:"appid"` // 服务商系统内部的分账单号,在服务商系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ OutOrderNo *string `json:"out_order_no"` // 分账接收方列表,可以设置出资商户作为分账接受方,最多可有50个分账接收方 Receivers []CreateOrderReceiver `json:"receivers,omitempty"` // 微信分配的子商户公众账号ID,分账接收方类型包含PERSONAL_SUB_OPENID时必填。(直连商户不需要,服务商需要) SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 微信支付订单号 TransactionId *string `json:"transaction_id"` // 1、如果为true,该笔订单剩余未分账的金额会解冻回分账方商户; 2、如果为false,该笔订单剩余未分账的金额不会解冻回分账方商户,可以对该笔订单再次进行分账。 UnfreezeUnsplit *bool `json:"unfreeze_unsplit"` }
CreateOrderRequest
func (CreateOrderRequest) Clone ¶
func (o CreateOrderRequest) Clone() *CreateOrderRequest
func (CreateOrderRequest) MarshalJSON ¶
func (o CreateOrderRequest) MarshalJSON() ([]byte, error)
func (CreateOrderRequest) String ¶
func (o CreateOrderRequest) String() string
type CreateReturnOrderRequest ¶
type CreateReturnOrderRequest struct { // 需要从分账接收方回退的金额,单位为分,只能为整数,不能超过原始分账单分出给该接收方的金额 Amount *int64 `json:"amount"` // 分账回退的原因描述 Description *string `json:"description"` // 微信分账单号,微信系统返回的唯一标识。微信分账单号和商户分账单号二选一填写 OrderId *string `json:"order_id,omitempty"` // 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。微信分账单号和商户分账单号二选一填写 取值范围:[0-9a-zA-Z_*@-] OutOrderNo *string `json:"out_order_no,omitempty"` // 此回退单号是商户在自己后台生成的一个新的回退单号,在商户后台唯一 OutReturnNo *string `json:"out_return_no"` // 分账回退的出资商户,只能对原分账请求中成功分给商户接收方进行回退 ReturnMchid *string `json:"return_mchid"` // 分账回退的接收商户,对应原分账出资的分账方商户,填写微信支付分配的商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` }
CreateReturnOrderRequest
func (CreateReturnOrderRequest) Clone ¶
func (o CreateReturnOrderRequest) Clone() *CreateReturnOrderRequest
func (CreateReturnOrderRequest) MarshalJSON ¶
func (o CreateReturnOrderRequest) MarshalJSON() ([]byte, error)
func (CreateReturnOrderRequest) String ¶
func (o CreateReturnOrderRequest) String() string
type DeleteReceiverRequest ¶
type DeleteReceiverRequest struct { // 类型是MERCHANT_ID时,是商户号 类型是PERSONAL_OPENID时,是个人openid 类型是PERSONAL_SUB_OPENID时,是个人sub_openid Account *string `json:"account"` // 微信分配的公众账号ID Appid *string `json:"appid"` // 微信分配的子商户公众账号ID,分账接收方类型包含PERSONAL_SUB_OPENID时必填。(直连商户不需要,服务商需要) SubAppid *string `json:"sub_appid,omitempty"` // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 枚举值: MERCHANT_ID:商户ID PERSONAL_OPENID:个人openid(由父商户APPID转换得到) PERSONAL_SUB_OPENID:个人sub_openid(由子商户APPID转换得到) * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要), Type *ReceiverType `json:"type"` }
DeleteReceiverRequest
func (DeleteReceiverRequest) Clone ¶
func (o DeleteReceiverRequest) Clone() *DeleteReceiverRequest
func (DeleteReceiverRequest) MarshalJSON ¶
func (o DeleteReceiverRequest) MarshalJSON() ([]byte, error)
func (DeleteReceiverRequest) String ¶
func (o DeleteReceiverRequest) String() string
type DeleteReceiverResponse ¶
type DeleteReceiverResponse struct { // 参考请求参数 Account *string `json:"account"` // 参考请求参数 SubMchid *string `json:"sub_mchid,omitempty"` // 参考请求参数 * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要), Type *ReceiverType `json:"type"` }
DeleteReceiverResponse
func (DeleteReceiverResponse) Clone ¶
func (o DeleteReceiverResponse) Clone() *DeleteReceiverResponse
func (DeleteReceiverResponse) MarshalJSON ¶
func (o DeleteReceiverResponse) MarshalJSON() ([]byte, error)
func (DeleteReceiverResponse) String ¶
func (o DeleteReceiverResponse) String() string
type DetailFailReason ¶
type DetailFailReason string
DetailFailReason * `ACCOUNT_ABNORMAL` - 分账接收账户异常, * `NO_RELATION` - 分账关系已解除, * `RECEIVER_HIGH_RISK` - 高风险接收方, * `RECEIVER_REAL_NAME_NOT_VERIFIED` - 接收方未实名, * `NO_AUTH` - 分账权限已解除,
const ( DETAILFAILREASON_ACCOUNT_ABNORMAL DetailFailReason = "ACCOUNT_ABNORMAL" DETAILFAILREASON_NO_RELATION DetailFailReason = "NO_RELATION" DETAILFAILREASON_RECEIVER_HIGH_RISK DetailFailReason = "RECEIVER_HIGH_RISK" DETAILFAILREASON_RECEIVER_REAL_NAME_NOT_VERIFIED DetailFailReason = "RECEIVER_REAL_NAME_NOT_VERIFIED" DETAILFAILREASON_NO_AUTH DetailFailReason = "NO_AUTH" )
Enums of DetailFailReason
func (DetailFailReason) Ptr ¶
func (e DetailFailReason) Ptr() *DetailFailReason
type DetailStatus ¶
type DetailStatus string
DetailStatus * `PENDING` - 待分账, * `SUCCESS` - 分账成功, * `CLOSED` - 已关闭,
const ( DETAILSTATUS_PENDING DetailStatus = "PENDING" DETAILSTATUS_SUCCESS DetailStatus = "SUCCESS" DETAILSTATUS_CLOSED DetailStatus = "CLOSED" )
Enums of DetailStatus
func (DetailStatus) Ptr ¶
func (e DetailStatus) Ptr() *DetailStatus
type MerchantsApiService ¶
func (*MerchantsApiService) QueryMerchantRatio ¶
func (a *MerchantsApiService) QueryMerchantRatio(ctx context.Context, req QueryMerchantRatioRequest) (resp *QueryMerchantRatioResponse, result *core.APIResult, err error)
QueryMerchantRatio 查询最大分账比例API
可调用此接口查询特约商户设置的允许服务商分账的最大比例
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|商户号未设置|请求参数不符合参数格式|请使用正确的参数重新调用| |RATELIMIT_EXCEED|429|商户发起查询的频率过高|接口有频率限制|请降低频率后重试| |NO_AUTH|403|服务商未开通分账功能|服务商未开通分账|请先开通分账功能| |NO_AUTH|403|非服务商下的签约子商户|服务商未与子商户签约|请先签约子商户| |NO_AUTH|403|子商户未开通分账功能|子商户未开通分账功能|请先开通子商户的分账功能|
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.MerchantsApiService{Client: client} resp, result, err := svc.QueryMerchantRatio(ctx, profitsharing.QueryMerchantRatioRequest{ SubMchid: core.String("1900000109"), }, ) if err != nil { // 处理错误 log.Printf("call QueryMerchantRatio err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type OrderReceiverDetail ¶
type OrderReceiverDetail struct { // 1、类型是MERCHANT_ID时,是商户号 2、类型是PERSONAL_OPENID时,是个人openid 3、类型是PERSONAL_SUB_OPENID时,是个人sub_openid Account *string `json:"account"` // 分账金额,单位为分,只能为整数,不能超过原订单支付金额及最大分账比例金额 Amount *int64 `json:"amount"` // 分账创建时间,遵循RFC3339标准格式 CreateTime *time.Time `json:"create_time"` // 分账的原因描述,分账账单中需要体现 Description *string `json:"description"` // 微信分账明细单号,每笔分账业务执行的明细单号,可与资金账单对账使用 DetailId *string `json:"detail_id"` // 分账失败原因。包含以下枚举值: 1、ACCOUNT_ABNORMAL : 分账接收账户异常 2、NO_RELATION : 分账关系已解除 3、RECEIVER_HIGH_RISK : 高风险接收方 4、RECEIVER_REAL_NAME_NOT_VERIFIED : 接收方未实名 5、NO_AUTH : 分账权限已解除 * `ACCOUNT_ABNORMAL` - 分账接收账户异常, * `NO_RELATION` - 分账关系已解除, * `RECEIVER_HIGH_RISK` - 高风险接收方, * `RECEIVER_REAL_NAME_NOT_VERIFIED` - 接收方未实名, * `NO_AUTH` - 分账权限已解除, FailReason *DetailFailReason `json:"fail_reason,omitempty"` // 分账完成时间,遵循RFC3339标准格式 FinishTime *time.Time `json:"finish_time"` // 枚举值: 1、PENDING:待分账 2、SUCCESS:分账成功 3、CLOSED:已关闭 * `PENDING` - 待分账, * `SUCCESS` - 分账成功, * `CLOSED` - 已关闭, Result *DetailStatus `json:"result"` // 1、MERCHANT_ID:商户号 2、PERSONAL_OPENID:个人openid(由父商户APPID转换得到) 3、PERSONAL_SUB_OPENID: 个人sub_openid(由子商户APPID转换得到) * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要), Type *ReceiverType `json:"type"` }
OrderReceiverDetail
func (OrderReceiverDetail) Clone ¶
func (o OrderReceiverDetail) Clone() *OrderReceiverDetail
func (OrderReceiverDetail) MarshalJSON ¶
func (o OrderReceiverDetail) MarshalJSON() ([]byte, error)
func (OrderReceiverDetail) String ¶
func (o OrderReceiverDetail) String() string
type OrderStatus ¶
type OrderStatus string
OrderStatus * `PROCESSING` - 处理中, * `FINISHED` - 分账完成,
const ( ORDERSTATUS_PROCESSING OrderStatus = "PROCESSING" ORDERSTATUS_FINISHED OrderStatus = "FINISHED" )
Enums of OrderStatus
func (OrderStatus) Ptr ¶
func (e OrderStatus) Ptr() *OrderStatus
type OrdersApiService ¶
func (*OrdersApiService) CreateOrder ¶
func (a *OrdersApiService) CreateOrder(ctx context.Context, req CreateOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
CreateOrder 请求分账API
微信订单支付成功后,商户发起分账请求,将结算后的资金分到分账接收方 注意: - 对同一笔订单最多能发起20次分账请求,每次请求最多分给50个接收方 - 此接口采用异步处理模式,即在接收到商户请求后,会先受理请求再异步处理,最终的分账结果可以通过查询分账接口获取
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|订单号格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用| |INVALID_REQUEST|400|非分账订单不支持分账|请求参数符合参数格式,但不符合业务规则|请根据返回的错误信息确认违反的业务规则| |RATELIMIT_EXCEED|429|对同笔订单分账频率过高|接口有频率限制|请降低频率后重试| |NOT_ENOUGH|403|分账金额不足|传入的分账金额超过了当前订单的剩余可分金额|调整分账金额| |NO_AUTH|403|商户无权限|未开通分账权限|请开通商户号分账权限|
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.OrdersApiService{Client: client} resp, result, err := svc.CreateOrder(ctx, profitsharing.CreateOrderRequest{ Appid: core.String("wx8888888888888888"), OutOrderNo: core.String("P20150806125346"), Receivers: []profitsharing.CreateOrderReceiver{profitsharing.CreateOrderReceiver{ Account: core.String("86693852"), Amount: core.Int64(888), Description: core.String("分给商户A"), Name: core.String("hu89ohu89ohu89o"), Type: core.String("MERCHANT_ID"), }}, SubAppid: core.String("wx8888888888888889"), SubMchid: core.String("1900000109"), TransactionId: core.String("4208450740201411110007820472"), UnfreezeUnsplit: core.Bool(true), }, ) if err != nil { // 处理错误 log.Printf("call CreateOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*OrdersApiService) QueryOrder ¶
func (a *OrdersApiService) QueryOrder(ctx context.Context, req QueryOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
QueryOrder 查询分账结果API
发起分账请求后,可调用此接口查询分账结果 注意: - 发起解冻剩余资金请求后,可调用此接口查询解冻剩余资金的结果
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|商户号未设置|请求参数不符合参数格式|请使用正确的参数重新调用| |RATELIMIT_EXCEED|429|商户发起分账查询的频率过高|接口有频率限制|请降低频率后重试| |RESOURCE_NOT_EXISTS|404|记录不存在|分账单不存在|请检查请求的单号是否正确|
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.OrdersApiService{Client: client} resp, result, err := svc.QueryOrder(ctx, profitsharing.QueryOrderRequest{ TransactionId: core.String("4208450740201411110007820472"), OutOrderNo: core.String("P20150806125346"), SubMchid: core.String("1900000109"), }, ) if err != nil { // 处理错误 log.Printf("call QueryOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*OrdersApiService) UnfreezeOrder ¶
func (a *OrdersApiService) UnfreezeOrder(ctx context.Context, req UnfreezeOrderRequest) (resp *OrdersEntity, result *core.APIResult, err error)
UnfreezeOrder 解冻剩余资金API
不需要进行分账的订单,可直接调用本接口将订单的金额全部解冻给特约商户 注意: - 调用分账接口后,需要解冻剩余资金时,调用本接口将剩余的分账金额全部解冻给特约商户 - 此接口采用异步处理模式,即在接收到商户请求后,会先受理请求再异步处理,最终的分账结果可以通过查询分账接口获取
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|订单号格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用| |INVALID_REQUEST|400|非分账订单不支持解冻剩余资金|请求参数符合参数格式,但不符合业务规则|请根据返回的错误信息确认违反的业务规则| |RATELIMIT_EXCEED|429|对同笔订单分账频率过高|接口有频率限制|请降低频率后重试| |NOT_ENOUGH|403|分账金额为0|分账已完成|分账已完成,无需再请求解冻剩余资金| |NO_AUTH|403|商户无权限|未开通分账权限|请开通商户号分账权限|
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.OrdersApiService{Client: client} resp, result, err := svc.UnfreezeOrder(ctx, profitsharing.UnfreezeOrderRequest{ Description: core.String("解冻全部剩余资金"), OutOrderNo: core.String("P20150806125346"), SubMchid: core.String("1900000109"), TransactionId: core.String("4208450740201411110007820472"), }, ) if err != nil { // 处理错误 log.Printf("call UnfreezeOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type OrdersEntity ¶
type OrdersEntity struct { // 微信分账单号,微信系统返回的唯一标识 OrderId *string `json:"order_id"` // 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ OutOrderNo *string `json:"out_order_no"` // 分账接收方列表 Receivers []OrderReceiverDetail `json:"receivers,omitempty"` // 分账单状态(每个接收方的分账结果请查看receivers中的result字段),枚举值: 1、PROCESSING:处理中 2、FINISHED:分账完成 * `PROCESSING` - 处理中, * `FINISHED` - 分账完成, State *OrderStatus `json:"state"` // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 微信支付订单号 TransactionId *string `json:"transaction_id"` }
OrdersEntity
func (OrdersEntity) Clone ¶
func (o OrdersEntity) Clone() *OrdersEntity
func (OrdersEntity) MarshalJSON ¶
func (o OrdersEntity) MarshalJSON() ([]byte, error)
func (OrdersEntity) String ¶
func (o OrdersEntity) String() string
type QueryMerchantRatioRequest ¶
type QueryMerchantRatioRequest struct { // 微信支付分配的子商户号,即分账的出资商户号。 SubMchid *string `json:"sub_mchid"` }
QueryMerchantRatioRequest
func (QueryMerchantRatioRequest) Clone ¶
func (o QueryMerchantRatioRequest) Clone() *QueryMerchantRatioRequest
func (QueryMerchantRatioRequest) MarshalJSON ¶
func (o QueryMerchantRatioRequest) MarshalJSON() ([]byte, error)
func (QueryMerchantRatioRequest) String ¶
func (o QueryMerchantRatioRequest) String() string
type QueryMerchantRatioResponse ¶
type QueryMerchantRatioResponse struct { // 子商户允许父商户分账的最大比例,单位万分比,比如2000表示20% MaxRatio *int64 `json:"max_ratio"` // 参考请求参数 SubMchid *string `json:"sub_mchid"` }
QueryMerchantRatioResponse
func (QueryMerchantRatioResponse) Clone ¶
func (o QueryMerchantRatioResponse) Clone() *QueryMerchantRatioResponse
func (QueryMerchantRatioResponse) MarshalJSON ¶
func (o QueryMerchantRatioResponse) MarshalJSON() ([]byte, error)
func (QueryMerchantRatioResponse) String ¶
func (o QueryMerchantRatioResponse) String() string
type QueryOrderAmountRequest ¶
type QueryOrderAmountRequest struct { // 微信支付订单号 TransactionId *string `json:"transaction_id"` }
QueryOrderAmountRequest
func (QueryOrderAmountRequest) Clone ¶
func (o QueryOrderAmountRequest) Clone() *QueryOrderAmountRequest
func (QueryOrderAmountRequest) MarshalJSON ¶
func (o QueryOrderAmountRequest) MarshalJSON() ([]byte, error)
func (QueryOrderAmountRequest) String ¶
func (o QueryOrderAmountRequest) String() string
type QueryOrderAmountResponse ¶
type QueryOrderAmountResponse struct { // 微信支付订单号 TransactionId *string `json:"transaction_id"` // 订单剩余待分金额,整数,单元为分 UnsplitAmount *int64 `json:"unsplit_amount"` }
QueryOrderAmountResponse
func (QueryOrderAmountResponse) Clone ¶
func (o QueryOrderAmountResponse) Clone() *QueryOrderAmountResponse
func (QueryOrderAmountResponse) MarshalJSON ¶
func (o QueryOrderAmountResponse) MarshalJSON() ([]byte, error)
func (QueryOrderAmountResponse) String ¶
func (o QueryOrderAmountResponse) String() string
type QueryOrderRequest ¶
type QueryOrderRequest struct { // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 微信支付订单号 TransactionId *string `json:"transaction_id"` // 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ 。 微信分账单号与商户分账单号二选一填写 OutOrderNo *string `json:"out_order_no"` }
QueryOrderRequest
func (QueryOrderRequest) Clone ¶
func (o QueryOrderRequest) Clone() *QueryOrderRequest
func (QueryOrderRequest) MarshalJSON ¶
func (o QueryOrderRequest) MarshalJSON() ([]byte, error)
func (QueryOrderRequest) String ¶
func (o QueryOrderRequest) String() string
type QueryReturnOrderRequest ¶
type QueryReturnOrderRequest struct { // 分账回退的接收商户,对应原分账出资的分账方商户,填写微信支付分配的商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 调用回退接口提供的商户系统内部的回退单号。微信支付回退单号与商户回退单号二选一填写 OutReturnNo *string `json:"out_return_no"` // 原发起分账请求时使用的商户系统内部的分账单号。微信分账单号与商户分账单号二选一填写 OutOrderNo *string `json:"out_order_no"` }
QueryReturnOrderRequest
func (QueryReturnOrderRequest) Clone ¶
func (o QueryReturnOrderRequest) Clone() *QueryReturnOrderRequest
func (QueryReturnOrderRequest) MarshalJSON ¶
func (o QueryReturnOrderRequest) MarshalJSON() ([]byte, error)
func (QueryReturnOrderRequest) String ¶
func (o QueryReturnOrderRequest) String() string
type ReceiverRelationType ¶
type ReceiverRelationType string
ReceiverRelationType * `SERVICE_PROVIDER` - 服务商, * `STORE` - 门店, * `STAFF` - 员工, * `STORE_OWNER` - 店主, * `PARTNER` - 合作伙伴, * `HEADQUARTER` - 总部, * `BRAND` - 品牌方, * `DISTRIBUTOR` - 分销商, * `USER` - 用户, * `SUPPLIER` - 供应商, * `CUSTOM` - 自定义,
const ( RECEIVERRELATIONTYPE_SERVICE_PROVIDER ReceiverRelationType = "SERVICE_PROVIDER" RECEIVERRELATIONTYPE_STORE ReceiverRelationType = "STORE" RECEIVERRELATIONTYPE_STAFF ReceiverRelationType = "STAFF" RECEIVERRELATIONTYPE_STORE_OWNER ReceiverRelationType = "STORE_OWNER" RECEIVERRELATIONTYPE_PARTNER ReceiverRelationType = "PARTNER" RECEIVERRELATIONTYPE_HEADQUARTER ReceiverRelationType = "HEADQUARTER" RECEIVERRELATIONTYPE_BRAND ReceiverRelationType = "BRAND" RECEIVERRELATIONTYPE_DISTRIBUTOR ReceiverRelationType = "DISTRIBUTOR" RECEIVERRELATIONTYPE_USER ReceiverRelationType = "USER" RECEIVERRELATIONTYPE_SUPPLIER ReceiverRelationType = "SUPPLIER" RECEIVERRELATIONTYPE_CUSTOM ReceiverRelationType = "CUSTOM" )
Enums of ReceiverRelationType
func (ReceiverRelationType) Ptr ¶
func (e ReceiverRelationType) Ptr() *ReceiverRelationType
type ReceiverType ¶
type ReceiverType string
ReceiverType * `MERCHANT_ID` - 商户号, * `PERSONAL_OPENID` - 个人openid(由父商户APPID转换得到), * `PERSONAL_SUB_OPENID` - 个人sub_openid(由子商户APPID转换得到)(直连商户不需要,服务商需要),
const ( RECEIVERTYPE_MERCHANT_ID ReceiverType = "MERCHANT_ID" RECEIVERTYPE_PERSONAL_OPENID ReceiverType = "PERSONAL_OPENID" RECEIVERTYPE_PERSONAL_SUB_OPENID ReceiverType = "PERSONAL_SUB_OPENID" )
Enums of ReceiverType
func (ReceiverType) Ptr ¶
func (e ReceiverType) Ptr() *ReceiverType
type ReceiversApiService ¶
func (*ReceiversApiService) AddReceiver ¶
func (a *ReceiversApiService) AddReceiver(ctx context.Context, req AddReceiverRequest) (resp *AddReceiverResponse, result *core.APIResult, err error)
AddReceiver 添加分账接收方API
商户发起添加分账接收方请求,建立分账接收方列表。后续可通过发起分账请求,将分账方商户结算后的资金,分到该分账接收方
错误码列表 名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用 PARAM_ERROR|400|参数格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用 INVALID_REQUEST|400|无效请求|请确认分账接收方是否存在|请确认分账接收方是否存在 NO_AUTH|403|商户无权限|未开通分账权限|请开通商户号分账权限 RATELIMIT_EXCEED|429|添加接收方频率过高|接口有频率限制|请降低频率后重试
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.ReceiversApiService{Client: client} resp, result, err := svc.AddReceiver(ctx, profitsharing.AddReceiverRequest{ Account: core.String("86693852"), Appid: core.String("wx8888888888888888"), CustomRelation: core.String("代理商"), Name: core.String("hu89ohu89ohu89o"), RelationType: profitsharing.RECEIVERRELATIONTYPE_SERVICE_PROVIDER.Ptr(), SubAppid: core.String("wx8888888888888889"), SubMchid: core.String("1900000109"), Type: profitsharing.RECEIVERTYPE_MERCHANT_ID.Ptr(), }, ) if err != nil { // 处理错误 log.Printf("call AddReceiver err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*ReceiversApiService) DeleteReceiver ¶
func (a *ReceiversApiService) DeleteReceiver(ctx context.Context, req DeleteReceiverRequest) (resp *DeleteReceiverResponse, result *core.APIResult, err error)
DeleteReceiver 删除分账接收方API
商户发起删除分账接收方请求。删除后,不支持将分账方商户结算后的资金,分到该分账接收方
错误码列表 名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用 PARAM_ERROR|400|参数格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用 INVALID_REQUEST|400|无效请求|请确认分账接收方是否存在|请确认分账接收方是否存在 NO_AUTH|403|商户无权限|未开通分账权限|请开通商户号分账权限 RATELIMIT_EXCEED|429|删除接收方频率过高|接口有频率限制|请降低频率后重试
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.ReceiversApiService{Client: client} resp, result, err := svc.DeleteReceiver(ctx, profitsharing.DeleteReceiverRequest{ Account: core.String("86693852"), Appid: core.String("wx8888888888888888"), SubAppid: core.String("wx8888888888888889"), SubMchid: core.String("1900000109"), Type: profitsharing.RECEIVERTYPE_MERCHANT_ID.Ptr(), }, ) if err != nil { // 处理错误 log.Printf("call DeleteReceiver err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type ReturnOrderFailReason ¶
type ReturnOrderFailReason string
ReturnOrderFailReason * `ACCOUNT_ABNORMAL` - 分账接收方账户异常, * `BALANCE_NOT_ENOUGH` - 余额不足, * `TIME_OUT_CLOSED` - 超时关单,
const ( RETURNORDERFAILREASON_ACCOUNT_ABNORMAL ReturnOrderFailReason = "ACCOUNT_ABNORMAL" RETURNORDERFAILREASON_BALANCE_NOT_ENOUGH ReturnOrderFailReason = "BALANCE_NOT_ENOUGH" RETURNORDERFAILREASON_TIME_OUT_CLOSED ReturnOrderFailReason = "TIME_OUT_CLOSED" )
Enums of ReturnOrderFailReason
func (ReturnOrderFailReason) Ptr ¶
func (e ReturnOrderFailReason) Ptr() *ReturnOrderFailReason
type ReturnOrderStatus ¶
type ReturnOrderStatus string
ReturnOrderStatus * `PROCESSING` - 处理中, * `SUCCESS` - 已成功, * `FAILED` - 已失败,
const ( RETURNORDERSTATUS_PROCESSING ReturnOrderStatus = "PROCESSING" RETURNORDERSTATUS_SUCCESS ReturnOrderStatus = "SUCCESS" RETURNORDERSTATUS_FAILED ReturnOrderStatus = "FAILED" )
Enums of ReturnOrderStatus
func (ReturnOrderStatus) Ptr ¶
func (e ReturnOrderStatus) Ptr() *ReturnOrderStatus
type ReturnOrdersApiService ¶
func (*ReturnOrdersApiService) CreateReturnOrder ¶
func (a *ReturnOrdersApiService) CreateReturnOrder(ctx context.Context, req CreateReturnOrderRequest) (resp *ReturnOrdersEntity, result *core.APIResult, err error)
CreateReturnOrder 请求分账回退API
如果订单已经分账,在退款时,可以先调此接口,将已分账的资金从分账接收方的账户回退给分账方,再发起退款 注意: - 分账回退以原分账单为依据,支持多次回退,申请回退总金额不能超过原分账单分给该接收方的金额 - 此接口采用同步处理模式,即在接收到商户请求后,会实时返回处理结果 - 对同一笔分账单最多能发起20次分账回退请求 - 退款和分账回退没有耦合,分账回退可以先于退款请求,也可以后于退款请求 - 此功能需要接收方在商户平台-交易中心-分账-分账接收设置下,开启同意分账回退后,才能使用
错误码列表 名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用 PARAM_ERROR|400|订单号格式不正确|请求参数不符合参数格式|请使用正确的参数重新调用 INVALID_REQUEST|400|回退方不存在|请求参数符合参数格式,但不符合业务规则|请根据返回的错误信息确认违反的业务规则 RATELIMIT_EXCEED|429|商户发起分账回退的频率过高|接口有频率限制|请降低频率后重试 NO_AUTH|403|回退方未开通分账回退功能|未开通分账权限|请先让回退方开通分账回退功能
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.ReturnOrdersApiService{Client: client} resp, result, err := svc.CreateReturnOrder(ctx, profitsharing.CreateReturnOrderRequest{ Amount: core.Int64(10), Description: core.String("用户退款"), OrderId: core.String("3008450740201411110007820472"), OutOrderNo: core.String("P20150806125346"), OutReturnNo: core.String("R20190516001"), ReturnMchid: core.String("86693852"), SubMchid: core.String("1900000109"), }, ) if err != nil { // 处理错误 log.Printf("call CreateReturnOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
func (*ReturnOrdersApiService) QueryReturnOrder ¶
func (a *ReturnOrdersApiService) QueryReturnOrder(ctx context.Context, req QueryReturnOrderRequest) (resp *ReturnOrdersEntity, result *core.APIResult, err error)
QueryReturnOrder 查询分账回退结果API
商户需要核实回退结果,可调用此接口查询回退结果 注意: - 如果分账回退接口返回状态为处理中,可调用此接口查询回退结果
错误码列表 名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用 PARAM_ERROR|400|商户号未设置|请求参数不符合参数格式|请使用正确的参数重新调用 RATELIMIT_EXCEED|429|商户发起分账回退查询的频率过高|接口有频率限制|请降低频率后重试 RESOURCE_NOT_EXISTS|404|记录不存在|分账回退单不存在|请检查请求的单号是否正确
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.ReturnOrdersApiService{Client: client} resp, result, err := svc.QueryReturnOrder(ctx, profitsharing.QueryReturnOrderRequest{ OutReturnNo: core.String("R20190516001"), OutOrderNo: core.String("P20190806125346"), SubMchid: core.String("1900000109"), }, ) if err != nil { // 处理错误 log.Printf("call QueryReturnOrder err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type ReturnOrdersEntity ¶
type ReturnOrdersEntity struct { // 需要从分账接收方回退的金额,单位为分,只能为整数 Amount *int64 `json:"amount"` // 分账回退创建时间,遵循RFC3339标准格式 CreateTime *time.Time `json:"create_time"` // 分账回退的原因描述 Description *string `json:"description"` // 失败原因。包含以下枚举值: ACCOUNT_ABNORMAL : 分账接收方账户异常 TIME_OUT_CLOSED : 超时关单 * `ACCOUNT_ABNORMAL` - 分账接收方账户异常, * `BALANCE_NOT_ENOUGH` - 余额不足, * `TIME_OUT_CLOSED` - 超时关单, FailReason *ReturnOrderFailReason `json:"fail_reason,omitempty"` // 分账回退完成时间,遵循RFC3339标准格式 FinishTime *time.Time `json:"finish_time"` // 参考请求参数 OrderId *string `json:"order_id"` // 参考请求参数 OutOrderNo *string `json:"out_order_no"` // 参考请求参数 OutReturnNo *string `json:"out_return_no"` // 如果请求返回为处理中,则商户可以通过调用回退结果查询接口获取请求的最终处理结果。如果查询到回退结果在处理中,请勿变更商户回退单号,使用相同的参数再次发起分账回退,否则会出现资金风险。在处理中状态的回退单如果5天没有成功,会因为超时被设置为已失败。 枚举值: PROCESSING:处理中 SUCCESS:已成功 FAILED:已失败 * `PROCESSING` - 处理中, * `SUCCESS` - 已成功, * `FAILED` - 已失败, Result *ReturnOrderStatus `json:"result"` // 微信分账回退单号,微信系统返回的唯一标识 ReturnId *string `json:"return_id"` // 只能对原分账请求中成功分给商户接收方进行回退 ReturnMchid *string `json:"return_mchid"` // 参考请求参数 SubMchid *string `json:"sub_mchid,omitempty"` }
ReturnOrdersEntity
func (ReturnOrdersEntity) Clone ¶
func (o ReturnOrdersEntity) Clone() *ReturnOrdersEntity
func (ReturnOrdersEntity) MarshalJSON ¶
func (o ReturnOrdersEntity) MarshalJSON() ([]byte, error)
func (ReturnOrdersEntity) String ¶
func (o ReturnOrdersEntity) String() string
type SplitBillHashType ¶
type SplitBillHashType string
SplitBillHashType * `SHA1` - SHA1,Secure Hash Algorithm 1
const (
SPLITBILLHASHTYPE_SHA1 SplitBillHashType = "SHA1"
)
Enums of SplitBillHashType
func (SplitBillHashType) Ptr ¶
func (e SplitBillHashType) Ptr() *SplitBillHashType
type SplitBillRequest ¶
type SplitBillRequest struct { // 若商户是直连商户: - 无需填写该字段 若商户是服务商: - 不填则默认返回服务商下的所有分账账单。 - 如需下载某个子商户下的分账账单,则填指定的子商户号。 SubMchid *string `json:"sub_mchid,omitempty"` // 格式YYYY-MM-DD。仅支持三个月内的账单下载申请。 BillDate *string `json:"bill_date"` // 不填则以不压缩的方式返回数据流 TarType *SplitBillTarType `json:"tar_type,omitempty"` }
SplitBillRequest
func (SplitBillRequest) Clone ¶
func (o SplitBillRequest) Clone() *SplitBillRequest
func (SplitBillRequest) MarshalJSON ¶
func (o SplitBillRequest) MarshalJSON() ([]byte, error)
func (SplitBillRequest) String ¶
func (o SplitBillRequest) String() string
type SplitBillResponse ¶
type SplitBillResponse struct { // 供下一步请求账单文件的下载地址,该地址30s内有效 DownloadUrl *string `json:"download_url"` // 原始账单(gzip需要解压缩)的摘要算法,用于校验文件的完整性 * `SHA1` - SHA1,Secure Hash Algorithm 1 HashType *SplitBillHashType `json:"hash_type"` // 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性 HashValue *string `json:"hash_value"` }
SplitBillResponse
func (SplitBillResponse) Clone ¶
func (o SplitBillResponse) Clone() *SplitBillResponse
func (SplitBillResponse) MarshalJSON ¶
func (o SplitBillResponse) MarshalJSON() ([]byte, error)
func (SplitBillResponse) String ¶
func (o SplitBillResponse) String() string
type SplitBillTarType ¶
type SplitBillTarType string
SplitBillTarType * `GZIP` - GZIP格式压缩,返回格式为.gzip的压缩包账单
const (
SPLITBILLTARTYPE_GZIP SplitBillTarType = "GZIP"
)
Enums of SplitBillTarType
func (SplitBillTarType) Ptr ¶
func (e SplitBillTarType) Ptr() *SplitBillTarType
type TransactionsApiService ¶
func (*TransactionsApiService) QueryOrderAmount ¶
func (a *TransactionsApiService) QueryOrderAmount(ctx context.Context, req QueryOrderAmountRequest) (resp *QueryOrderAmountResponse, result *core.APIResult, err error)
QueryOrderAmount 查询剩余待分金额API
可调用此接口查询订单剩余待分金额
错误码列表 |名称|状态码|描述示例|原因|解决方案 |-|-|-|-|-| |SYSTEM_ERROR|500|系统错误|系统超时|系统异常,请使用相同参数稍后重新调用| |PARAM_ERROR|400|商户号未设置|请求参数不符合参数格式|请使用正确的参数重新调用| |RATELIMIT_EXCEED|429|商户发起查询的频率过高|接口有频率限制|请降低频率后重试| |INVALID_REQUEST|400|非分账订单不支持此查询|请求参数符合参数格式,但不符合业务规则|请根据返回的错误信息确认违反的业务规则| |INVALID_REQUEST|400|非本商户的订单不支持查询|请求参数符合参数格式,但不符合业务规则|请根据返回的错误信息确认违反的业务规则|
Example ¶
package main import ( "context" "log" "github.com/charleybin/wechatpay-go/core" "github.com/charleybin/wechatpay-go/core/option" "github.com/charleybin/wechatpay-go/services/profitsharing" "github.com/charleybin/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.Print("load merchant private key error") } 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) } svc := profitsharing.TransactionsApiService{Client: client} resp, result, err := svc.QueryOrderAmount(ctx, profitsharing.QueryOrderAmountRequest{ TransactionId: core.String("4208450740201411110007820472"), }, ) if err != nil { // 处理错误 log.Printf("call QueryOrderAmount err:%s", err) } else { // 处理返回结果 log.Printf("status=%d resp=%s", result.Response.StatusCode, resp) } }
Output:
type UnfreezeOrderRequest ¶
type UnfreezeOrderRequest struct { // 分账的原因描述,分账账单中需要体现 Description *string `json:"description"` // 商户系统内部的分账单号,在商户系统内部唯一,同一分账单号多次请求等同一次。只能是数字、大小写字母_-|*@ OutOrderNo *string `json:"out_order_no"` // 微信支付分配的子商户号,即分账的出资商户号。(直连商户不需要,服务商需要) SubMchid *string `json:"sub_mchid,omitempty"` // 微信支付订单号 TransactionId *string `json:"transaction_id"` }
UnfreezeOrderRequest
func (UnfreezeOrderRequest) Clone ¶
func (o UnfreezeOrderRequest) Clone() *UnfreezeOrderRequest
func (UnfreezeOrderRequest) MarshalJSON ¶
func (o UnfreezeOrderRequest) MarshalJSON() ([]byte, error)
func (UnfreezeOrderRequest) String ¶
func (o UnfreezeOrderRequest) String() string