Documentation
¶
Index ¶
- type AuxParam
- type BizInfo
- type Client
- func (c *Client) GetAccessToken(param GetAccessToken) (result *GetAccessTokenRsp, err error)
- func (c *Client) GetUnionId(param GetUnionId) (result *GetUnionIdRsp, err error)
- func (c *Client) LoadAppPrivateKey(priKey string)
- func (c *Client) LoadAppPublicKey(pubKey string)
- func (c *Client) LoadOptionFunc(opts ...OptionFunc)
- func (c *Client) LongQrcode(param LongQrcode) (result *QrcodeRsp, err error)
- func (c *Client) OnReceivedData(fn func(method string, data []byte))
- func (c *Client) SessionKey(param SessionKey) (result *SessionKeyRsp, err error)
- func (c *Client) ShortQrcode(param ShortQrcode) (result *QrcodeRsp, err error)
- func (c *Client) TradeCloseOrder(param TradeCloseOrder) (result *TradeCloseOrderRsp, err error)
- func (c *Client) TradeOrderQuery(param TradeOrderQuery) (result *TradeOrderQueryRsp, err error)
- func (c *Client) TradePolymerPayment(param TradePolymerPayment) (result TradePolymerPaymentRsp, err error)
- func (c *Client) TradeRefund(param TradeRefund) (result *TradeRefundRsp, err error)
- func (c *Client) TradeRefundQuery(param TradeRefundQuery) (result *TradeRefundQueryRsp, err error)
- func (c *Client) URLValues(param Param) (value url.Values, err error)
- func (c *Client) VerifySign(signContent, sign string) (checkRes bool, err error)
- type Err
- type ErrorCode
- type ErrorNo
- type GetAccessToken
- type GetAccessTokenRsp
- type GetUnionId
- type GetUnionIdRsp
- type LongQrcode
- type OptionFunc
- type Param
- type QrcodeRsp
- type SessionKey
- type SessionKeyRsp
- type ShortQrcode
- type TpData
- type TradeCloseOrder
- type TradeCloseOrderRsp
- type TradeOrderQuery
- type TradeOrderQueryRsp
- type TradePolymerPayment
- type TradePolymerPaymentRsp
- type TradeRefund
- type TradeRefundQuery
- type TradeRefundQueryRsp
- type TradeRefundRsp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) GetAccessToken ¶
func (c *Client) GetAccessToken(param GetAccessToken) (result *GetAccessTokenRsp, err error)
GetAccessToken 获取小程序全局唯一后台接口调用凭据(access_token)https://smartprogram.baidu.com/docs/develop/serverapi/power_exp/ GET https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=CLIENT_ID&client_secret=CLIENT_SECRET&scope=smartapp_snsapi_base
func (*Client) GetUnionId ¶
func (c *Client) GetUnionId(param GetUnionId) (result *GetUnionIdRsp, err error)
GetUnionId 获取unionID https://smartprogram.baidu.com/docs/develop/api/open/log_getunionid/ POST https://openapi.baidu.com/rest/2.0/smartapp/getunionid?access_token=ACCESS_TOKEN
func (*Client) LongQrcode ¶
func (c *Client) LongQrcode(param LongQrcode) (result *QrcodeRsp, err error)
LongQrcode 二维码长链 https://smartprogram.baidu.com/docs/develop/serverapi/get_unlimited_qrcode/ POST https://openapi.baidu.com/rest/2.0/smartapp/qrcode/getunlimitedv2?access_token=ACCESS_TOKEN
func (*Client) OnReceivedData ¶
返回内容
func (*Client) SessionKey ¶
func (c *Client) SessionKey(param SessionKey) (result *SessionKeyRsp, err error)
SessionKey 用户登陆凭证 https://smartprogram.baidu.com/docs/develop/api/open/getSessionKey/ GET https://openapi.baidu.com/rest/2.0/smartapp/getsessionkey?access_token=ACCESS_TOKEN&code=CODE
func (*Client) ShortQrcode ¶
func (c *Client) ShortQrcode(param ShortQrcode) (result *QrcodeRsp, err error)
ShortQrcode 二维码短链 https://smartprogram.baidu.com/docs/develop/serverapi/get_qrcode/ POST https://openapi.baidu.com/rest/2.0/smartapp/qrcode/getv2?access_token=ACCESS_TOKEN
func (*Client) TradeCloseOrder ¶
func (c *Client) TradeCloseOrder(param TradeCloseOrder) (result *TradeCloseOrderRsp, err error)
TradeCloseOrder 关闭订单 https://smartprogram.baidu.com/docs/third/pay/close_order/ GET https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/tp/cancelOrder
func (*Client) TradeOrderQuery ¶
func (c *Client) TradeOrderQuery(param TradeOrderQuery) (result *TradeOrderQueryRsp, err error)
TradeOrderQuery 查询订单 https://smartprogram.baidu.com/docs/third/pay/get_by_tp_order_id/ GET https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/tp/findByTpOrderId
func (*Client) TradePolymerPayment ¶
func (c *Client) TradePolymerPayment(param TradePolymerPayment) (result TradePolymerPaymentRsp, err error)
TradePolymerPayment 百度收银台 https://smartprogram.baidu.com/docs/develop/api/open/payment_swan-requestPolymerPayment/#orderInfo
func (*Client) TradeRefund ¶
func (c *Client) TradeRefund(param TradeRefund) (result *TradeRefundRsp, err error)
TradeRefund 申请退款 https://smartprogram.baidu.com/docs/third/pay/apply_order_refund/ POST https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/tp/applyOrderRefund
func (*Client) TradeRefundQuery ¶
func (c *Client) TradeRefundQuery(param TradeRefundQuery) (result *TradeRefundQueryRsp, err error)
TradeRefundQuery 查询退款 https://smartprogram.baidu.com/docs/third/pay/get_order_refund/ GET https://openapi.baidu.com/rest/2.0/smartapp/pay/paymentservice/tp/findOrderRefund
type Err ¶
type Err struct { ErrorS string `json:"error"` // 异常提示信息 ErrorDescription string `json:"error_description"` // 异常情况详细的提示信息 }
TOKEN错误
type ErrorCode ¶
type ErrorCode struct { ErrorNo ErrorCode int `json:"error_code"` ErrorMsg string `json:"error_msg"` }
openapi错误
type ErrorNo ¶
type ErrorNo struct { Errno int `json:"errno"` Errmsg string `json:"errmsg"` Msg string `json:"msg"` }
基本错误
type GetAccessToken ¶
type GetAccessToken struct { AuxParam GrantType string `json:"grant_type"` // 固定为:client_credentials Scope string `json:"scope"` // 固定为:smartapp_snsapi_base }
GetAccessToken 获取小程序全局唯一后台接口调用凭据(access_token)https://smartprogram.baidu.com/docs/develop/serverapi/power_exp/
func (GetAccessToken) NeedSecret ¶
func (a GetAccessToken) NeedSecret() bool
func (GetAccessToken) NeedSign ¶
func (a GetAccessToken) NeedSign() bool
type GetAccessTokenRsp ¶
type GetAccessTokenRsp struct { Err AccessToken string `json:"access_token"` // 获取到的凭证 ExpiresIn int `json:"expires_in"` // 凭证有效时间,单位:秒 }
GetAccessTokenRsp 获取小程序全局唯一后台接口调用凭据响应参数
type GetUnionId ¶
GetUnionId 获取unionID https://smartprogram.baidu.com/docs/develop/api/open/log_getunionid/
func (GetUnionId) NeedSecret ¶
func (a GetUnionId) NeedSecret() bool
func (GetUnionId) NeedSign ¶
func (a GetUnionId) NeedSign() bool
type GetUnionIdRsp ¶
type LongQrcode ¶
type LongQrcode struct { AuxParam Path string `json:"path"` // 扫码进入的小程序页面路径,最大长度 4000 字节,可以为空。 Width int `json:"width"` // 二维码的宽度(单位:px)。最小 280px,最大 1280px Mf int `json:"mf"` // 是否包含二维码内嵌 logo 标识,1001 为不包含,默认包含 ImgFlag int `json:"img_flag"` // 返回值选项,默认或传 1 时只返回二维码 base64 编码字符串,传 0 只返回 url }
LongQrcode 二维码长链 https://smartprogram.baidu.com/docs/develop/serverapi/get_unlimited_qrcode/ 获取小程序二维码长链接,适用于需要的码数量较多的业务场景。通过该接口生成的二维码,永久有效,无数量限制。
func (LongQrcode) NeedAppId ¶
func (q LongQrcode) NeedAppId() bool
func (LongQrcode) NeedSign ¶
func (q LongQrcode) NeedSign() bool
type OptionFunc ¶
type OptionFunc func(c *Client)
type QrcodeRsp ¶
type QrcodeRsp struct { ErrorNo RequestId string `json:"request_id"` // 请求 ID,标识一次请求 Timestamp int `json:"timestamp"` // 时间戳 Data struct { Base64Str string `json:"base64_str,omitempty"` // 二维码 base64 编码字符串 Url string `json:"url,omitempty"` // 小程序二维码短链 } `json:"data"` }
QrcodeRsp 二维码短链响应参数
type SessionKey ¶
type SessionKey struct { AuxParam AccessToken string `json:"access_token"` // 接口调用凭证 Code string `json:"code"` // 通过 swan.getLoginCode 获取 Authorization Code 特殊说明:code 中有 @ 符号时,会请求对应的开源宿主,用户身份校验及 SessionKey 生成过程由开源宿主实现 }
SessionKey 用户登陆凭证 https://smartprogram.baidu.com/docs/develop/api/open/getSessionKey/
func (SessionKey) NeedAppId ¶
func (a SessionKey) NeedAppId() bool
func (SessionKey) NeedSecret ¶
func (a SessionKey) NeedSecret() bool
func (SessionKey) NeedSign ¶
func (a SessionKey) NeedSign() bool
type SessionKeyRsp ¶
type SessionKeyRsp struct { ErrorCode Data struct { SessionKey string `json:"session_key"` // 用户的 SessionKey OpenId string `json:"open_id"` // 用户身份标识 不同用户登录同一个小程序获取到的 openid 不同,同一个用户登录不同小程序获取到的 openid 也不同 } `json:"data"` RequestId string `json:"request_id"` // 请求 ID ,标识一次请求 Timestamp int `json:"timestamp"` // 时间戳 1640140013 }
SessionKeyRsp 用户登陆凭证响应参数
type ShortQrcode ¶
type ShortQrcode struct { AuxParam Path string `json:"path"` // 扫码进入的小程序页面路径,最大长度 4000 字节,可以为空。 Width int `json:"width"` // 二维码的宽度(单位:px)。最小 280px,最大 1280px Mf int `json:"mf"` // 是否包含二维码内嵌 logo 标识,1001 为不包含,默认包含 ImgFlag int `json:"img_flag"` // 返回值选项,默认或传 1 时只返回二维码 base64 编码字符串,传 0 只返回 url }
ShortQrcode 二维码短链 https://smartprogram.baidu.com/docs/develop/serverapi/get_qrcode/ 获取小程序二维码短链,长度固定 35 个字符,适用于需要的码数量较少的业务场景。通过该接口生成的二维码,永久有效,有数量限制。
func (ShortQrcode) NeedAppId ¶
func (q ShortQrcode) NeedAppId() bool
func (ShortQrcode) NeedSign ¶
func (q ShortQrcode) NeedSign() bool
type TpData ¶
type TpData struct { AppKey string `json:"appKey"` // 表示应用身份的唯一 ID DealId string `json:"dealId"` // 百度收银台的财务结算凭证 TpOrderId string `json:"tpOrderId"` // 业务方唯一订单号 TotalAmount string `json:"totalAmount"` // 订单总金额(单位:分) ReturnData map[string]interface{} `json:"returnData"` // 业务方用于透传的业务变量 支付成功后会以 query 形式注入到 payResultUrl 页面中(query 可以在页面的 onLoad 生命周期内获取) DisplayData string `json:"display_data"` // 收银台定制页面展示属性,非定制业务请置空 用于支付页面展示订单详细信息 }
type TradeCloseOrder ¶
type TradeCloseOrder struct { AuxParam AccessToken string `json:"access_token"` // 授权小程序的接口调用凭据 TpOrderId string `json:"tpOrderId"` // 开发者订单 ID PmAppKey string `json:"pmAppKey"` // 调起百度收银台的支付服务 appKey }
TradeCloseOrder 关闭订单 https://smartprogram.baidu.com/docs/third/pay/close_order/
func (TradeCloseOrder) NeedAppId ¶
func (aux TradeCloseOrder) NeedAppId() bool
func (TradeCloseOrder) NeedSign ¶
func (aux TradeCloseOrder) NeedSign() bool
type TradeCloseOrderRsp ¶
TradeCloseOrderRsp 关闭订单响应参数
type TradeOrderQuery ¶
type TradeOrderQuery struct { AuxParam AccessToken string `json:"access_token"` // 授权小程序的接口调用凭据 TpOrderId string `json:"tpOrderId"` // 开发者订单 ID PmAppKey string `json:"pmAppKey"` // 调起百度收银台的支付服务 appKey }
TradeOrderQuery 查询订单 https://smartprogram.baidu.com/docs/third/pay/get_by_tp_order_id/
func (TradeOrderQuery) NeedAppId ¶
func (aux TradeOrderQuery) NeedAppId() bool
func (TradeOrderQuery) NeedSign ¶
func (aux TradeOrderQuery) NeedSign() bool
type TradeOrderQueryRsp ¶
type TradeOrderQueryRsp struct { ErrorNo Data struct { BizInfo string `json:"bizInfo"` // 业务扩展字段 Count int `json:"count"` // 数量 CreateTime int `json:"createTime"` // 创建时间 DealId int `json:"dealId"` // 跳转百度收银台支付必带参数之一 OrderId int `json:"orderId"` // 百度订单ID OriPrice int `json:"oriPrice"` // 原价 ParentOrderId int `json:"parentOrderId"` // 购物车订单父订单ID ParentType int `json:"parentType"` // 订单类型 PayMoney int `json:"payMoney"` // 支付金额 SettlePrice int `json:"settlePrice"` // 结算金额 Status int `json:"status"` // 订单状态 -1订单已取消/订单已异常退款 1订单支付中 2订单已支付 SubStatus int `json:"subStatus"` // 订单子状态 TotalMoney int `json:"totalMoney"` // 总金额 TpId int `json:"tpId"` // tpid TpOrderId string `json:"tpOrderId"` // 开发者订单ID TradeNo string `json:"tradeNo"` // 支付单号 Type int `json:"type"` // ordertype OpenId int `json:"openId"` // 小程序用户id AppKey int `json:"appKey"` // 小程序appkey AppId int `json:"appId"` // 小程序appid UserId int `json:"userId"` // 用户 id 与支付状态通知中的保持一致 } `json:"data"` }
TradeOrderQueryRsp 查询订单响应参数
type TradePolymerPayment ¶
type TradePolymerPayment struct { TotalAmount string `json:"totalAmount"` // 订单金额(单位:人民币分)。注:小程序测试包测试金额不可超过 1000 分 TpOrderId string `json:"tpOrderId"` // 小程序开发者系统创建的唯一订单 ID ,当支付状态发生变化时,会通过此订单 ID 通知开发者 NotifyUrl string `json:"notifyUrl"` // 通知开发者支付状态的回调地址,必须是合法的 URL ,与开发者平台填写的支付回调地址作用一致,未填写的以平台回调地址为准 DealTitle string `json:"dealTitle"` // 订单的名称 SignFieldsRange string `json:"signFieldsRange"` // 用于区分验签字段范围,signFieldsRange 的值:0:原验签字段 appKey+dealId+tpOrderId;1:包含 totalAmount 的验签,验签字段包括appKey+dealId+tpOrderId+totalAmount。固定值为 1 。 BizInfo string `json:"bizInfo,omitempty"` // 订单详细信息,需要是一个可解析为 JSON Object 的字符串 PayResultUrl string `json:"payResultUrl,omitempty"` // 当前页面 path。Web 态小程序支付成功后跳回的页面路径,例如:'/pages/payResult/payResult' InlinePaySign string `json:"inlinePaySign,omitempty"` // 内嵌支付组件返回的支付信息加密 key,与 内嵌支付组件配套使用,此值不传或者传空时默认调起支付面板 PromotionTag string `json:"promotionTag,omitempty"` // 平台营销信息,此处传可使用平台券的 spuid,支持通过英文逗号分割传入多个 spuid 值,仅与百度合作平台类目券的开发者需要填写 }
TradePolymerPayment 百度收银台 https://smartprogram.baidu.com/docs/develop/api/open/payment_swan-requestPolymerPayment/#orderInfo
type TradePolymerPaymentRsp ¶
type TradePolymerPaymentRsp struct { DealId string `json:"dealId"` // 跳转百度收银台支付必带参数之一,是百度收银台的财务结算凭证,与账号绑定的结算协议一一对应,每笔交易将结算到 dealId 对应的协议主体 AppKey string `json:"appKey"` // 支付能力开通后分配的支付 appKey,用以表示应用身份的唯一 ID ,在应用审核通过后进行分配,一经分配后不会发生更改,来唯一确定一个应用 RsaSign string `json:"rsaSign"` // 对appKey+dealId+totalAmount+tpOrderId进行 RSA 加密后的签名,防止订单被伪造 TradePolymerPayment }
TradePolymerPaymentRsp 百度收银台响应参数
type TradeRefund ¶
type TradeRefund struct { AuxParam AccessToken string `json:"access_token" form:"access_token"` // 授权小程序的接口调用凭据 ApplyRefundMoney int64 `json:"applyRefundMoney,omitempty" form:"applyRefundMoney"` // 退款金额(单位:分),该字段最大不能超过支付回调中的总金额(totalMoney) 1.如不填金额时,默认整单发起退款 2.含有百度平台营销的订单,目前只支持整单发起退款,不支持部分多次退款 BizRefundBatchID string `json:"bizRefundBatchId" form:"bizRefundBatchId"` // 开发者退款批次 IsSkipAudit int64 `json:"isSkipAudit" form:"isSkipAudit"` // 是否跳过审核,不需要百度请求开发者退款审核请传 1,默认为0; 0:不跳过开发者业务方审核;1:跳过开发者业务方审核。 若不跳过审核,请对接请求业务方退款审核接口 OrderID int64 `json:"orderId" form:"orderId"` // 百度收银台订单 ID RefundReason string `json:"refundReason" form:"refundReason"` // 退款原因 RefundType int64 `json:"refundType" form:"refundType"` // 退款类型 1:用户发起退款;2:开发者业务方客服退款;3:开发者服务异常退款。 TpOrderID string `json:"tpOrderId" form:"tpOrderId"` // 开发者订单 ID UserID int64 `json:"userId" form:"userId"` // 百度收银台用户 ID RefundNotifyURL string `json:"refundNotifyUrl,omitempty" form:"refundNotifyUrl"` // 退款通知 url ,不传时默认为在开发者后台配置的 url PmAppKey string `json:"pmAppKey" form:"pmAppKey"` // 调起百度收银台的支付服务 appKey }
TradeRefund 申请退款 https://smartprogram.baidu.com/docs/third/pay/apply_order_refund/
func (TradeRefund) NeedAppId ¶
func (aux TradeRefund) NeedAppId() bool
func (TradeRefund) NeedSign ¶
func (aux TradeRefund) NeedSign() bool
type TradeRefundQuery ¶
type TradeRefundQuery struct { AuxParam AccessToken string `json:"access_token"` // 授权小程序的接口调用凭据 TpOrderId string `json:"tpOrderId"` // 开发者订单 ID PmAppKey string `json:"pmAppKey"` // 调起百度收银台的支付服务 appKey UserId string `json:"userId"` // 百度收银台用户 ID }
TradeRefundQuery 查询退款 https://smartprogram.baidu.com/docs/third/pay/get_order_refund/
func (TradeRefundQuery) NeedAppId ¶
func (aux TradeRefundQuery) NeedAppId() bool
func (TradeRefundQuery) NeedSign ¶
func (aux TradeRefundQuery) NeedSign() bool
type TradeRefundQueryRsp ¶
type TradeRefundQueryRsp struct { ErrorNo Data []struct { BizRefundBatchId string `json:"bizRefundBatchId"` // 开发者退款批次id OrderId int `json:"orderId"` // 退款订单号 RefundBatchId int `json:"refundBatchId"` // 退款批次id RefundStatus int `json:"refundStatus"` // 退款状态 1 退款中 2 退款成功 3 退款失败 UserId int `json:"userId"` // 退款用户id } `json:"data"` }
TradeRefundQueryRsp 查询退款响应参数
type TradeRefundRsp ¶
type TradeRefundRsp struct { ErrorNo Data struct { RefundBatchId string `json:"refundBatchId"` // 平台退款批次号 RefundPayMoney int `json:"refundPayMoney"` // 平台可退退款金额【分为单位】 } `json:"data"` }
TradeRefundRsp 申请退款响应参数