update
This commit is contained in:
parent
b7a8867716
commit
d8fc978608
26
Dockerfile
Normal file
26
Dockerfile
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#编译阶段镜像
|
||||||
|
FROM golang:alpine AS builder
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
RUN go env -w GOPRIVATE="gitea.youtukeji.com.cn"
|
||||||
|
RUN go env -w GOPROXY="https://goproxy.cn,direct"
|
||||||
|
RUN go mod tidy
|
||||||
|
RUN go build -o /app/ecpm cmd/main.go
|
||||||
|
|
||||||
|
#运行阶段镜像
|
||||||
|
FROM alpine AS runtime
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY --from=builder /app/ecpm /app/ecpm
|
||||||
|
|
||||||
|
ENV TZ=Asia/Shanghai
|
||||||
|
ENV APP_ENV=prod
|
||||||
|
ENV LOG_PATH=/app/data/logs/ecpm.log
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/ecpm"]
|
||||||
|
|
||||||
|
LABEL authors="xiabin"
|
@ -82,9 +82,9 @@ func (ctl *DouyinOpenApiController) GetEcpm(c *gin.Context) {
|
|||||||
func (ctl *DouyinOpenApiController) Code2OpenId(c *gin.Context) {
|
func (ctl *DouyinOpenApiController) Code2OpenId(c *gin.Context) {
|
||||||
code := c.Query("code")
|
code := c.Query("code")
|
||||||
anonymousOpenid := c.Query("anonymous_openid")
|
anonymousOpenid := c.Query("anonymous_openid")
|
||||||
mpid := c.Query("mpid")
|
appId := c.Query("app_id")
|
||||||
|
|
||||||
douyinCli, err := ctl.douyinCli.GetDouYinOpenApi(mpid)
|
douyinCli, err := ctl.douyinCli.GetDouYinOpenApi(appId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctl.logger.Sugar().Error("获取小程序登录地址失败", err)
|
ctl.logger.Sugar().Error("获取小程序登录地址失败", err)
|
||||||
c.JSON(200, gin.H{
|
c.JSON(200, gin.H{
|
||||||
@ -103,5 +103,14 @@ func (ctl *DouyinOpenApiController) Code2OpenId(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.String(http.StatusOK, res.Data.Openid)
|
|
||||||
|
if res.Errcode != 0 {
|
||||||
|
ctl.logger.Sugar().Errorf("Code2Session 错误,res : %+v", res)
|
||||||
|
c.JSON(200, gin.H{
|
||||||
|
"code": 500,
|
||||||
|
"msg": http.StatusOK,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.String(http.StatusOK, res.Openid)
|
||||||
}
|
}
|
||||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.23.4
|
|||||||
replace gitea.youtukeji.com.cn/xiabin/douyin-openapi => ../douyin-openapi
|
replace gitea.youtukeji.com.cn/xiabin/douyin-openapi => ../douyin-openapi
|
||||||
|
|
||||||
require (
|
require (
|
||||||
gitea.youtukeji.com.cn/xiabin/douyin-openapi v0.0.1
|
gitea.youtukeji.com.cn/xiabin/douyin-openapi v0.0.4
|
||||||
github.com/gin-contrib/zap v1.1.4
|
github.com/gin-contrib/zap v1.1.4
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/google/wire v0.6.0
|
github.com/google/wire v0.6.0
|
||||||
|
2
go.sum
2
go.sum
@ -1,3 +1,5 @@
|
|||||||
|
gitea.youtukeji.com.cn/xiabin/douyin-openapi v0.0.3 h1:aDHEBU2s8Yb6HknPCpEjTBVHtdUXw8ZaROmY3fXvr6A=
|
||||||
|
gitea.youtukeji.com.cn/xiabin/douyin-openapi v0.0.3/go.mod h1:7d5OkLrsgX/iI4E9nVi2hYC2vvLrDi/QKCuTF4S/k6g=
|
||||||
github.com/bytedance/sonic v1.12.1 h1:jWl5Qz1fy7X1ioY74WqO0KjAMtAGQs4sYnjiEBiyX24=
|
github.com/bytedance/sonic v1.12.1 h1:jWl5Qz1fy7X1ioY74WqO0KjAMtAGQs4sYnjiEBiyX24=
|
||||||
github.com/bytedance/sonic v1.12.1/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
github.com/bytedance/sonic v1.12.1/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk=
|
||||||
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU=
|
||||||
|
@ -16,7 +16,6 @@ type DouYinOpenApiClient struct {
|
|||||||
|
|
||||||
type DouYinApi struct {
|
type DouYinApi struct {
|
||||||
Api *douyinopenapi.DouYinOpenApi // 抖音openapi客户端
|
Api *douyinopenapi.DouYinOpenApi // 抖音openapi客户端
|
||||||
Token *access_token.DefaultAccessToken // 抖音token管理
|
|
||||||
ecpmValue uint32 // ECPM值
|
ecpmValue uint32 // ECPM值
|
||||||
viewCount uint32 //浏览数
|
viewCount uint32 //浏览数
|
||||||
}
|
}
|
||||||
@ -57,11 +56,16 @@ func (d *DouYinOpenApiClient) SetDouYinOpenApi(appId string, api *DouYinApi) {
|
|||||||
// appSecret: 小程序secret
|
// appSecret: 小程序secret
|
||||||
// cache: 缓存
|
// cache: 缓存
|
||||||
func (d *DouYinOpenApiClient) NewAndStoreDouYinOpenApi(appId, appSecret string, ecpmValue uint32, viewCount uint32, cache cache.Cache) {
|
func (d *DouYinOpenApiClient) NewAndStoreDouYinOpenApi(appId, appSecret string, ecpmValue uint32, viewCount uint32, cache cache.Cache) {
|
||||||
api := douyinopenapi.NewDouYinOpenApi(douyinopenapi.DouYinOpenApiConfig{})
|
|
||||||
token := access_token.NewDefaultAccessToken(appId, appSecret, cache, false)
|
token := access_token.NewDefaultAccessToken(appId, appSecret, cache, false)
|
||||||
|
api := douyinopenapi.NewDouYinOpenApi(douyinopenapi.DouYinOpenApiConfig{
|
||||||
|
AppId: appId,
|
||||||
|
AppSecret: appSecret,
|
||||||
|
AccessToken: token,
|
||||||
|
Cache: cache,
|
||||||
|
IsSandbox: false,
|
||||||
|
})
|
||||||
d.SetDouYinOpenApi(appId, &DouYinApi{
|
d.SetDouYinOpenApi(appId, &DouYinApi{
|
||||||
Api: api,
|
Api: api,
|
||||||
Token: token,
|
|
||||||
ecpmValue: ecpmValue,
|
ecpmValue: ecpmValue,
|
||||||
viewCount: viewCount,
|
viewCount: viewCount,
|
||||||
})
|
})
|
||||||
@ -98,7 +102,7 @@ func (d *DouYinOpenApiClient) GetEcpmData(appId, openId, dateHour string) (list
|
|||||||
}
|
}
|
||||||
|
|
||||||
//获取accessToken
|
//获取accessToken
|
||||||
accessToken, err := douyin.Token.GetAccessToken()
|
accessToken, err := douyin.Api.GetAccessToken()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user