Documentation
¶
Index ¶
- Constants
- Variables
- type AccessTokenResponse
- type App
- type AppOptions
- type CallbackReqeust
- type CallbackRequestMessage
- type CallbackResponse
- type Douyin
- type ExpandOrderInfo
- type Option
- func WithAppClientKey(clientKey string) Option
- func WithAppClientSecret(clientSecret string) Option
- func WithIsProduct(isProduct bool) Option
- func WithMiniProgramClientKey(clientKey string) Option
- func WithMiniProgramClientSecret(clientSecret string) Option
- func WithPayAppId(appId string) Option
- func WithPayDisableMsg(disableMsg int) Option
- func WithPayMsgPage(msgPage string) Option
- func WithPayNotifyUrl(notifyUrl string) Option
- func WithPaySalt(salt string) Option
- func WithPayStoreUid(storeUid string) Option
- func WithPayThirdpartyId(thirdpartyId string) Option
- func WithPayToken(token string) Option
- type Options
- type PayCreateOrderConfig
- type PayCreateOrderRequest
- type PayCreateOrderResponse
- type PayOptions
- type Payment
- type QueryOrderRequest
- type QueryOrderResponse
- type UserinfoResponse
Constants ¶
const ( OrderSuccess = 0 // 订单查询成功 OrderErrInternal = 1000 // 内部错误 OrderErrLimit = 1001 // 系统限流 OrderErrNoOrder = 2000 // 支付记录不存在 OrderErrSign = 2008 // 签名错误 OrderErrParams = 2010 // 参数错误 OrderErrAppId = 2042 // app_id 错误 OrderErrThirdPartyId = 2047 // thirdparty_id 错误 OrderErrPermission = 2048 // 未查询到服务商与小程序的授权关系 )
const ( OrderStatusSuccess = "SUCCESS" // 支付成功 OrderStatusTimeout = "TIMEOUT" // 支付超时 OrderStatusProcessing = "PROCESSING" // 处理中 OrderStatusFail = "FAIL" // 支付失败 )
const ( ProductURL = "https://developer.toutiao.com/api/apps/ecpay/v1/" SandboxURL = "https://open-sandbox.douyin.com/api/apps/ecpay/v1/" )
const ( OtherSettleParams = "other_settle_params" // 其他分账方参数 (Other settle params) AppId = "app_id" // 小程序appID (Applets appID) ThirdpartyId = "thirdparty_id" // 代小程序进行该笔交易调用的第三方平台服务商 id (The id of the third-party platform service provider that calls the transaction on behalf of the Applets) Sign = "sign" // 签名 (sign) )
Variables ¶
var ( CallbackCheckSignErr = fmt.Errorf("回调请求验签失败") // 验签失败 CallbackMessageDecodeErr = fmt.Errorf("回调请求信息解析错误") )
Functions ¶
This section is empty.
Types ¶
type AccessTokenResponse ¶
type AccessTokenResponse struct { Data struct { AccessToken string `json:"access_token"` Description string `json:"description"` ErrorCode int `json:"error_code"` ExpiresIn string `json:"expires_in"` OpenId string `json:"open_id"` RefreshExpiresIn string `json:"refresh_expires_in"` RefreshToken string `json:"refresh_token"` Scope string `json:"scope"` } `json:"data"` Message string `json:"message"` Extra struct { Logid string `json:"logid"` Now int64 `json:"now"` } `json:"extra"` }
AccessTokenResponse 抖音获取access_token的返回内容
type App ¶
type App struct {
// contains filtered or unexported fields
}
func NewApp ¶
func NewApp(opts *AppOptions) *App
func (*App) DecryptUserPhone ¶
DecryptUserPhone 解密用户手机号 文档 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/phone-number-decode-demo
func (*App) GetAssessToken ¶
func (app *App) GetAssessToken(code string) (*AccessTokenResponse, error)
GetAssessToken 获取授权码 文档 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-permission/get-access-token
func (*App) GetUserinfo ¶
func (app *App) GetUserinfo(accessToken, openid string) (resp *UserinfoResponse, err error)
GetUserinfo 获取用户信息 文档 https://developer.open-douyin.com/docs/resource/zh-CN/dop/develop/openapi/account-management/get-account-open-info
type AppOptions ¶
type CallbackReqeust ¶
type CallbackReqeust struct { Timestamp string `json:"timestamp"` // Unix 时间戳,字符串类型 Nonce string `json:"nonce"` // 随机数 Msg string `json:"msg"` // 订单信息的 json 字符串 Type string `json:"type"` // 回调类型标记,支付成功回调为"payment" MsgSignature string `json:"msg_signature"` // 签名 }
CallbackReqeust 抖音支付回调请求内容
type CallbackRequestMessage ¶
type CallbackRequestMessage struct { Appid string `json:"appid"` // 当前交易发起的小程序id CpOrderno string `json:"cp_orderno"` // 开发者侧的订单号 CpExtra string `json:"cp_extra"` // 预下单时开发者传入字段 Way string `json:"way"` // way 字段中标识了支付渠道: 1-微信支付,2-支付宝支付,10-抖音支付 ChannelNo string `json:"channel_no"` // 支付渠道侧单号(抖音平台请求下游渠道微信或支付宝时传入的单号) PaymentOrderNo string `json:"payment_order_no"` // 支付渠道侧PC单号,支付页面可见(微信支付宝侧的订单号) TotalAmount int64 `json:"total_amount"` // 支付金额,单位为分 Status string `json:"status"` // 固定SUCCESS ItemId string `json:"item_id"` // 订单来源视频对应视频 id SellerUid string `json:"seller_uid"` // 该笔交易卖家商户号 PaidAt int64 `json:"paid_at"` // 支付时间,Unix 时间戳,10 位,整型数 OrderId string `json:"order_id"` // 抖音侧订单号 Extra string `json:"extra"` // 该笔交易卖家商户号 }
CallbackRequestMessage 抖音支付回调请求订单内容
type CallbackResponse ¶
CallbackResponse 抖音支付回调返回内容
type ExpandOrderInfo ¶
type Option ¶
type Option func(*Options)
func WithAppClientKey ¶
func WithAppClientSecret ¶
func WithIsProduct ¶
func WithPayAppId ¶
func WithPayDisableMsg ¶
func WithPayMsgPage ¶
func WithPayNotifyUrl ¶
func WithPaySalt ¶
func WithPayStoreUid ¶
func WithPayThirdpartyId ¶
func WithPayToken ¶
type Options ¶
type Options struct { AppOptions *AppOptions MiniProgramOptions *AppOptions PayOptions *PayOptions }
type PayCreateOrderConfig ¶
type PayCreateOrderConfig struct { OutTradeNo *string TotalAmount *int64 Subject *string Body *string ValidTime *int CpExtra *string DisableMsg *int MsgPage *string ExpandOrderInfo *ExpandOrderInfo LimitPayWay *string NotifyUrl *string }
PayCreateOrderConfig 抖音创建预下单接口配置
type PayCreateOrderRequest ¶
type PayCreateOrderRequest struct { AppId *string `json:"app_id"` // 小程序APPID OutOrderNo *string `json:"out_order_no"` // 开发者侧的订单号。 只能是数字、大小写字母_-*且在同一个app_id下唯一 TotalAmount *int64 `json:"total_amount"` // 支付价格。 单位为[分] Subject *string `json:"subject"` // 商品描述。 长度限制不超过 128 字节且不超过 42 字符 Body *string `json:"body"` // 商品详情 长度限制不超过 128 字节且不超过 42 字符 ValidTime *int `json:"valid_time"` // 订单过期时间(秒)。最小5分钟,最大2天,小于5分钟会被置为5分钟,大于2天会被置为2天 Sign *string `json:"sign"` // 签名 CpExtra *string `json:"cp_extra,omitempty"` // 开发者自定义字段,回调原样回传。 超过最大长度会被截断 NotifyUrl *string `json:"notify_url,omitempty"` // 商户自定义回调地址,必须以 https 开头,支持 443 端口。 指定时,支付成功后抖音会请求该地址通知开发者 ThirdpartyId *string `json:"thirdparty_id,omitempty"` // 第三方平台服务商 id,非服务商模式留空 StoreUid *string `json:"store_uid,omitempty"` // 可用此字段指定本单使用的收款商户号(目前为灰度功能,需要联系平台运营添加白名单,白名单添加1小时后生效;未在白名单的小程序,该字段不生效) DisableMsg *int `json:"disable_msg,omitempty"` // 是否屏蔽支付完成后推送用户抖音消息,1-屏蔽 0-非屏蔽,默认为0。 特别注意: 若接入POI, 请传1。因为POI订单体系会发消息,所以不用再接收一次担保支付推送消息, MsgPage *string `json:"msg_page,omitempty"` // 支付完成后推送给用户的抖音消息跳转页面,开发者需要传入在app.json中定义的链接,如果不传则跳转首页。 ExpandOrderInfo *ExpandOrderInfo `json:"expand_order_info,omitempty"` // 订单拓展信息 LimitPayWay *string `json:"limit_pay_way,omitempty"` // 屏蔽指定支付方式,屏蔽多个支付方式,请使用逗号","分割,枚举值: }
PayCreateOrderRequest 抖音创建预下单接口请求内容
func (*PayCreateOrderRequest) ToMap ¶
func (req *PayCreateOrderRequest) ToMap() map[string]interface{}
ToMap 转换为map
type PayCreateOrderResponse ¶
type PayCreateOrderResponse struct { ErrNo int `json:"err_no"` ErrTips string `json:"err_tips"` Data struct { OrderId string `json:"order_id"` OrderToken string `json:"order_token"` } `json:"data"` }
PayCreateOrderResponse 抖音创建预下单接口返回内容
type PayOptions ¶
type Payment ¶
type Payment struct {
Options *PayOptions
}
func NewPayment ¶
func NewPayment(opts *PayOptions) *Payment
func (*Payment) Callback ¶
func (pay *Payment) Callback(req *CallbackReqeust) (*CallbackRequestMessage, error)
Callback 抖音回调请求处理
func (*Payment) CreateOrder ¶
func (pay *Payment) CreateOrder(conf *PayCreateOrderConfig) (*PayCreateOrderResponse, error)
CreateOrder 预下单接口 文档: https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/ecpay/pay-list/pay
func (*Payment) QueryOrder ¶
func (pay *Payment) QueryOrder(outTradeNo string) (*QueryOrderResponse, error)
type QueryOrderRequest ¶
type QueryOrderRequest struct { AppId *string `json:"app_id"` // 小程序id OutOrderNo *string `json:"out_order_no"` // 开发者侧的订单号 Sign *string `json:"sign"` // 签名 ThirdPartyId *string `json:"thirdparty_id"` // 第三方平台服务商 id,非服务商模式留空 }
QueryOrderRequest 抖音支付订单查询请求内容
func (*QueryOrderRequest) ToMap ¶
func (req *QueryOrderRequest) ToMap() map[string]interface{}
type QueryOrderResponse ¶
type QueryOrderResponse struct { ErrNo int `json:"err_no"` ErrTips string `json:"err_tips"` OutOrderNo string `json:"out_order_no"` OrderId string `json:"order_id"` PaymentInfo struct { TotalFee int `json:"total_fee"` OrderStatus string `json:"order_status"` PayTime string `json:"pay_time"` Way int `json:"way"` ChannelNo string `json:"channel_no"` SellerUid string `json:"seller_uid"` ItemId string `json:"item_id"` CpsInfo string `json:"cps_info"` } `json:"payment_info"` }
QueryOrderResponse 抖音支付订单查询返回内容
type UserinfoResponse ¶
type UserinfoResponse struct { Data struct { Avatar string `json:"avatar"` AvatarLarger string `json:"avatar_larger"` ClientKey string `json:"client_key"` EAccountRole string `json:"e_account_role"` ErrorCode int `json:"error_code"` LogId string `json:"log_id"` Nickname string `json:"nickname"` OpenId string `json:"open_id"` UnionId string `json:"union_id"` EncryptMobile string `json:"encrypt_mobile"` Description string `json:"description"` } `json:"data"` Extra struct { Logid string `json:"logid"` Now int64 `json:"now"` } `json:"extra"` Message string `json:"message"` }
UserinfoResponse 抖音获取用户信息的返回内容