This commit is contained in:
邹宗楠
2022-06-02 10:13:26 +08:00
parent dad0d7bb19
commit 7de52d4ab3
6 changed files with 85 additions and 80 deletions

View File

@@ -16,43 +16,6 @@ const (
TtPayWay = "10" // 10-抖音支付
)
type CallBackResult struct {
Timestamp int `json:"timestamp"` // Unix 时间戳10 位,整型数
Nonce string `json:"nonce"` // 随机数
Msg string `json:"msg"` // 订单信息的 json 字符串
TypePay string `json:"type"` // 回调类型标记,支付成功回调为"payment"
Msgsignature string `json:"msgsignature"` // 签名,详见
}
// 详细信息MSG(支付回调)
type DetailCallBackMessage 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"` // 支付渠道侧商家订单号
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"` // 抖音侧订单号
}
// 详细信息MSG(退款回调)
type DetailCallBackMessage2Refund struct {
AppId string `json:"appid"` // 当前交易发起的小程序id
CpRefundno string `json:"cp_refundno"` // 开发者侧的退款订单号
CpExtra string `json:"cp_extra"` // 预下单时开发者传入字段
Status string `json:"status"` // 固定SUCCESS/FAIL
RefundAmount int64 `json:"refund_amount"` // 退款金额
RefundedAt int64 `json:"refunded_at"` // 退款时间
Message string `json:"message"` // 退款失败描述
OrderId string `json:"order_id"` // 抖音侧订单号
}
func (a *API) GetCallbackMsg(request *http.Request) (call *DetailCallBackMessage, refund *DetailCallBackMessage2Refund, payType string, err error) {
data, err := ioutil.ReadAll(request.Body)
if err != nil {

View File

@@ -11,6 +11,10 @@ const (
BaseURL = "https://open.snssdk.com" // 头条
TiktokTokenUrl = "oauth/access_token/"
TiktokRefreshTokenUrl = "oauth/renew_refresh_token/"
salt = "TUsUuzcfWriQ8ZXUQOrxPcScjEGlgMSjJaDMCtVy"
ResponseCodeSuccess = "SUCCESS"
ResponseCodeFail = "FAIL"
)
type API struct {

View File

@@ -10,12 +10,6 @@ import (
"time"
)
const (
salt = "TUsUuzcfWriQ8ZXUQOrxPcScjEGlgMSjJaDMCtVy"
ResponseCodeSuccess = "SUCCESS"
ResponseCodeFail = "FAIL"
)
// 获取支付签名
func (a *API) Sign(paramsMap map[string]interface{}) string {
var paramsArr []string

View File

@@ -4,6 +4,43 @@ const (
PayUrl = "https://developer.toutiao.com/api/apps/ecpay/v1/create_order"
)
// OauthAccessTokenResData access_token
type OauthAccessTokenResData struct {
ErrorCode int64 `json:"error_code"` // 错误码
ExpiresIn uint64 `json:"expires_in"` // access_token接口调用凭证超时时间单位
OpenId string `json:"open_id"` // 授权用户唯一标识
RefreshExpiresIn int64 `json:"refresh_expires_in"` // refresh_token凭证超时时间单位秒)
RefreshToken string `json:"refresh_token"` // 用户刷新access_token
Scope string `json:"scope"` // 用户授权的作用域(Scope),使用逗号(,分隔开放平台几乎几乎每个接口都需要特定的Scope。
AccessToken string `json:"access_token"` // 接口调用凭证
Description string `json:"description"` // 错误码描述
}
// DYError 错误结构体
type DYError struct {
ErrorCode int64 `json:"error_code,omitempty"` // 错误码
Description string `json:"description,omitempty"` // 错误码描述
}
// OauthAccessTokenRes access_token
type OauthAccessTokenRes struct {
Data *OauthAccessTokenResData
Message string `json:"message"`
}
// 抖音登录返回值
type TiktokOauthResone struct {
ErrNo int64 `json:"err_no"`
ErrTips string `json:"err_tips"`
Data *struct {
SessionKey string `json:"session_key"`
OpenId string `json:"openid"` // 授权用户唯一标识
AnonymousOpenid string `json:"anonymous_openid"`
Unionid string `json:"unionid"`
Dopenid string `json:"dopenid"`
}
}
// 预下单
type TickTokCreateOrder struct {
AppID string `json:"app_id"` // 小程序APPID
@@ -45,3 +82,41 @@ type ReturnMoneyReq struct {
CpExtra string `json:"cp_extra"`
NotifyURL string `json:"notify_url"`
}
/***************回调****************/
type CallBackResult struct {
Timestamp int `json:"timestamp"` // Unix 时间戳10 位,整型数
Nonce string `json:"nonce"` // 随机数
Msg string `json:"msg"` // 订单信息的 json 字符串
TypePay string `json:"type"` // 回调类型标记,支付成功回调为"payment"
Msgsignature string `json:"msgsignature"` // 签名,详见
}
// 详细信息MSG(支付回调)
type DetailCallBackMessage 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"` // 支付渠道侧商家订单号
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"` // 抖音侧订单号
}
// 详细信息MSG(退款回调)
type DetailCallBackMessage2Refund struct {
AppId string `json:"appid"` // 当前交易发起的小程序id
CpRefundno string `json:"cp_refundno"` // 开发者侧的退款订单号
CpExtra string `json:"cp_extra"` // 预下单时开发者传入字段
Status string `json:"status"` // 固定SUCCESS/FAIL
RefundAmount int64 `json:"refund_amount"` // 退款金额
RefundedAt int64 `json:"refunded_at"` // 退款时间
Message string `json:"message"` // 退款失败描述
OrderId string `json:"order_id"` // 抖音侧订单号
}

View File

@@ -39,3 +39,9 @@ func TestCode22(t *testing.T) {
fmt.Println(1&1 != 0)
fmt.Println(2&2 != 0)
}
func TestGetToken(t *testing.T) {
a := New("5c08a0465cf0f996af254a03b6c2548defef87ad", "tta6a1d01c399f264201")
a.GetTiktokToken()
fmt.Println(a.msgToken)
}

View File

@@ -4,43 +4,6 @@ import (
"git.rosy.net.cn/baseapi/utils"
)
// OauthAccessTokenResData access_token
type OauthAccessTokenResData struct {
ErrorCode int64 `json:"error_code"` // 错误码
ExpiresIn uint64 `json:"expires_in"` // access_token接口调用凭证超时时间单位
OpenId string `json:"open_id"` // 授权用户唯一标识
RefreshExpiresIn int64 `json:"refresh_expires_in"` // refresh_token凭证超时时间单位秒)
RefreshToken string `json:"refresh_token"` // 用户刷新access_token
Scope string `json:"scope"` // 用户授权的作用域(Scope),使用逗号(,分隔开放平台几乎几乎每个接口都需要特定的Scope。
AccessToken string `json:"access_token"` // 接口调用凭证
Description string `json:"description"` // 错误码描述
}
// DYError 错误结构体
type DYError struct {
ErrorCode int64 `json:"error_code,omitempty"` // 错误码
Description string `json:"description,omitempty"` // 错误码描述
}
// OauthAccessTokenRes access_token
type OauthAccessTokenRes struct {
Data *OauthAccessTokenResData
Message string `json:"message"`
}
// 抖音登录返回值
type TiktokOauthResone struct {
ErrNo int64 `json:"err_no"`
ErrTips string `json:"err_tips"`
Data *struct {
SessionKey string `json:"session_key"`
OpenId string `json:"openid"` // 授权用户唯一标识
AnonymousOpenid string `json:"anonymous_openid"`
Unionid string `json:"unionid"`
Dopenid string `json:"dopenid"`
}
}
// 获取抖音登录授权2
func (a *API) GetTiktokOauth(code string) (*TiktokOauthResone, error) {
tokenReq := make(map[string]interface{}, 3)