Initial commit

This commit is contained in:
Donny
2019-04-22 20:46:32 +08:00
commit 49ab8aadd1
25441 changed files with 4055000 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/live/app-room/api/http/v1:all-srcs",
"//app/interface/live/app-room/cmd:all-srcs",
"//app/interface/live/app-room/conf:all-srcs",
"//app/interface/live/app-room/dao:all-srcs",
"//app/interface/live/app-room/model:all-srcs",
"//app/interface/live/app-room/server/http:all-srcs",
"//app/interface/live/app-room/service:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,15 @@
# v1.0.1
1. 送礼后的充值弹窗
# v1.0.0
1. 上线功能xxx
# v1.1.6
1. 添加版本控制
# v1.1.7
1. 传递roomid至验证码服务
# v1.1.8
1. 修复TipRechargeAction 方法为post

View File

@@ -0,0 +1,7 @@
# Owner
zhangwei01
# Author
# Reviewer
zhaohailin

View File

@@ -0,0 +1,13 @@
# See the OWNERS docs at https://go.k8s.io/owners
approvers:
- zhangwei01
labels:
- interface
- interface/live/app-room
- live
options:
no_parent_owners: true
reviewers:
- shenli01
- zhaohailin

View File

@@ -0,0 +1,12 @@
# app-room-interface
# 项目简介
1.
# 编译环境
# 依赖包
# 编译执行

View File

@@ -0,0 +1 @@
# HTTP API文档

View File

@@ -0,0 +1,65 @@
load(
"@io_bazel_rules_go//proto:def.bzl",
"go_proto_library",
)
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
proto_library(
name = "v1_proto",
srcs = [
"api.proto",
"dm.proto",
"gift.proto",
"roomNotice.proto",
],
tags = ["automanaged"],
deps = ["@gogo_special_proto//github.com/gogo/protobuf/gogoproto"],
)
go_proto_library(
name = "v1_go_proto",
compilers = ["@io_bazel_rules_go//proto:gogofast_grpc"],
importpath = "go-common/app/interface/live/app-room/api/http/v1",
proto = ":v1_proto",
tags = ["automanaged"],
deps = ["@com_github_gogo_protobuf//gogoproto:go_default_library"],
)
go_library(
name = "go_default_library",
srcs = [
"dm.bm.go",
"gift.bm.go",
"roomNotice.bm.go",
],
embed = [":v1_go_proto"],
importpath = "go-common/app/interface/live/app-room/api/http/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/binding:go_default_library",
"@com_github_gogo_protobuf//gogoproto:go_default_library",
"@com_github_gogo_protobuf//proto:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,472 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: api.proto
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
// 获取banner配置(客户端)
type GetBannerResp struct {
Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id"`
Img string `protobuf:"bytes,2,opt,name=img,proto3" json:"img"`
Link string `protobuf:"bytes,3,opt,name=link,proto3" json:"link"`
Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *GetBannerResp) Reset() { *m = GetBannerResp{} }
func (m *GetBannerResp) String() string { return proto.CompactTextString(m) }
func (*GetBannerResp) ProtoMessage() {}
func (*GetBannerResp) Descriptor() ([]byte, []int) {
return fileDescriptor_api_4b14556a41d2f2e2, []int{0}
}
func (m *GetBannerResp) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *GetBannerResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_GetBannerResp.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalTo(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (dst *GetBannerResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_GetBannerResp.Merge(dst, src)
}
func (m *GetBannerResp) XXX_Size() int {
return m.Size()
}
func (m *GetBannerResp) XXX_DiscardUnknown() {
xxx_messageInfo_GetBannerResp.DiscardUnknown(m)
}
var xxx_messageInfo_GetBannerResp proto.InternalMessageInfo
func (m *GetBannerResp) GetId() int64 {
if m != nil {
return m.Id
}
return 0
}
func (m *GetBannerResp) GetImg() string {
if m != nil {
return m.Img
}
return ""
}
func (m *GetBannerResp) GetLink() string {
if m != nil {
return m.Link
}
return ""
}
func (m *GetBannerResp) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
func init() {
proto.RegisterType((*GetBannerResp)(nil), "live.approom.v1.GetBannerResp")
}
func (m *GetBannerResp) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *GetBannerResp) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Id != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintApi(dAtA, i, uint64(m.Id))
}
if len(m.Img) > 0 {
dAtA[i] = 0x12
i++
i = encodeVarintApi(dAtA, i, uint64(len(m.Img)))
i += copy(dAtA[i:], m.Img)
}
if len(m.Link) > 0 {
dAtA[i] = 0x1a
i++
i = encodeVarintApi(dAtA, i, uint64(len(m.Link)))
i += copy(dAtA[i:], m.Link)
}
if len(m.Title) > 0 {
dAtA[i] = 0x22
i++
i = encodeVarintApi(dAtA, i, uint64(len(m.Title)))
i += copy(dAtA[i:], m.Title)
}
if m.XXX_unrecognized != nil {
i += copy(dAtA[i:], m.XXX_unrecognized)
}
return i, nil
}
func encodeVarintApi(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *GetBannerResp) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Id != 0 {
n += 1 + sovApi(uint64(m.Id))
}
l = len(m.Img)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.Link)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
l = len(m.Title)
if l > 0 {
n += 1 + l + sovApi(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovApi(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozApi(x uint64) (n int) {
return sovApi(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *GetBannerResp) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: GetBannerResp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: GetBannerResp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Id", wireType)
}
m.Id = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Id |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Img", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Img = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Link", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Link = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowApi
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthApi
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Title = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipApi(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthApi
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipApi(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowApi
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowApi
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowApi
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthApi
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowApi
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipApi(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthApi = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowApi = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("api.proto", fileDescriptor_api_4b14556a41d2f2e2) }
var fileDescriptor_api_4b14556a41d2f2e2 = []byte{
// 213 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xe2, 0x4c, 0x2c, 0xc8, 0xd4,
0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0xcf, 0xc9, 0x2c, 0x4b, 0xd5, 0x4b, 0x2c, 0x28, 0x28,
0xca, 0xcf, 0xcf, 0xd5, 0x2b, 0x33, 0x94, 0xd2, 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b,
0xce, 0xcf, 0xd5, 0x4f, 0xcf, 0x4f, 0xcf, 0xd7, 0x07, 0xab, 0x4b, 0x2a, 0x4d, 0x03, 0xf3, 0xc0,
0x1c, 0x30, 0x0b, 0xa2, 0x5f, 0xa9, 0x91, 0x91, 0x8b, 0xd7, 0x3d, 0xb5, 0xc4, 0x29, 0x31, 0x2f,
0x2f, 0xb5, 0x28, 0x28, 0xb5, 0xb8, 0x40, 0x48, 0x8c, 0x8b, 0x29, 0x33, 0x45, 0x82, 0x51, 0x81,
0x51, 0x83, 0xd9, 0x89, 0xed, 0xd5, 0x3d, 0x79, 0xa6, 0xcc, 0x94, 0x20, 0xa6, 0xcc, 0x14, 0x21,
0x49, 0x2e, 0xe6, 0xcc, 0xdc, 0x74, 0x09, 0x26, 0x05, 0x46, 0x0d, 0x4e, 0x27, 0xf6, 0x57, 0xf7,
0xe4, 0x41, 0xdc, 0x20, 0x10, 0x21, 0x24, 0xc3, 0xc5, 0x92, 0x93, 0x99, 0x97, 0x2d, 0xc1, 0x0c,
0x96, 0xe3, 0x78, 0x75, 0x4f, 0x1e, 0xcc, 0x0f, 0x02, 0x93, 0x42, 0xf2, 0x5c, 0xac, 0x25, 0x99,
0x25, 0x39, 0xa9, 0x12, 0x2c, 0x60, 0x69, 0xce, 0x57, 0xf7, 0xe4, 0x21, 0x02, 0x41, 0x10, 0xca,
0x49, 0xe0, 0xc4, 0x23, 0x39, 0xc6, 0x0b, 0x8f, 0xe4, 0x18, 0x1f, 0x3c, 0x92, 0x63, 0x8c, 0x62,
0x2a, 0x33, 0x4c, 0x62, 0x03, 0x3b, 0xce, 0x18, 0x10, 0x00, 0x00, 0xff, 0xff, 0x1f, 0x57, 0x53,
0x50, 0xe9, 0x00, 0x00, 0x00,
}

View File

@@ -0,0 +1,13 @@
syntax = "proto3";
package live.approom.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// 获取banner配置(客户端)
message GetBannerResp {
int64 id = 1 [(gogoproto.jsontag) = "id"];
string img = 2 [(gogoproto.jsontag) = "img"];
string link = 3 [(gogoproto.jsontag) = "link"];
string title = 4 [(gogoproto.jsontag) = "title"];
}

View File

@@ -0,0 +1,73 @@
// Code generated by protoc-gen-bm v0.1, DO NOT EDIT.
// source: dm.proto
/*
Package v1 is a generated blademaster stub package.
This code was generated with go-common/app/tool/bmgen/protoc-gen-bm v0.1.
It is generated from these files:
dm.proto
*/
package v1
import (
"context"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
)
// to suppressed 'imported but not used warning'
var _ *bm.Context
var _ context.Context
var _ binding.StructValidator
var PathDMSendMsg = "/live.approom.v1.DM/SendMsg"
var PathDMGetHistory = "/live.approom.v1.DM/GetHistory"
// ============
// DM Interface
// ============
type DMBMServer interface {
// `method:"POST"`
SendMsg(ctx context.Context, req *SendDMReq) (resp *SendMsgResp, err error)
// `method:"POST"`
GetHistory(ctx context.Context, req *HistoryReq) (resp *HistoryResp, err error)
}
var v1DMSvc DMBMServer
func dMSendMsg(c *bm.Context) {
p := new(SendDMReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1DMSvc.SendMsg(c, p)
c.JSON(resp, err)
}
func dMGetHistory(c *bm.Context) {
p := new(HistoryReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1DMSvc.GetHistory(c, p)
c.JSON(resp, err)
}
// RegisterV1DMService Register the blademaster route with middleware map
// midMap is the middleware map, the key is defined in proto
func RegisterV1DMService(e *bm.Engine, svc DMBMServer, midMap map[string]bm.HandlerFunc) {
v1DMSvc = svc
e.POST("/xlive/app-room/v1/dM/SendMsg", dMSendMsg)
e.POST("/xlive/app-room/v1/dM/GetHistory", dMGetHistory)
}
// RegisterDMBMServer Register the blademaster route
func RegisterDMBMServer(e *bm.Engine, server DMBMServer) {
v1DMSvc = server
e.POST("/live.approom.v1.DM/SendMsg", dMSendMsg)
e.POST("/live.approom.v1.DM/GetHistory", dMGetHistory)
}

View File

@@ -0,0 +1,64 @@
<!-- package=live.approom.v1 -->
- [/xlive/app-room/v1/dM/SendMsg](#xliveapp-roomv1dMSendMsg)
- [/xlive/app-room/v1/dM/GetHistory](#xliveapp-roomv1dMGetHistory)
## /xlive/app-room/v1/dM/SendMsg
### 无标题
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|roomid|是|integer||
|msg|是|string||
|rnd|是|string||
|fontsize|是|integer||
|mode|否|integer||
|color|是|integer||
|bubble|否|integer||
|build|否|integer||
|anti|否|string||
|platform|否|string||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /xlive/app-room/v1/dM/GetHistory
### 无标题
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|roomid|是|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"Room": [
""
],
"Admin": [
""
]
}
}
```

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,39 @@
syntax = "proto3";
package live.approom.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
message SendDMReq {
int64 roomid = 1 [(gogoproto.moretags) = 'form:"cid" validate:"required"'];
string msg = 2 [(gogoproto.moretags) = 'form:"msg" validate:"required"'];
string rnd = 3 [(gogoproto.moretags) = 'form:"rnd" validate:"required"'];
int64 fontsize = 4 [(gogoproto.moretags) = 'form:"fontsize" validate:"required"'];
int64 mode = 5 [(gogoproto.moretags) = 'form:"mode" validate:"gte=0"'];
int64 color = 6 [(gogoproto.moretags) = 'form:"color" validate:"required"'];
int64 bubble = 7 [(gogoproto.moretags) = 'form:"bubble"'];
int64 build = 8 [(gogoproto.moretags) = 'form:"build"'];
string anti = 9 [(gogoproto.moretags) = 'form:"_anti"'];
string platform = 10 [(gogoproto.moretags) = 'form:"platform"'];
}
message SendMsgResp {
}
message HistoryReq {
int64 roomid = 1 [(gogoproto.moretags) = 'form:"room_id" validate:"required"'];
}
message HistoryResp {
repeated string Room = 1;
repeated string Admin = 2;
}
service DM{
// `method:"POST"`
rpc SendMsg(SendDMReq) returns (SendMsgResp);
// `method:"POST"`
rpc GetHistory(HistoryReq) returns (HistoryResp);
}

View File

@@ -0,0 +1,106 @@
// Code generated by protoc-gen-bm v0.1, DO NOT EDIT.
// source: gift.proto
/*
Package v1 is a generated blademaster stub package.
This code was generated with go-common/app/tool/bmgen/protoc-gen-bm v0.1.
It is generated from these files:
gift.proto
*/
package v1
import (
"context"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
)
// to suppressed 'imported but not used warning'
var _ *bm.Context
var _ context.Context
var _ binding.StructValidator
var PathGiftDailyBag = "/live.approom.v1.Gift/daily_bag"
var PathGiftNeedTipRecharge = "/live.approom.v1.Gift/NeedTipRecharge"
var PathGiftTipRechargeAction = "/live.approom.v1.Gift/TipRechargeAction"
var PathGiftGiftConfig = "/live.approom.v1.Gift/gift_config"
// ==============
// Gift Interface
// ==============
type GiftBMServer interface {
// 每日礼包接口
// `midware:"guest"`
DailyBag(ctx context.Context, req *DailyBagReq) (resp *DailyBagResp, err error)
// `midware:"auth"`
NeedTipRecharge(ctx context.Context, req *NeedTipRechargeReq) (resp *NeedTipRechargeResp, err error)
// `midware:"auth" method:"post"`
TipRechargeAction(ctx context.Context, req *TipRechargeActionReq) (resp *TipRechargeActionResp, err error)
// 礼物全量配置
GiftConfig(ctx context.Context, req *GiftConfigReq) (resp *GiftConfigResp, err error)
}
var v1GiftSvc GiftBMServer
func giftDailyBag(c *bm.Context) {
p := new(DailyBagReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1GiftSvc.DailyBag(c, p)
c.JSON(resp, err)
}
func giftNeedTipRecharge(c *bm.Context) {
p := new(NeedTipRechargeReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1GiftSvc.NeedTipRecharge(c, p)
c.JSON(resp, err)
}
func giftTipRechargeAction(c *bm.Context) {
p := new(TipRechargeActionReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1GiftSvc.TipRechargeAction(c, p)
c.JSON(resp, err)
}
func giftGiftConfig(c *bm.Context) {
p := new(GiftConfigReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1GiftSvc.GiftConfig(c, p)
c.JSON(resp, err)
}
// RegisterV1GiftService Register the blademaster route with middleware map
// midMap is the middleware map, the key is defined in proto
func RegisterV1GiftService(e *bm.Engine, svc GiftBMServer, midMap map[string]bm.HandlerFunc) {
auth := midMap["auth"]
guest := midMap["guest"]
v1GiftSvc = svc
e.GET("/xlive/app-room/v1/gift/daily_bag", guest, giftDailyBag)
e.GET("/xlive/app-room/v1/gift/NeedTipRecharge", auth, giftNeedTipRecharge)
e.POST("/xlive/app-room/v1/gift/TipRechargeAction", auth, giftTipRechargeAction)
e.GET("/xlive/app-room/v1/gift/gift_config", giftGiftConfig)
}
// RegisterGiftBMServer Register the blademaster route
func RegisterGiftBMServer(e *bm.Engine, server GiftBMServer) {
v1GiftSvc = server
e.GET("/live.approom.v1.Gift/daily_bag", giftDailyBag)
e.GET("/live.approom.v1.Gift/NeedTipRecharge", giftNeedTipRecharge)
e.POST("/live.approom.v1.Gift/TipRechargeAction", giftTipRechargeAction)
e.GET("/live.approom.v1.Gift/gift_config", giftGiftConfig)
}

View File

@@ -0,0 +1,174 @@
<!-- package=live.approom.v1 -->
- [/xlive/app-room/v1/gift/daily_bag](#xliveapp-roomv1giftdaily_bag) 每日礼包接口
- [/xlive/app-room/v1/gift/NeedTipRecharge](#xliveapp-roomv1giftNeedTipRecharge)
- [/xlive/app-room/v1/gift/TipRechargeAction](#xliveapp-roomv1giftTipRechargeAction)
- [/xlive/app-room/v1/gift/gift_config](#xliveapp-roomv1giftgift_config) 礼物全量配置
## /xlive/app-room/v1/gift/daily_bag
### 每日礼包接口
#### 方法GET
#### 请求参数
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"bag_status": 0,
"bag_expire_status": 0,
"bag_toast": {
"toast_status": 0,
"toast_message": ""
},
"bag_list": [
{
"type": 0,
"bag_name": "",
"source": {
"medal_id": 0,
"medal_name": "",
"level": 0,
"user_level": 0
},
"gift_list": [
{
"gift_id": "",
"gift_num": 0,
"expire_at": 0
}
]
}
]
}
}
```
## /xlive/app-room/v1/gift/NeedTipRecharge
### 无标题
> 需要登录
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|from|是|integer| 来源 1金瓜子 2 银瓜子|
|needGold|否|integer| 需要的金瓜子 如果From=2 那么直接传0|
|platform|是|string| 平台 android ios|
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
// 是否展示
"show": 0,
// bp
"bp": 0.1,
// bp券
"bpCoupon": 0.1,
// 需要充值的金瓜子
"rechargeGold": 0
}
}
```
## /xlive/app-room/v1/gift/TipRechargeAction
### 无标题
> 需要登录
#### 方法POST
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|from|是|integer| 来源 1金瓜子 2 银瓜子|
|action|是|integer|行为 1 停止推送|
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
}
}
```
## /xlive/app-room/v1/gift/gift_config
###礼物全量配置
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|platform|否|string||
|build|否|integer||
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
"list": [
{
"id": 0,
"name": "",
"price": 0,
"type": 0,
"coin_type": "",
"bag_gift": 0,
"effect": 0,
"corner_mark": "",
"broadcast": 0,
"draw": 0,
"stay_time": 0,
"animation_frame_num": 0,
"desc": "",
"rule": "",
"rights": "",
"privilege_required": 0,
"count_map": [
{
"num": 0,
"text": ""
}
],
"img_basic": "",
"img_dynamic": "",
"frame_animation": "",
"gif": "",
"webp": "",
"full_sc_web": "",
"full_sc_horizontal": "",
"full_sc_vertical": "",
"full_sc_horizontal_svga": "",
"full_sc_vertical_svga": "",
"bullet_head": "",
"bullet_tail": "",
"limit_interval": 0
}
]
}
}
```

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,139 @@
syntax = "proto3";
package live.approom.v1;
option go_package = "v1";
option (gogoproto.goproto_getters_all) = false;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
service Gift{
// 每日礼包接口
// `midware:"guest"`
rpc daily_bag(DailyBagReq) returns (DailyBagResp);
// `midware:"auth"`
rpc NeedTipRecharge (NeedTipRechargeReq) returns (NeedTipRechargeResp);
// `midware:"auth" method:"post"`
rpc TipRechargeAction (TipRechargeActionReq) returns(TipRechargeActionResp);
//礼物全量配置
rpc gift_config(GiftConfigReq) returns (GiftConfigResp);
}
message DailyBagReq{
}
message DailyBagResp{
int64 bag_status=1 [(gogoproto.jsontag)="bag_status"];
int64 bag_expire_status=2 [(gogoproto.jsontag)="bag_expire_status"];
BagToast bag_toast = 3 [(gogoproto.jsontag)="bag_toast"];
message BagToast{
int64 toast_status=1 [(gogoproto.jsontag)="toast_status"];
string toast_message=2 [(gogoproto.jsontag)="toast_message"];
}
repeated BagList bag_list = 4 [(gogoproto.jsontag)="bag_list"];
message BagList{
int64 type=1 [(gogoproto.jsontag)="type"];
string bag_name=2 [(gogoproto.jsontag)="bag_name"];
Source source = 3 [(gogoproto.jsontag)="source"];
message Source{
int64 medal_id = 1 [(gogoproto.jsontag)="medal_id"];
string medal_name = 2 [(gogoproto.jsontag)="medal_name"];
int64 level = 3 [(gogoproto.jsontag)="level"];
int64 user_level = 4 [(gogoproto.jsontag)="user_level"];
}
repeated GiftList gift_list = 4 [(gogoproto.jsontag)="gift_list"];
message GiftList{
string gift_id=1 [(gogoproto.jsontag)="gift_id"];
int64 gift_num=2 [(gogoproto.jsontag)="gift_num"];
int64 expire_at=3 [(gogoproto.jsontag)="expire_at"];
}
}
}
message GiftConfigReq{
string platform = 1 [(gogoproto.moretags) = 'form:"platform"'];
int64 build = 2 [(gogoproto.moretags) = 'form:"build"'];
}
message GiftConfigResp{
repeated Config list = 1 [(gogoproto.jsontag)="list"];
message Config{
int64 id = 1 [(gogoproto.jsontag)="id"];
string name = 2 [(gogoproto.jsontag)="name"];
int64 price = 3 [(gogoproto.jsontag)="price"];
int64 type = 4 [(gogoproto.jsontag)="type"];
string coin_type = 5 [(gogoproto.jsontag)="coin_type"];
int64 bag_gift = 6 [(gogoproto.jsontag)="bag_gift"];
int64 effect = 7 [(gogoproto.jsontag)="effect"];
string corner_mark = 8 [(gogoproto.jsontag)="corner_mark"];
int64 broadcast = 9 [(gogoproto.jsontag)="broadcast"];
int64 draw = 10 [(gogoproto.jsontag)="draw"];
int64 stay_time = 11 [(gogoproto.jsontag)="stay_time"];
int64 animation_frame_num = 12 [(gogoproto.jsontag)="animation_frame_num"];
string desc = 13 [(gogoproto.jsontag)="desc"];
string rule = 14 [(gogoproto.jsontag)="rule"];
string rights = 15 [(gogoproto.jsontag)="rights"];
int64 privilege_required = 16 [(gogoproto.jsontag)="privilege_required"];
repeated CountMap count_map = 17 [(gogoproto.jsontag)="count_map"];
string img_basic = 18 [(gogoproto.jsontag)="img_basic"];
string img_dynamic = 19 [(gogoproto.jsontag)="img_dynamic"];
string frame_animation = 20 [(gogoproto.jsontag)="frame_animation"];
string gif = 21 [(gogoproto.jsontag)="gif"];
string webp = 22 [(gogoproto.jsontag)="webp"];
string full_sc_web = 23 [(gogoproto.jsontag)="full_sc_web"];
string full_sc_horizontal = 24 [(gogoproto.jsontag)="full_sc_horizontal"];
string full_sc_vertical = 25 [(gogoproto.jsontag)="full_sc_vertical"];
string full_sc_horizontal_svga = 26 [(gogoproto.jsontag)="full_sc_horizontal_svga"];
string full_sc_vertical_svga = 27 [(gogoproto.jsontag)="full_sc_vertical_svga"];
string bullet_head = 28 [(gogoproto.jsontag)="bullet_head"];
string bullet_tail = 29 [(gogoproto.jsontag)="bullet_tail"];
int64 limit_interval = 30 [(gogoproto.jsontag)="limit_interval"];
}
message CountMap{
int64 num = 1 [(gogoproto.jsontag)="num"];
string text = 2 [(gogoproto.jsontag)="text"];
}
}
enum from {
None = 0;
Gold = 1;
Silver = 2;
}
enum userAction {
ActionNone = 0;
StopPush = 1;
}
message NeedTipRechargeReq {
// 来源 1金瓜子 2 银瓜子
from from = 1 [(gogoproto.moretags) = 'form:"from" validate:"required"'];
// 需要的金瓜子 如果From=2 那么直接传0
int64 needGold = 2 [(gogoproto.moretags) = 'form:"needGold"'];
// 平台 android ios
string platform = 3 [(gogoproto.moretags) = 'form:"platform" validate:"required"'];
}
message NeedTipRechargeResp {
// 是否展示
int32 show = 1 [(gogoproto.jsontag) = "show"];
// bp
float bp = 2 [(gogoproto.jsontag) = "bp"];
// bp券
float bpCoupon = 3 [(gogoproto.jsontag) = "bpCoupon"];
// 需要充值的金瓜子
int64 rechargeGold = 4 [(gogoproto.jsontag) = "rechargeGold"];
}
message TipRechargeActionReq {
// 来源 1金瓜子 2 银瓜子
from from = 1 [(gogoproto.moretags) = 'form:"from" validate:"required"'];
//行为 1 停止推送
userAction action = 2 [(gogoproto.moretags) = 'form:"action" validate:"required"'];
}
message TipRechargeActionResp {
}

View File

@@ -0,0 +1,59 @@
// Code generated by protoc-gen-bm v0.1, DO NOT EDIT.
// source: roomNotice.proto
/*
Package v1 is a generated blademaster stub package.
This code was generated with go-common/app/tool/bmgen/protoc-gen-bm v0.1.
It is generated from these files:
roomNotice.proto
*/
package v1
import (
"context"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/binding"
)
// to suppressed 'imported but not used warning'
var _ *bm.Context
var _ context.Context
var _ binding.StructValidator
var PathRoomNoticeBuyGuard = "/live.approom.v1.RoomNotice/buy_guard"
// ====================
// RoomNotice Interface
// ====================
// 房间提示 相关服务
type RoomNoticeBMServer interface {
// 是否弹出大航海购买提示
BuyGuard(ctx context.Context, req *RoomNoticeBuyGuardReq) (resp *RoomNoticeBuyGuardResp, err error)
}
var v1RoomNoticeSvc RoomNoticeBMServer
func roomNoticeBuyGuard(c *bm.Context) {
p := new(RoomNoticeBuyGuardReq)
if err := c.BindWith(p, binding.Default(c.Request.Method, c.Request.Header.Get("Content-Type"))); err != nil {
return
}
resp, err := v1RoomNoticeSvc.BuyGuard(c, p)
c.JSON(resp, err)
}
// RegisterV1RoomNoticeService Register the blademaster route with middleware map
// midMap is the middleware map, the key is defined in proto
func RegisterV1RoomNoticeService(e *bm.Engine, svc RoomNoticeBMServer, midMap map[string]bm.HandlerFunc) {
v1RoomNoticeSvc = svc
e.GET("/xlive/app-room/v1/roomNotice/buy_guard", roomNoticeBuyGuard)
}
// RegisterRoomNoticeBMServer Register the blademaster route
func RegisterRoomNoticeBMServer(e *bm.Engine, server RoomNoticeBMServer) {
v1RoomNoticeSvc = server
e.GET("/live.approom.v1.RoomNotice/buy_guard", roomNoticeBuyGuard)
}

View File

@@ -0,0 +1,788 @@
// Code generated by protoc-gen-gogo. DO NOT EDIT.
// source: roomNotice.proto
package v1
import proto "github.com/gogo/protobuf/proto"
import fmt "fmt"
import math "math"
import _ "github.com/gogo/protobuf/gogoproto"
import io "io"
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package
type RoomNoticeBuyGuardReq struct {
// UID
Uid int64 `protobuf:"varint,1,opt,name=uid,proto3" json:"uid,omitempty" form:"uid" validate:"required"`
// 主播UID
TargetId int64 `protobuf:"varint,2,opt,name=target_id,json=targetId,proto3" json:"target_id,omitempty" form:"target_id" validate:"required"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RoomNoticeBuyGuardReq) Reset() { *m = RoomNoticeBuyGuardReq{} }
func (m *RoomNoticeBuyGuardReq) String() string { return proto.CompactTextString(m) }
func (*RoomNoticeBuyGuardReq) ProtoMessage() {}
func (*RoomNoticeBuyGuardReq) Descriptor() ([]byte, []int) {
return fileDescriptor_roomNotice_bb87aa9995daa825, []int{0}
}
func (m *RoomNoticeBuyGuardReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *RoomNoticeBuyGuardReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_RoomNoticeBuyGuardReq.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalTo(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (dst *RoomNoticeBuyGuardReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_RoomNoticeBuyGuardReq.Merge(dst, src)
}
func (m *RoomNoticeBuyGuardReq) XXX_Size() int {
return m.Size()
}
func (m *RoomNoticeBuyGuardReq) XXX_DiscardUnknown() {
xxx_messageInfo_RoomNoticeBuyGuardReq.DiscardUnknown(m)
}
var xxx_messageInfo_RoomNoticeBuyGuardReq proto.InternalMessageInfo
func (m *RoomNoticeBuyGuardReq) GetUid() int64 {
if m != nil {
return m.Uid
}
return 0
}
func (m *RoomNoticeBuyGuardReq) GetTargetId() int64 {
if m != nil {
return m.TargetId
}
return 0
}
type RoomNoticeBuyGuardResp struct {
// 是否提示 1:弹出提示,0:不弹出
ShouldNotice int64 `protobuf:"varint,1,opt,name=should_notice,json=shouldNotice,proto3" json:"should_notice,omitempty"`
// 状态有效开始时间
Begin int64 `protobuf:"varint,2,opt,name=begin,proto3" json:"begin,omitempty"`
// 状态有效结束时间
End int64 `protobuf:"varint,3,opt,name=end,proto3" json:"end,omitempty"`
// 当前的时间戳
Now int64 `protobuf:"varint,7,opt,name=now,proto3" json:"now,omitempty"`
// 标题
Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"`
// 内容
Content string `protobuf:"bytes,5,opt,name=content,proto3" json:"content,omitempty"`
// 按钮
Button string `protobuf:"bytes,6,opt,name=button,proto3" json:"button,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *RoomNoticeBuyGuardResp) Reset() { *m = RoomNoticeBuyGuardResp{} }
func (m *RoomNoticeBuyGuardResp) String() string { return proto.CompactTextString(m) }
func (*RoomNoticeBuyGuardResp) ProtoMessage() {}
func (*RoomNoticeBuyGuardResp) Descriptor() ([]byte, []int) {
return fileDescriptor_roomNotice_bb87aa9995daa825, []int{1}
}
func (m *RoomNoticeBuyGuardResp) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *RoomNoticeBuyGuardResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_RoomNoticeBuyGuardResp.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalTo(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (dst *RoomNoticeBuyGuardResp) XXX_Merge(src proto.Message) {
xxx_messageInfo_RoomNoticeBuyGuardResp.Merge(dst, src)
}
func (m *RoomNoticeBuyGuardResp) XXX_Size() int {
return m.Size()
}
func (m *RoomNoticeBuyGuardResp) XXX_DiscardUnknown() {
xxx_messageInfo_RoomNoticeBuyGuardResp.DiscardUnknown(m)
}
var xxx_messageInfo_RoomNoticeBuyGuardResp proto.InternalMessageInfo
func (m *RoomNoticeBuyGuardResp) GetShouldNotice() int64 {
if m != nil {
return m.ShouldNotice
}
return 0
}
func (m *RoomNoticeBuyGuardResp) GetBegin() int64 {
if m != nil {
return m.Begin
}
return 0
}
func (m *RoomNoticeBuyGuardResp) GetEnd() int64 {
if m != nil {
return m.End
}
return 0
}
func (m *RoomNoticeBuyGuardResp) GetNow() int64 {
if m != nil {
return m.Now
}
return 0
}
func (m *RoomNoticeBuyGuardResp) GetTitle() string {
if m != nil {
return m.Title
}
return ""
}
func (m *RoomNoticeBuyGuardResp) GetContent() string {
if m != nil {
return m.Content
}
return ""
}
func (m *RoomNoticeBuyGuardResp) GetButton() string {
if m != nil {
return m.Button
}
return ""
}
func init() {
proto.RegisterType((*RoomNoticeBuyGuardReq)(nil), "live.approom.v1.RoomNoticeBuyGuardReq")
proto.RegisterType((*RoomNoticeBuyGuardResp)(nil), "live.approom.v1.RoomNoticeBuyGuardResp")
}
func (m *RoomNoticeBuyGuardReq) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *RoomNoticeBuyGuardReq) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.Uid != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.Uid))
}
if m.TargetId != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.TargetId))
}
if m.XXX_unrecognized != nil {
i += copy(dAtA[i:], m.XXX_unrecognized)
}
return i, nil
}
func (m *RoomNoticeBuyGuardResp) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalTo(dAtA)
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *RoomNoticeBuyGuardResp) MarshalTo(dAtA []byte) (int, error) {
var i int
_ = i
var l int
_ = l
if m.ShouldNotice != 0 {
dAtA[i] = 0x8
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.ShouldNotice))
}
if m.Begin != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.Begin))
}
if m.End != 0 {
dAtA[i] = 0x18
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.End))
}
if len(m.Title) > 0 {
dAtA[i] = 0x22
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(len(m.Title)))
i += copy(dAtA[i:], m.Title)
}
if len(m.Content) > 0 {
dAtA[i] = 0x2a
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(len(m.Content)))
i += copy(dAtA[i:], m.Content)
}
if len(m.Button) > 0 {
dAtA[i] = 0x32
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(len(m.Button)))
i += copy(dAtA[i:], m.Button)
}
if m.Now != 0 {
dAtA[i] = 0x38
i++
i = encodeVarintRoomNotice(dAtA, i, uint64(m.Now))
}
if m.XXX_unrecognized != nil {
i += copy(dAtA[i:], m.XXX_unrecognized)
}
return i, nil
}
func encodeVarintRoomNotice(dAtA []byte, offset int, v uint64) int {
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return offset + 1
}
func (m *RoomNoticeBuyGuardReq) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Uid != 0 {
n += 1 + sovRoomNotice(uint64(m.Uid))
}
if m.TargetId != 0 {
n += 1 + sovRoomNotice(uint64(m.TargetId))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *RoomNoticeBuyGuardResp) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.ShouldNotice != 0 {
n += 1 + sovRoomNotice(uint64(m.ShouldNotice))
}
if m.Begin != 0 {
n += 1 + sovRoomNotice(uint64(m.Begin))
}
if m.End != 0 {
n += 1 + sovRoomNotice(uint64(m.End))
}
l = len(m.Title)
if l > 0 {
n += 1 + l + sovRoomNotice(uint64(l))
}
l = len(m.Content)
if l > 0 {
n += 1 + l + sovRoomNotice(uint64(l))
}
l = len(m.Button)
if l > 0 {
n += 1 + l + sovRoomNotice(uint64(l))
}
if m.Now != 0 {
n += 1 + sovRoomNotice(uint64(m.Now))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovRoomNotice(x uint64) (n int) {
for {
n++
x >>= 7
if x == 0 {
break
}
}
return n
}
func sozRoomNotice(x uint64) (n int) {
return sovRoomNotice(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *RoomNoticeBuyGuardReq) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: RoomNoticeBuyGuardReq: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: RoomNoticeBuyGuardReq: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Uid", wireType)
}
m.Uid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Uid |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field TargetId", wireType)
}
m.TargetId = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.TargetId |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipRoomNotice(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthRoomNotice
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *RoomNoticeBuyGuardResp) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: RoomNoticeBuyGuardResp: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: RoomNoticeBuyGuardResp: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field ShouldNotice", wireType)
}
m.ShouldNotice = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.ShouldNotice |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Begin", wireType)
}
m.Begin = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Begin |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field End", wireType)
}
m.End = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.End |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Title", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthRoomNotice
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Title = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 5:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Content", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthRoomNotice
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Content = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 6:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Button", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthRoomNotice
}
postIndex := iNdEx + intStringLen
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Button = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 7:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Now", wireType)
}
m.Now = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Now |= (int64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipRoomNotice(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthRoomNotice
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipRoomNotice(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
return iNdEx, nil
case 1:
iNdEx += 8
return iNdEx, nil
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
iNdEx += length
if length < 0 {
return 0, ErrInvalidLengthRoomNotice
}
return iNdEx, nil
case 3:
for {
var innerWire uint64
var start int = iNdEx
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowRoomNotice
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
innerWire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
innerWireType := int(innerWire & 0x7)
if innerWireType == 4 {
break
}
next, err := skipRoomNotice(dAtA[start:])
if err != nil {
return 0, err
}
iNdEx = start + next
}
return iNdEx, nil
case 4:
return iNdEx, nil
case 5:
iNdEx += 4
return iNdEx, nil
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
}
panic("unreachable")
}
var (
ErrInvalidLengthRoomNotice = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowRoomNotice = fmt.Errorf("proto: integer overflow")
)
func init() { proto.RegisterFile("roomNotice.proto", fileDescriptor_roomNotice_bb87aa9995daa825) }
var fileDescriptor_roomNotice_bb87aa9995daa825 = []byte{
// 355 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x51, 0xcd, 0x6a, 0x2a, 0x31,
0x14, 0x26, 0xce, 0x55, 0xaf, 0xe1, 0x5e, 0xae, 0x84, 0x5b, 0x09, 0x2e, 0x46, 0x99, 0x96, 0xd6,
0x4d, 0x47, 0x6c, 0xbb, 0x72, 0x29, 0x94, 0xd2, 0x4d, 0x17, 0xb3, 0x2c, 0x05, 0x99, 0x31, 0x71,
0x4c, 0x19, 0x73, 0xc6, 0x98, 0x8c, 0xf8, 0x1e, 0x7d, 0x9f, 0x6e, 0xbb, 0xec, 0x13, 0x48, 0xf1,
0x11, 0x7c, 0x82, 0x32, 0x49, 0x6b, 0xa1, 0xb8, 0xe8, 0xee, 0x7c, 0xe7, 0xfb, 0xe1, 0x1c, 0x3e,
0xdc, 0x54, 0x00, 0xf3, 0x3b, 0xd0, 0x62, 0xc2, 0xc3, 0x5c, 0x81, 0x06, 0xf2, 0x2f, 0x13, 0x05,
0x0f, 0xe3, 0x3c, 0x2f, 0x99, 0xb0, 0x18, 0xb4, 0xcf, 0x53, 0xa1, 0x67, 0x26, 0x09, 0x27, 0x30,
0xef, 0xa7, 0x90, 0x42, 0xdf, 0xea, 0x12, 0x33, 0xb5, 0xc8, 0x02, 0x3b, 0x39, 0x7f, 0xf0, 0x84,
0xf0, 0x51, 0xb4, 0x0f, 0x1d, 0x99, 0xf5, 0x8d, 0x89, 0x15, 0x8b, 0xf8, 0x82, 0x5c, 0x61, 0xcf,
0x08, 0x46, 0x51, 0x17, 0xf5, 0xbc, 0x51, 0xb0, 0xdb, 0x74, 0xfc, 0x29, 0xa8, 0xf9, 0x30, 0x30,
0x82, 0x05, 0xdd, 0x22, 0xce, 0x04, 0x8b, 0x35, 0x1f, 0x06, 0x8a, 0x2f, 0x8c, 0x50, 0x9c, 0x05,
0x51, 0x29, 0x27, 0xd7, 0xb8, 0xa1, 0x63, 0x95, 0x72, 0x3d, 0x16, 0x8c, 0x56, 0xac, 0xb7, 0xb7,
0xdb, 0x74, 0x4e, 0x9c, 0x77, 0x4f, 0x1d, 0x4e, 0xf8, 0xed, 0xf8, 0x5b, 0x16, 0x3c, 0x23, 0xdc,
0x3a, 0x74, 0xd6, 0x32, 0x27, 0xc7, 0xf8, 0xef, 0x72, 0x06, 0x26, 0x63, 0x63, 0x69, 0x49, 0x77,
0x61, 0xf4, 0xc7, 0x2d, 0x9d, 0x81, 0xfc, 0xc7, 0xd5, 0x84, 0xa7, 0x42, 0xba, 0x13, 0x22, 0x07,
0x48, 0x13, 0x7b, 0x5c, 0x32, 0xea, 0xd9, 0x5d, 0x39, 0x96, 0x3a, 0x2d, 0x74, 0xc6, 0xe9, 0xaf,
0x2e, 0xea, 0x35, 0x22, 0x07, 0x08, 0xc5, 0xf5, 0x09, 0x48, 0xcd, 0xa5, 0xa6, 0x55, 0xbb, 0xff,
0x84, 0xa4, 0x85, 0x6b, 0x89, 0xd1, 0x1a, 0x24, 0xad, 0x59, 0xe2, 0x03, 0x95, 0xc9, 0x12, 0x56,
0xb4, 0xee, 0x92, 0x25, 0xac, 0x2e, 0x1e, 0x31, 0xfe, 0x7a, 0x80, 0x3c, 0xe0, 0x46, 0x62, 0xd6,
0xe3, 0xb4, 0xfc, 0x82, 0x9c, 0x86, 0xdf, 0x4a, 0x0b, 0x0f, 0x36, 0xd0, 0x3e, 0xfb, 0x91, 0x6e,
0x99, 0x8f, 0x9a, 0x2f, 0x5b, 0x1f, 0xbd, 0x6e, 0x7d, 0xf4, 0xb6, 0xf5, 0xd1, 0x7d, 0xa5, 0x18,
0x24, 0x35, 0xdb, 0xee, 0xe5, 0x7b, 0x00, 0x00, 0x00, 0xff, 0xff, 0x45, 0x0f, 0x10, 0xb8, 0x31,
0x02, 0x00, 0x00,
}

View File

@@ -0,0 +1,36 @@
syntax = "proto3";
package live.approom.v1;
option go_package = "v1";
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// 房间提示 相关服务
service RoomNotice {
// 是否弹出大航海购买提示
rpc buy_guard (RoomNoticeBuyGuardReq) returns (RoomNoticeBuyGuardResp);
}
message RoomNoticeBuyGuardReq {
// UID
int64 uid = 1 [(gogoproto.moretags) = 'form:"uid" validate:"required"'];
// 主播UID
int64 target_id = 2 [(gogoproto.moretags) = 'form:"target_id" validate:"required"'];
}
message RoomNoticeBuyGuardResp {
// 是否提示 1:弹出提示,0:不弹出
int64 should_notice = 1;
// 状态有效开始时间
int64 begin = 2;
// 状态有效结束时间
int64 end = 3;
// 当前的时间戳
int64 now = 7;
// 标题
string title = 4;
// 内容
string content = 5;
// 按钮
string button = 6;
}

View File

@@ -0,0 +1,40 @@
<!-- package=live.approom.v1 -->
- [/xlive/app-room/v1/roomNotice/buy_guard](#xliveapp-roomv1roomNoticebuy_guard) 是否弹出大航海购买提示
## /xlive/app-room/v1/roomNotice/buy_guard
### 是否弹出大航海购买提示
#### 方法GET
#### 请求参数
|参数名|必选|类型|描述|
|:---|:---|:---|:---|
|uid|是|integer| UID|
|target_id|是|integer| 主播UID|
#### 响应
```javascript
{
"code": 0,
"message": "ok",
"data": {
// 是否提示 1:弹出提示,0:不弹出
"should_notice": 0,
// 状态有效开始时间
"begin": 0,
// 状态有效结束时间
"end": 0,
// 当前的时间戳
"now": 0,
// 标题
"title": "",
// 内容
"content": "",
// 按钮
"button": ""
}
}
```

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_binary",
"go_library",
)
go_binary(
name = "cmd",
embed = [":go_default_library"],
tags = ["automanaged"],
)
go_library(
name = "go_default_library",
srcs = ["main.go"],
data = ["test.toml"],
importpath = "go-common/app/interface/live/app-room/cmd",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/server/http:go_default_library",
"//app/interface/live/app-room/service:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/trace:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,47 @@
package main
import (
"flag"
"os"
"os/signal"
"syscall"
"time"
"go-common/app/interface/live/app-room/conf"
"go-common/app/interface/live/app-room/server/http"
"go-common/app/interface/live/app-room/service"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
"go-common/library/net/trace"
)
func main() {
flag.Parse()
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
log.Info("app-room-interface start")
trace.Init(conf.Conf.Tracer)
defer trace.Close()
ecode.Init(conf.Conf.Ecode)
svc := service.New(conf.Conf)
http.Init(conf.Conf, svc)
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGHUP, syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT)
for {
s := <-c
log.Info("get a signal %s", s.String())
switch s {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
svc.Close()
log.Info("app-room-interface exit")
time.Sleep(time.Second)
return
case syscall.SIGHUP:
default:
return
}
}
}

View File

@@ -0,0 +1,79 @@
[mysql]
addr = "127.0.0.1:3306"
dsn = "test:test@tcp(127.0.0.1:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"
readDSN = ["test:test@tcp(127.0.0.2:3306)/test? timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4","test:test@tcp(127.0.0.3:3306)/test?timeout=200ms&readTimeout=200ms&writeTimeout=200ms&parseTime=true&loc=Local&charset=utf8,utf8mb4"]
active = 20
idle = 10
idleTimeout ="4h"
queryTimeout = "100ms"
execTimeout = "100ms"
tranTimeout = "200ms"
[redis]
name = "app-room-interface"
proto = "tcp"
addr = ""
idle = 10
active = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "1m"
[memcache]
name = "app-room-interface"
proto = "tcp"
addr = ""
active = 50
idle = 10
dialTimeout = "1s"
readTimeout = "1s"
writeTimeout = "1s"
idleTimeout = "10s"
expire = "24h"
[log]
stdout = true
[DMsend]
taskID = "582"
proto = "tcp"
addr = "172.18.33.125:15140"
chanSize = 10240
[DMerr]
taskID = "1409"
proto = "tcp"
addr = "172.18.33.125:15140"
chanSize = 10240
[host]
payCenter = "http://pay.bilibili.co"
liveRpc = "http://rpc.live.bilibili.co"
[httpClient]
[httpClient.payCenter]
key = "xHf74ZfV43cAUsUl"
secret = "d0dbe915091d400bd8ee7f27f0791303"
dial = "1s"
timeout = "1s"
keepAlive = "60s"
timer = 1000
[httpClient.liveRpc]
key = "fb06a25c6338edbc"
secret = "fd10bd177559780c2e4a44f1fa47fa83"
dial = "1s"
timeout = "1s"
keepAlive = "60s"
timer = 1000
[gift]
[gift.rechargeTip]
silverTipDays = [7]
[liverpc]
[liverpc.userext]
Addr = "172.18.33.128:20803"

View File

@@ -0,0 +1,43 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["conf.go"],
importpath = "go-common/app/interface/live/app-room/conf",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//library/cache/memcache:go_default_library",
"//library/cache/redis:go_default_library",
"//library/conf:go_default_library",
"//library/database/sql:go_default_library",
"//library/ecode/tip:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/auth:go_default_library",
"//library/net/http/blademaster/middleware/verify:go_default_library",
"//library/net/rpc/liverpc:go_default_library",
"//library/net/rpc/warden:go_default_library",
"//library/net/trace:go_default_library",
"//vendor/github.com/BurntSushi/toml:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,121 @@
package conf
import (
"errors"
"flag"
"go-common/library/cache/memcache"
"go-common/library/cache/redis"
"go-common/library/conf"
"go-common/library/database/sql"
ecode "go-common/library/ecode/tip"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/auth"
"go-common/library/net/http/blademaster/middleware/verify"
"go-common/library/net/trace"
"go-common/library/net/rpc/warden"
"go-common/library/net/rpc/liverpc"
"github.com/BurntSushi/toml"
)
var (
// ConfPath 配置地址
ConfPath string
client *conf.Client
// Conf config
Conf = &Config{}
)
type host struct {
PayCenter string
LiveRpc string
}
type httpClient struct {
PayCenter *bm.ClientConfig
LiveRpc *bm.ClientConfig
}
type gift struct {
RechargeTip *rechargeTip
}
type rechargeTip struct {
SilverTipDays []int
}
// Config .
type Config struct {
Log *log.Config
BM *bm.ServerConfig
Verify *verify.Config
Tracer *trace.Config
Redis *redis.Config
Memcache *memcache.Config
MySQL *sql.Config
Ecode *ecode.Config
ResourceClient *warden.ClientConfig
Auth *auth.Config
Warden *warden.ClientConfig
DM *warden.ClientConfig
Risk *warden.ClientConfig
VerifyConf *warden.ClientConfig
Host host
HTTPClient *httpClient
Gift *gift
LiveRpc map[string]*liverpc.ClientConfig
}
func init() {
flag.StringVar(&ConfPath, "conf", "", "default config path")
}
// Init init conf
func Init() error {
if ConfPath != "" {
return local()
}
return remote()
}
func local() (err error) {
_, err = toml.DecodeFile(ConfPath, &Conf)
return
}
func remote() (err error) {
if client, err = conf.New(); err != nil {
return
}
if err = load(); err != nil {
return
}
go func() {
for range client.Event() {
log.Info("config reload")
if load() != nil {
log.Error("config reload error (%v)", err)
}
}
}()
return
}
func load() (err error) {
var (
s string
ok bool
tmpConf *Config
)
if s, ok = client.Toml2(); !ok {
return errors.New("load config center error")
}
if _, err = toml.Decode(s, &tmpConf); err != nil {
return errors.New("could not decode config")
}
*Conf = *tmpConf
return
}

View File

@@ -0,0 +1,69 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"dao_test.go",
"livewallet_test.go",
"paycenter_test.go",
"userext_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/model:go_default_library",
"//library/log:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"api.go",
"dao.go",
"livewallet.go",
"paycenter.go",
"userext.go",
],
importpath = "go-common/app/interface/live/app-room/dao",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/model:go_default_library",
"//app/service/live/userext/api/liverpc:go_default_library",
"//app/service/live/userext/api/liverpc/v0:go_default_library",
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//library/cache:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/rpc/liverpc:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/live/app-room/dao/av:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,20 @@
package dao
import (
"go-common/app/interface/live/app-room/conf"
userextApi "go-common/app/service/live/userext/api/liverpc"
"go-common/library/net/rpc/liverpc"
)
// InitAPI init all service APIs
func InitAPI(dao *Dao) {
dao.UserExtAPI = userextApi.New(getConf("userext"))
}
func getConf(appName string) *liverpc.ClientConfig {
c := conf.Conf.LiveRpc
if c != nil {
return c[appName]
}
return nil
}

View File

@@ -0,0 +1,20 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,60 @@
package dao
import (
"context"
"go-common/app/interface/live/app-room/conf"
userextApi "go-common/app/service/live/userext/api/liverpc"
xUserEx "go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/library/cache"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
)
const (
_payCenterWalletURL = "/wallet-int/wallet/getUserWalletInfo"
_liveWalletURL = "/x/internal/livewallet/wallet/getAll"
)
// Dao dao
type Dao struct {
c *conf.Config
payCenterWalletURL string
payCenterClient *bm.Client
liveWalletURL string
liveWalletClient *bm.Client
UserExtAPI *userextApi.Client
giftCache *cache.Cache
XuserexAPI *xUserEx.Client
}
// New init mysql db
func New(c *conf.Config) (dao *Dao) {
dao = &Dao{
c: c,
payCenterWalletURL: c.Host.PayCenter + _payCenterWalletURL,
payCenterClient: bm.NewClient(c.HTTPClient.PayCenter),
liveWalletURL: c.Host.LiveRpc + _liveWalletURL,
liveWalletClient: bm.NewClient(c.HTTPClient.LiveRpc),
giftCache: cache.New(1, 1024),
}
xUserexApi, err := xUserEx.NewClient(c.Warden)
if err != nil {
log.Error("init xuserex error(%v)", err)
}
dao.XuserexAPI = xUserexApi
InitAPI(dao)
return
}
// Close close the resource.
func (d *Dao) Close() {
}
// Ping dao ping
func (d *Dao) Ping(c context.Context) error {
// TODO: if you need use mc,redis, please add
// check
return nil
}

View File

@@ -0,0 +1,21 @@
package dao
import (
"go-common/app/interface/live/app-room/conf"
"go-common/library/log"
"os"
"testing"
)
var testDao *Dao
func TestMain(m *testing.M) {
conf.ConfPath = "../cmd/test.toml"
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
testDao = New(conf.Conf)
os.Exit(m.Run())
}

View File

@@ -0,0 +1,55 @@
package dao
import (
"context"
"crypto/md5"
"encoding/hex"
"github.com/pkg/errors"
"go-common/app/interface/live/app-room/model"
"go-common/library/ecode"
"net/http"
"net/url"
"strconv"
"time"
)
//LiveWallet 获取用户直播钱包数据
func (d *Dao) LiveWallet(c context.Context, mid int64, platform string) (wallet *model.LiveWallet, err error) {
params := url.Values{}
params.Set("uid", strconv.FormatInt(mid, 10))
params.Set("ts", strconv.FormatInt(time.Now().Unix(), 10))
params.Set("appkey", d.c.HTTPClient.LiveRpc.Key)
tmp := params.Encode() + d.c.HTTPClient.LiveRpc.Secret
mh := md5.Sum([]byte(tmp))
sign := hex.EncodeToString(mh[:])
params.Set("sign", sign)
req, _ := http.NewRequest("GET", d.liveWalletURL+"?"+params.Encode(), nil)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("platform", platform)
var wr struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
Gold string `json:"gold"`
Silver string `json:"silver"`
GoldRechargeCnt string `json:"gold_recharge_cnt"`
GoldPayCnt string `json:"gold_pay_cnt"`
SilverPayCnt string `json:"silver_pay_cnt"`
} `json:"data"`
}
if err = d.liveWalletClient.Do(c, req, &wr); err != nil {
return
}
if wr.Code != 0 {
err = errors.Wrap(ecode.Int(wr.Code), d.liveWalletURL+"?"+params.Encode())
return
}
wallet = &model.LiveWallet{}
wallet.Gold, _ = strconv.ParseInt(wr.Data.Gold, 10, 64)
wallet.Silver, _ = strconv.ParseInt(wr.Data.Silver, 10, 64)
wallet.GoldRechargeCnt, _ = strconv.ParseInt(wr.Data.GoldRechargeCnt, 10, 64)
wallet.GoldPayCnt, _ = strconv.ParseInt(wr.Data.GoldPayCnt, 10, 64)
wallet.SilverPayCnt, _ = strconv.ParseInt(wr.Data.SilverPayCnt, 10, 64)
return
}

View File

@@ -0,0 +1,17 @@
package dao
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestDao_LiveWallet(t *testing.T) {
Convey("normal", t, func() {
mid := int64(1)
w, e := testDao.LiveWallet(context.Background(), mid, "android")
So(e, ShouldBeNil)
t.Logf("%+v", w)
})
}

View File

@@ -0,0 +1,130 @@
package dao
import (
"bytes"
"context"
"crypto/md5"
"encoding/hex"
"encoding/json"
"github.com/pkg/errors"
"go-common/app/interface/live/app-room/model"
"go-common/library/ecode"
"go-common/library/log"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"
)
const (
customID = "10005"
)
//PayCenterWallet Wallet get user bcoin doc:http://info.bilibili.co/pages/viewpage.action?pageId=7559096
func (d *Dao) PayCenterWallet(c context.Context, mid int64, platform string) (wallet *model.Wallet, err error) {
var plat int
if platform == "ios" {
plat = 1
} else if platform == "android" {
plat = 2
} else if platform == "pc" {
plat = 3
} else {
err = ecode.ParamInvalid
return
}
platStr := strconv.Itoa(plat)
params := url.Values{}
params.Set("customerId", customID)
params.Set("platformType", platStr)
params.Set("mid", strconv.FormatInt(mid, 10))
params.Set("traceId", strconv.FormatInt(time.Now().Unix(), 10))
params.Set("timestamp", strconv.FormatInt(time.Now().UnixNano()/1e6, 10))
params.Set("signType", "MD5")
params.Set("token", d.c.HTTPClient.PayCenter.Secret)
type pJSON struct {
CustomerID string `json:"customerId"`
PlatformType int `json:"platformType"`
Mid int64 `json:"mid"`
TraceID string `json:"traceId"`
Timestamp string `json:"timestamp"`
SignType string `json:"signType"`
Sign string `json:"sign"`
}
tmp := encode(params)
mh := md5.Sum([]byte(tmp))
sign := hex.EncodeToString(mh[:])
p := &pJSON{
CustomerID: customID,
PlatformType: plat,
Mid: mid,
TraceID: params.Get("traceId"),
Timestamp: params.Get("timestamp"),
SignType: params.Get("signType"),
Sign: sign,
}
bs, _ := json.Marshal(p)
req, _ := http.NewRequest("POST", d.payCenterWalletURL, strings.NewReader(string(bs)))
req.Header.Set("Content-Type", "application/json")
var res struct {
Code int `json:"errno"`
Msg string `json:"msg"`
Data struct {
// DefaultBp float32 `json:"defaultBp"`
CouponBalance float32 `json:"couponBalance"`
AvailableBp float32 `json:"availableBp"`
DefaultBp float32 `json:"defaultBp"`
IosBp float32 `json:"iosBp"`
} `json:"data"`
}
if err = d.payCenterClient.Do(c, req, &res); err != nil {
return
}
if res.Code != 0 {
err = errors.Wrap(ecode.Int(res.Code), d.payCenterWalletURL+"?"+string(bs))
log.Error("account pay url(%s) error(%v) %s", d.payCenterWalletURL+"?"+string(bs), res.Code, res.Msg)
return
}
wallet = &model.Wallet{
Mid: mid,
BcoinBalance: res.Data.AvailableBp,
CouponBalance: res.Data.CouponBalance,
DefaultBp: res.Data.DefaultBp,
IosBp: res.Data.IosBp,
}
return
}
func encode(v url.Values) string {
if v == nil {
return ""
}
var buf bytes.Buffer
keys := make([]string, 0, len(v))
ht := false
for k := range v {
if k == "token" {
ht = true
continue
}
keys = append(keys, k)
}
sort.Strings(keys)
if ht { // 需要把token放在最后 支付中心的规则
keys = append(keys, "token")
}
for _, k := range keys {
vs := v[k]
prefix := k + "="
for _, v := range vs {
if buf.Len() > 0 {
buf.WriteByte('&')
}
buf.WriteString(prefix)
buf.WriteString(v)
}
}
return buf.String()
}

View File

@@ -0,0 +1,17 @@
package dao
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"testing"
)
func TestDao_PayCenterWallet(t *testing.T) {
Convey("normal", t, func() {
mid := int64(1)
w, e := testDao.PayCenterWallet(context.Background(), mid, "android")
So(e, ShouldBeNil)
t.Logf("%+v", w)
})
}

View File

@@ -0,0 +1,105 @@
package dao
import (
"context"
"go-common/app/interface/live/app-room/model"
"go-common/app/service/live/userext/api/liverpc/v0"
"go-common/library/ecode"
"go-common/library/log"
"strconv"
)
//GetUserConf 获取用户配置
func (d *Dao) GetUserConf(c context.Context, mid int64, targetId int64, keys []int64) (values model.ConfValues, err error) {
req := &v0.ConfGetReq{
Uid: mid,
TargetId: targetId,
Type: keys,
}
resp, err := d.UserExtAPI.V0Conf.Get(c, req)
if err != nil {
log.Error("call getUserConf sys error %v", err.Error())
return
}
if resp.Code != 0 {
log.Error("call getUserConf failed %d %v", resp.Code, resp.Msg)
err = ecode.ParamInvalid
return
}
o := resp.Data
values = make(map[int64]string, len(o))
for i, v := range o {
s, e := strconv.ParseInt(i, 10, 64)
if e != nil {
log.Error("call getUserConf string2int64 failed %v", e.Error())
err = e
return
}
values[s] = v
}
return
}
//AsyncSetUserConf 异步设置用户一个配置 "存在"
func (d *Dao) AsyncSetUserConf(c context.Context, mid int64, targetId int64, key int64) (err error) {
value := model.Set
vs := make(map[int64]string, 1)
vs[key] = value
err = d.giftCache.Save(func() {
d.SetMoreUserConf(context.Background(), mid, targetId, vs)
})
if err != nil {
err = d.SetMoreUserConf(c, mid, targetId, vs)
}
return
}
//SetUserConf 设置用户一个配置 "存在"
func (d *Dao) SetUserConf(c context.Context, mid int64, targetId int64, key int64) (err error) {
value := model.Set
vs := make(map[int64]string, 1)
vs[key] = value
err = d.SetMoreUserConf(c, mid, targetId, vs)
return
}
//DelUserConf 删除用户一个配置 "不存在"
func (d *Dao) DelUserConf(c context.Context, mid int64, targetId int64, key int64) (err error) {
value := model.Empty
vs := make(map[int64]string, 1)
vs[key] = value
err = d.SetMoreUserConf(c, mid, targetId, vs)
return
}
//SetMoreUserConf 设置用户多个配置
func (d *Dao) SetMoreUserConf(c context.Context, mid int64, targetId int64, values map[int64]string) (err error) {
varList := make([]*v0.ConfSetReq_Var, len(values))
ic := 0
for k, v := range values {
rv := &v0.ConfSetReq_Var{
Uid: mid,
TargetId: targetId,
Type: k,
Content: v,
}
varList[ic] = rv
ic++
}
req := &v0.ConfSetReq{
VarList: varList,
}
r, err := d.UserExtAPI.V0Conf.Set(c, req)
if err != nil {
log.Error("call setUserConf sys error %v", err.Error())
return
}
if r.Code != 0 {
log.Error("call setUserConf failed %d %v", r.Code, r.Msg)
err = ecode.ParamInvalid
return
}
return
}

View File

@@ -0,0 +1,48 @@
package dao
import (
"context"
. "github.com/smartystreets/goconvey/convey"
"go-common/app/interface/live/app-room/model"
"math/rand"
"testing"
"time"
)
func getTestRandUid() int64 {
var r = rand.New(rand.NewSource(time.Now().UnixNano()))
return r.Int63n(10000000)
}
func TestDao_UserConf(t *testing.T) {
Convey("normal", t, func() {
Convey("conf", func() {
So(7, ShouldEqual, testDao.c.Gift.RechargeTip.SilverTipDays[0])
So(1, ShouldEqual, len(testDao.c.Gift.RechargeTip.SilverTipDays))
t.Logf("%v", testDao.c.Gift.RechargeTip.SilverTipDays)
})
Convey("set and get", func() {
uid := getTestRandUid()
err := testDao.SetUserConf(context.Background(), uid, model.GoldTarget, 1)
So(err, ShouldBeNil)
m, err := testDao.GetUserConf(context.Background(), uid, model.GoldTarget, []int64{1})
So(err, ShouldBeNil)
v, ok := m[1]
t.Logf("v: %v", v)
So(ok, ShouldBeTrue)
So(v, ShouldEqual, "1")
So(m.IsSet(1), ShouldBeTrue)
testDao.DelUserConf(context.Background(), uid, model.GoldTarget, 1)
m, err = testDao.GetUserConf(context.Background(), uid, model.GoldTarget, []int64{1})
So(err, ShouldBeNil)
v, ok = m[1]
t.Logf("v: %v", v)
So(ok, ShouldBeTrue)
So(v, ShouldEqual, "")
So(m.IsSet(1), ShouldBeFalse)
})
})
}

View File

@@ -0,0 +1,33 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"livewallet.go",
"model.go",
"paycenter.go",
"userext.go",
],
importpath = "go-common/app/interface/live/app-room/model",
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,10 @@
package model
//LiveWallet 直播钱包数据
type LiveWallet struct {
Gold int64 `json:"gold"`
Silver int64 `json:"silver"`
GoldRechargeCnt int64 `json:"gold_recharge_cnt"`
GoldPayCnt int64 `json:"gold_pay_cnt"`
SilverPayCnt int64 `json:"silver_pay_cnt"`
}

View File

@@ -0,0 +1,22 @@
package model
//History 存档信息
type History struct {
Text string `json:"text"`
NickName string `json:"nickname"`
UID int64 `json:"uid"`
UnameColor string `json:"uname_color"`
TimeLine string `json:"timeline"`
Isadmin int32 `json:"isadmin"`
Vip int `json:"vip"`
SVip int `json:"svip"`
Medal []interface{} `json:"medal"`
Title []interface{} `json:"title"`
UserLevel []interface{} `json:"user_level"`
Rank int32 `json:"rank"`
Teamid int64 `json:"teamid"`
RND string `json:"rnd"`
UserTitle string `json:"user_title"`
GuardLevel int `json:"guard_level"`
Bubble int64 `json:"bubble"`
}

View File

@@ -0,0 +1,10 @@
package model
// Wallet struct.
type Wallet struct {
Mid int64 `json:"mid"`
BcoinBalance float32 `json:"bcoin_balance"`
CouponBalance float32 `json:"coupon_balance"`
DefaultBp float32 `json:"default_bp"`
IosBp float32 `json:"ios_bp"`
}

View File

@@ -0,0 +1,24 @@
package model
//ConfValues 配置
type ConfValues map[int64]string
const (
// Empty 空
Empty = ""
// Set 存在
Set = "1"
// GoldTarget 金瓜子
GoldTarget = 1010
// SilverTarget 银瓜子
SilverTarget = 1011
)
// IsSet 是否存在
func (vs ConfValues) IsSet(key int64) bool {
v, ok := vs[key]
if !ok {
return false
}
return v == Set
}

View File

@@ -0,0 +1,42 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dm.go",
"http.go",
],
importpath = "go-common/app/interface/live/app-room/server/http",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-room/api/http/v1:go_default_library",
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/service:go_default_library",
"//app/interface/live/app-room/service/v1:go_default_library",
"//app/interface/live/app-room/service/v1/dm:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/http/blademaster/middleware/auth:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,57 @@
package http
import (
apiv1 "go-common/app/interface/live/app-room/api/http/v1"
v1index "go-common/app/interface/live/app-room/service/v1/dm"
"go-common/library/ecode"
bm "go-common/library/net/http/blademaster"
)
func sendMsgSendMsg(ctx *bm.Context) {
p := new(apiv1.SendDMReq)
if err := ctx.Bind(p); err != nil {
return
}
_, err := dmservice.SendMsg(ctx, p)
res := map[string]interface{}{}
if e, ok := err.(*ecode.Status); ok {
res["msg"] = e.Message()
res["message"] = e.Message()
//验证返回
if e.Code() == 1990000 {
res["data"] = map[string]string{
"verify_url": "https://live.bilibili.com/p/html/live-app-captcha/index.html?is_live_half_webview=1&hybrid_half_ui=1,5,290,332,0,0,30,0;2,5,290,332,0,0,30,0;3,5,290,332,0,0,30,0;4,5,290,332,0,0,30,0;5,5,290,332,0,0,30,0;6,5,290,332,0,0,30,0;7,5,290,332,0,0,30,0;8,5,290,332,0,0,30,0",
}
}
ctx.JSONMap(res, err)
return
}
res["msg"] = ""
res["message"] = ""
res["data"] = []string{}
ctx.JSONMap(res, err)
}
func getHistory(ctx *bm.Context) {
p := new(apiv1.HistoryReq)
if err := ctx.Bind(p); err != nil {
return
}
resp, err := dmservice.GetHistory(ctx, p)
res := map[string]interface{}{}
res["msg"] = ""
res["message"] = ""
empty := make(map[string][]string)
empty["room"] = make([]string, 0)
empty["admin"] = make([]string, 0)
if err != nil {
res["data"] = empty
ctx.JSONMap(res, err)
return
}
res["data"] = v1index.HistoryData(resp)
ctx.JSONMap(res, err)
}

View File

@@ -0,0 +1,62 @@
package http
import (
"go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/conf"
"go-common/app/interface/live/app-room/service"
resSrv "go-common/app/interface/live/app-room/service/v1"
v1Svc "go-common/app/interface/live/app-room/service/v1"
dm "go-common/app/interface/live/app-room/service/v1/dm"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/http/blademaster/middleware/auth"
)
var (
srv *service.Service
midAuth *auth.Auth
dmservice *dm.DMService
)
// Init init
func Init(c *conf.Config, svc *service.Service) {
srv = svc
resSrv.Init(c)
initService(c)
engine := bm.DefaultServer(c.BM)
route(engine)
if err := engine.Start(); err != nil {
log.Error("bm Start error(%v)", err)
panic(err)
}
}
func initService(c *conf.Config) {
dmservice = dm.NewDMService(c)
midAuth = auth.New(c.Auth)
}
func route(e *bm.Engine) {
e.Ping(ping)
e.Register(register)
g := e.Group("/xlive/app-room")
{
g.GET("/v1/banner/getBanner", resSrv.GetBanner)
}
midMap := map[string]bm.HandlerFunc{
"guest": midAuth.Guest,
"auth": midAuth.User,
}
v1.RegisterV1GiftService(e, v1Svc.NewGiftService(conf.Conf), midMap)
v1.RegisterV1RoomNoticeService(e, resSrv.NewRoomNoticeService(conf.Conf), midMap)
g.POST("/v1/dM/sendmsg", midAuth.User, sendMsgSendMsg)
g.GET("/v1/dM/gethistory", getHistory)
}
func ping(c *bm.Context) {
}
func register(c *bm.Context) {
c.JSON(map[string]interface{}{}, nil)
}

View File

@@ -0,0 +1,32 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["service.go"],
importpath = "go-common/app/interface/live/app-room/service",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = ["//app/interface/live/app-room/conf:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/live/app-room/service/v1:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,23 @@
package service
import (
"go-common/app/interface/live/app-room/conf"
)
// Service struct
type Service struct {
c *conf.Config
}
// New init
func New(c *conf.Config) (s *Service) {
s = &Service{
c: c,
}
return s
}
// Close -
func (s *Service) Close() error {
return nil
}

View File

@@ -0,0 +1,66 @@
load(
"@io_bazel_rules_go//go:def.bzl",
"go_test",
"go_library",
)
go_test(
name = "go_default_test",
srcs = [
"gift_test.go",
"service_test.go",
],
embed = [":go_default_library"],
tags = ["automanaged"],
deps = [
"//app/interface/live/app-room/api/http/v1:go_default_library",
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/model:go_default_library",
"//library/log:go_default_library",
"//library/net/metadata:go_default_library",
"//vendor/github.com/smartystreets/goconvey/convey:go_default_library",
],
)
go_library(
name = "go_default_library",
srcs = [
"banner.go",
"gift.go",
"roomNotice.go",
],
importpath = "go-common/app/interface/live/app-room/service/v1",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-room/api/http/v1:go_default_library",
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/dao:go_default_library",
"//app/interface/live/app-room/model:go_default_library",
"//app/service/live/gift/api/grpc/v1:go_default_library",
"//app/service/live/resource/api/grpc/v1:go_default_library",
"//app/service/live/xuserex/api/grpc/v1:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/metadata:go_default_library",
"//library/sync/errgroup:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//app/interface/live/app-room/service/v1/dm:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,38 @@
package v1
import (
resAPI "go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/conf"
rspb "go-common/app/service/live/resource/api/grpc/v1"
bm "go-common/library/net/http/blademaster"
)
var _rsCli *rspb.Client
// Init -
func Init(c *conf.Config) {
var err error
if _rsCli, err = rspb.NewClient(c.ResourceClient); err != nil {
panic(err)
}
}
// GetBanner -
func GetBanner(context *bm.Context) {
p := new(rspb.GetBannerReq)
if err := context.Bind(p); err != nil {
return
}
respRPC, err := _rsCli.GetBanner(context, p)
if err != nil {
return
}
resp := make([]resAPI.GetBannerResp, len(respRPC.List))
for index, banner := range respRPC.List {
resp[index].Id = banner.Id
resp[index].Title = banner.Title
resp[index].Img = banner.ImageUrl
resp[index].Link = banner.JumpPath
}
context.JSON(resp, err)
}

View File

@@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"dM.go",
"data.go",
"validate.go",
],
importpath = "go-common/app/interface/live/app-room/service/v1/dm",
tags = ["automanaged"],
visibility = ["//visibility:public"],
deps = [
"//app/interface/live/app-room/api/http/v1:go_default_library",
"//app/interface/live/app-room/conf:go_default_library",
"//app/interface/live/app-room/model:go_default_library",
"//app/service/live/live-dm/api/grpc/v1:go_default_library",
"//app/service/live/live_riskcontrol/api/grpc/v1:go_default_library",
"//app/service/live/xcaptcha/api/grpc/v1:go_default_library",
"//library/ecode:go_default_library",
"//library/log:go_default_library",
"//library/net/http/blademaster:go_default_library",
"//library/net/metadata:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@@ -0,0 +1,162 @@
package v1
import (
v1pb "go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/conf"
dmrpc "go-common/app/service/live/live-dm/api/grpc/v1"
risk "go-common/app/service/live/live_riskcontrol/api/grpc/v1"
xcaptcha "go-common/app/service/live/xcaptcha/api/grpc/v1"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
"strings"
)
// DMService struct
type DMService struct {
conf *conf.Config
}
var (
//弹幕client
dmClient dmrpc.DMClient
//风控client
riskClient risk.IsForbiddenClient
//验证码client
xcaptchaClient xcaptcha.XCaptchaClient
)
//NewDMService init
func NewDMService(c *conf.Config) (s *DMService) {
s = &DMService{
conf: c,
}
var err error
if dmClient, err = dmrpc.NewClient(c.DM); err != nil {
panic(err)
}
if riskClient, err = risk.NewClient(c.Risk); err != nil {
panic(err)
}
if xcaptchaClient, err = xcaptcha.NewClient(c.VerifyConf); err != nil {
panic(err)
}
return s
}
func sendMsg(ctx *bm.Context, req *v1pb.SendDMReq, uid int64) (resp *v1pb.SendMsgResp, err error) {
resp = &v1pb.SendMsgResp{}
ip := metadata.String(ctx, metadata.RemoteIP)
var ck = make([]string, 0, 10)
for _, v := range ctx.Request.Cookies() {
if v.Name != "SESSDATA" {
ck = append(ck, v.Name+"="+v.Value)
}
}
var dmReq = &dmrpc.SendMsgReq{
Uid: uid,
Roomid: req.Roomid,
Msg: req.Msg,
Rnd: req.Rnd,
Ip: ip,
Fontsize: req.Fontsize,
Mode: req.Mode,
Platform: req.Platform,
Msgtype: 0,
Bubble: req.Bubble,
Lancer: &dmrpc.Lancer{
Build: req.Build,
Buvid: ctx.Request.Header.Get("Buvid"),
UserAgent: ctx.Request.Header.Get("User-Agent"),
Refer: ctx.Request.Header.Get("Referer"),
Cookie: strings.Join(ck, ";"),
},
}
gresp, gerr := dmClient.SendMsg(ctx, dmReq)
if gerr != nil {
log.Error("DM GRPC ERR: %v", gerr)
err = ecode.Error(1003218, "系统正在维护中,请稍后尝试")
return nil, err
}
if gresp.IsLimit {
err = ecode.Error(ecode.Code(gresp.Code), gresp.LimitMsg)
return nil, err
}
return resp, nil
}
//验证码风控
func verifyRisk(ctx *bm.Context, uid int64, req *v1pb.SendDMReq) (resp *v1pb.SendMsgResp, err error) {
//验证码
if req.Anti != "" {
result := checkVerify(ctx, req.Anti, uid, req.Roomid)
if !result {
return nil, ecode.Error(1990001, "验证码验证失败")
}
return sendMsg(ctx, req, uid)
}
//风控校验
ifb, ferr := isriskcontrol(ctx, uid, req)
if ifb {
return nil, ferr
}
return sendMsg(ctx, req, uid)
}
// SendMsg implementation
// `method:"POST"`
func (s *DMService) SendMsg(ctx *bm.Context, req *v1pb.SendDMReq) (resp *v1pb.SendMsgResp, err error) {
//获取UID
uid, ok := ctx.Get("mid")
if !ok {
err = ecode.Error(1003218, "未登录")
return nil, err
}
uid64, ok := uid.(int64)
if !ok {
log.Error("DM: mid error")
err = ecode.Error(1003218, "未登录")
return nil, err
}
device, ok := ctx.Get("device")
if !ok {
log.Error("DM: Get device error")
return sendMsg(ctx, req, uid64)
}
devices, ok := device.(*bm.Device)
if !ok {
log.Error("DM: device error")
return sendMsg(ctx, req, uid64)
}
//验证码版本控制
if (devices.RawMobiApp == "android" && devices.Build >= 5360000) ||
(devices.RawMobiApp == "iphone" && devices.Build >= 8290) {
return verifyRisk(ctx, uid64, req)
}
//发送弹幕
return sendMsg(ctx, req, uid64)
}
// GetHistory implementation
// `method:"POST"`
func (s *DMService) GetHistory(ctx *bm.Context, req *v1pb.HistoryReq) (resp *v1pb.HistoryResp, err error) {
resp = &v1pb.HistoryResp{}
var hreq = &dmrpc.HistoryReq{
Roomid: req.Roomid,
}
gresp, err := dmClient.GetHistory(ctx, hreq)
if err != nil {
log.Error("DM GRPC ERR: %v", err)
return
}
resp.Admin = gresp.Admin
resp.Room = gresp.Room
return
}

View File

@@ -0,0 +1,32 @@
package v1
import (
"encoding/json"
v1pb "go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/model"
)
//HistoryData 历史数据处理
func HistoryData(data *v1pb.HistoryResp) map[string][]*model.History {
var result = make(map[string][]*model.History)
result["admin"] = make([]*model.History, 0, 10)
result["room"] = make([]*model.History, 0, 10)
for i := 0; i < len(data.Admin); i++ {
var h = &model.History{}
err := json.Unmarshal([]byte(data.Admin[i]), h)
if err != nil {
break
}
result["admin"] = append(result["admin"], h)
}
for i := 0; i < len(data.Room); i++ {
var h = &model.History{}
err := json.Unmarshal([]byte(data.Room[i]), h)
if err != nil {
break
}
result["room"] = append(result["room"], h)
}
return result
}

View File

@@ -0,0 +1,78 @@
package v1
import (
"encoding/json"
v1pb "go-common/app/interface/live/app-room/api/http/v1"
risk "go-common/app/service/live/live_riskcontrol/api/grpc/v1"
xcaptcha "go-common/app/service/live/xcaptcha/api/grpc/v1"
"go-common/library/ecode"
"go-common/library/log"
bm "go-common/library/net/http/blademaster"
"go-common/library/net/metadata"
)
type rbody struct {
Roomid int64 `json:"roomid"`
Msg string `json:"msg" `
Rnd string `json:"rnd" `
Fontsize int64 `json:"fontsize"`
Mode int64 `json:"mode" `
Color int64 `json:"color"`
Bubble int64 `json:"bubble"`
}
func isriskcontrol(ctx *bm.Context, uid int64, r *v1pb.SendDMReq) (forbid bool, err *ecode.Status) {
req := &risk.GetForbiddenReq{
Uid: uid,
Uri: "/xlive/app-room/v1/dM/sendmsg",
Ip: metadata.String(ctx, metadata.RemoteIP),
Method: "POST",
Header: make(map[string]string),
}
for k := range ctx.Request.Header {
req.Header[k] = ctx.Request.Header.Get(k)
}
rb := &rbody{
Roomid: r.Roomid,
Msg: r.Msg,
Rnd: r.Rnd,
Fontsize: r.Fontsize,
Mode: r.Mode,
Color: r.Color,
Bubble: r.Bubble,
}
jb, _ := json.Marshal(rb)
req.Body = string(jb)
resp, rerr := riskClient.GetForbidden(ctx, req)
if rerr != nil {
log.Error("DM: riskcontrol err:%+v", rerr)
return false, nil
}
switch resp.IsForbidden {
case 0:
return false, nil
case 1:
return true, ecode.Error(400, "访问被拒绝")
case 2:
return true, ecode.Error(1990000, "need a second time verify")
}
return false, nil
}
func checkVerify(ctx *bm.Context, anti string, uid int64, roomid int64) bool {
req := &xcaptcha.XVerifyReq{
Uid: uid,
ClientIp: metadata.String(ctx, metadata.RemoteIP),
XAnti: anti,
RoomId: roomid,
}
if _, err := xcaptchaClient.Verify(ctx, req); err != nil {
return false
}
return true
}

View File

@@ -0,0 +1,318 @@
package v1
import (
"context"
v1pb "go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/conf"
"go-common/app/interface/live/app-room/dao"
"go-common/app/interface/live/app-room/model"
"go-common/app/service/live/gift/api/grpc/v1"
"go-common/library/ecode"
"go-common/library/log"
"go-common/library/net/metadata"
"go-common/library/sync/errgroup"
"strconv"
"time"
)
// GiftService struct
type GiftService struct {
conf *conf.Config
// optionally add other properties here, such as dao
// dao *dao.Dao
client v1.GiftClient
dao *dao.Dao
}
const (
// HasShow 已经展示
HasShow = 302
// StopPush 停止推送
StopPush = 403
)
//NewGiftService init
func NewGiftService(c *conf.Config) (s *GiftService) {
s = &GiftService{
conf: c,
dao: dao.New(c),
}
cli, err := v1.NewClient(conf.Conf.Warden)
if err != nil {
panic(err)
}
s.client = cli
return s
}
// DailyBag implementation
// `method:"GET" midware:"guest"`
func (s *GiftService) DailyBag(ctx context.Context, req *v1pb.DailyBagReq) (resp *v1pb.DailyBagResp, err error) {
resp = &v1pb.DailyBagResp{}
mid, _ := metadata.Value(ctx, metadata.Mid).(int64)
if mid <= 0 {
err = ecode.NoLogin
return
}
//mid = 88895029
ret, err := s.client.DailyBag(ctx, &v1.DailyBagReq{
Uid: mid,
})
if err != nil {
err = ecode.Error(-1, "系统错误")
return
}
resp = &v1pb.DailyBagResp{
BagStatus: ret.BagStatus,
BagExpireStatus: ret.BagExpireStatus,
BagToast: &v1pb.DailyBagResp_BagToast{
ToastStatus: ret.BagToast.ToastStatus,
ToastMessage: ret.BagToast.ToastMessage,
},
BagList: make([]*v1pb.DailyBagResp_BagList, 0),
}
for _, v := range ret.BagList {
s := &v1pb.DailyBagResp_BagList_Source{}
if v.Source != nil {
s = &v1pb.DailyBagResp_BagList_Source{
MedalId: v.Source.MedalId,
MedalName: v.Source.MedalName,
Level: v.Source.Level,
UserLevel: v.Source.UserLevel,
}
}
tmp := &v1pb.DailyBagResp_BagList{
Type: v.Type,
BagName: v.BagName,
Source: s,
}
for _, v2 := range v.GiftList {
tmp.GiftList = append(tmp.GiftList, &v1pb.DailyBagResp_BagList_GiftList{
GiftId: v2.GiftId,
GiftNum: v2.GiftNum,
ExpireAt: v2.ExpireAt,
})
}
resp.BagList = append(resp.BagList, tmp)
}
return
}
// 实际充值的金瓜子数 最小单位是1000
func realRechargeGold(gold int64) (realGold int64) {
if gold%1000 == 0 {
realGold = gold
} else {
realGold = gold + 1000 - gold%1000
}
return
}
func day(t time.Time) int {
s := t.Format("2")
d, _ := strconv.Atoi(s)
return d
}
func yearMonthNum(t time.Time) int64 {
yearMonth, _ := strconv.ParseInt(t.Format("200601"), 10, 64)
return yearMonth
}
// 银瓜子是否提醒
func (s *GiftService) silverNeedTipRecharge(ctx context.Context, mid int64, req *v1pb.NeedTipRechargeReq) (resp *v1pb.NeedTipRechargeResp, err error) {
resp = &v1pb.NeedTipRechargeResp{}
d := day(time.Now())
dHit := false
for _, v := range s.conf.Gift.RechargeTip.SilverTipDays {
if v == d {
dHit = true
break
}
}
if !dHit { // 日期
log.Info("silver not show because day not hit %d mid:%d", d, mid)
return
}
yearMonth := yearMonthNum(time.Now())
defer func() {
if resp.Show == 1 {
s.dao.AsyncSetUserConf(ctx, mid, model.SilverTarget, yearMonth)
}
}()
// 每月只推一次
userConf, err := s.dao.GetUserConf(ctx, mid, model.SilverTarget, []int64{yearMonth, StopPush})
if err != nil {
err = ecode.ServerErr
return
}
if userConf.IsSet(yearMonth) || userConf.IsSet(StopPush) {
log.Info("silver not show because userConf yearMonth:%v stopPush:%v mid:%d", userConf.IsSet(yearMonth), userConf.IsSet(StopPush), mid)
return
}
w, err := s.dao.PayCenterWallet(ctx, mid, req.Platform)
if err != nil {
return
}
if w.CouponBalance < 1 { // bp coupon >= 1
log.Info("silver not show because couponBalance less than 1 %f mid:%d", w.CouponBalance, mid)
return
}
resp.Bp = w.BcoinBalance
resp.BpCoupon = w.CouponBalance
resp.Show = 1
resp.RechargeGold = 0
log.Info("SilverShow mid:%d coupon:%f", mid, w.CouponBalance)
return
}
// 金瓜子是否提醒
func (s *GiftService) goldNeedTipRecharge(ctx context.Context, mid int64, req *v1pb.NeedTipRechargeReq) (resp *v1pb.NeedTipRechargeResp, err error) {
resp = &v1pb.NeedTipRechargeResp{}
defer func() {
if resp.Show == 1 {
s.dao.AsyncSetUserConf(ctx, mid, model.GoldTarget, HasShow) // 设置已经展示过
}
}()
userConf, err := s.dao.GetUserConf(ctx, mid, model.GoldTarget, []int64{HasShow}) // 是否已经展示过
if err != nil {
err = ecode.ServerErr
return
}
if userConf.IsSet(HasShow) {
log.Info("gold not show because has show mid:%d", mid)
return
}
eg, errCtx := errgroup.WithContext(ctx)
var payCenterWallet *model.Wallet
var liveWallet *model.LiveWallet
eg.Go(func() error {
var pErr error
payCenterWallet, pErr = s.dao.PayCenterWallet(errCtx, mid, req.Platform)
return pErr
})
eg.Go(func() error {
var lErr error
liveWallet, lErr = s.dao.LiveWallet(errCtx, mid, req.Platform)
return lErr
})
err = eg.Wait()
if err != nil {
return
}
if liveWallet.GoldPayCnt > 0 { // 历史上没有消费过金瓜子
log.Info("gold not show because gold pay cnt lt 0 %d mid:%d", liveWallet.GoldPayCnt, mid)
return
}
if payCenterWallet.BcoinBalance < 1 { // bp余额大于1
log.Info("gold not show because bcoin lt 1 %f mid:%d", payCenterWallet.BcoinBalance, mid)
return
}
bpGold := int64(payCenterWallet.BcoinBalance * 1000)
realRechargeGold := realRechargeGold(req.NeedGold)
if bpGold < realRechargeGold { // 金瓜子差值
log.Info("gold not show because bcoin lt gold bcoin:%f gold:%d mid:%d", payCenterWallet.BcoinBalance, realRechargeGold, mid)
return
}
resp.Bp = payCenterWallet.BcoinBalance
resp.BpCoupon = payCenterWallet.CouponBalance
resp.Show = 1
resp.RechargeGold = realRechargeGold
log.Info("GoldShow mid:%d bp:%f goldPayCnt:%d needGold:%d", mid, payCenterWallet.BcoinBalance, liveWallet.GoldPayCnt, req.NeedGold)
return
}
// NeedTipRecharge implementation
//
// `midware:"auth"`
func (s *GiftService) NeedTipRecharge(ctx context.Context, req *v1pb.NeedTipRechargeReq) (resp *v1pb.NeedTipRechargeResp, err error) {
mid := metadata.Value(ctx, metadata.Mid).(int64)
if req.From == v1pb.From_Gold {
return s.goldNeedTipRecharge(ctx, mid, req)
} else if req.From == v1pb.From_Silver {
return s.silverNeedTipRecharge(ctx, mid, req)
}
err = ecode.RequestErr
resp = &v1pb.NeedTipRechargeResp{}
return
}
// TipRechargeAction implementation
//
// `midware:"auth"`
// `method:"post"`
func (s *GiftService) TipRechargeAction(ctx context.Context, req *v1pb.TipRechargeActionReq) (resp *v1pb.TipRechargeActionResp, err error) {
resp = &v1pb.TipRechargeActionResp{}
mid := metadata.Value(ctx, metadata.Mid).(int64)
if req.From == v1pb.From_Silver && req.Action == v1pb.UserAction_StopPush {
err = s.dao.SetUserConf(ctx, mid, model.SilverTarget, StopPush)
} else {
err = ecode.RequestErr
}
return
}
// GiftConfig implementation
func (s *GiftService) GiftConfig(ctx context.Context, req *v1pb.GiftConfigReq) (resp *v1pb.GiftConfigResp, err error) {
resp = &v1pb.GiftConfigResp{
List: make([]*v1pb.GiftConfigResp_Config, 0),
}
ret, err := s.client.GiftConfig(ctx, &v1.GiftConfigReq{
Platform: req.Platform,
Build: req.Build,
})
if err != nil {
log.Error("get gift config err,%v", err)
err = ecode.Error(-1, "系统错误")
return
}
for _, v := range ret.Data {
countMap := make([]*v1pb.GiftConfigResp_CountMap, 0)
for _, c := range v.CountMap {
tmp := &v1pb.GiftConfigResp_CountMap{
Num: c.Num,
Text: c.Text,
}
countMap = append(countMap, tmp)
}
d := &v1pb.GiftConfigResp_Config{
Id: v.Id,
Name: v.Name,
Price: v.Price,
Type: v.Type,
CoinType: v.CoinType,
BagGift: v.BagGift,
Effect: v.Effect,
CornerMark: v.CornerMark,
Broadcast: v.Broadcast,
Draw: v.Draw,
StayTime: v.StayTime,
AnimationFrameNum: v.AnimationFrameNum,
Desc: v.Desc,
Rule: v.Rule,
Rights: v.Rights,
PrivilegeRequired: v.PrivilegeRequired,
CountMap: countMap,
ImgBasic: v.ImgBasic,
ImgDynamic: v.ImgDynamic,
FrameAnimation: v.FrameAnimation,
Gif: v.Gif,
Webp: v.Webp,
FullScWeb: v.FullScWeb,
FullScHorizontal: v.FullScHorizontal,
FullScVertical: v.FullScVertical,
FullScHorizontalSvga: v.FullScHorizontalSvga,
FullScVerticalSvga: v.FullScVerticalSvga,
BulletHead: v.BulletHead,
BulletTail: v.BulletTail,
LimitInterval: v.LimitInterval,
}
resp.List = append(resp.List, d)
}
return
}

View File

@@ -0,0 +1,290 @@
package v1
import (
"context"
"go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/model"
"go-common/library/net/metadata"
"strconv"
"testing"
"time"
. "github.com/smartystreets/goconvey/convey"
v1pb "go-common/app/interface/live/app-room/api/http/v1"
"github.com/smartystreets/goconvey/convey"
)
func TestV1DailyBag(t *testing.T) {
convey.Convey("DailyBag", t, func(c convey.C) {
var (
ctx = metadata.NewContext(context.Background(), metadata.MD{
metadata.Mid: int64(88895029),
})
req = &v1pb.DailyBagReq{}
)
c.Convey("When everything gose positive", func(c convey.C) {
resp, err := s.DailyBag(ctx, req)
c.Convey("Then err should be nil.resp should not be nil.", func(c convey.C) {
c.So(err, convey.ShouldBeNil)
c.So(resp, convey.ShouldNotBeNil)
})
})
})
}
func Test_RealGoldRecharge(t *testing.T) {
Convey("normal", t, func() {
So(1000, ShouldEqual, realRechargeGold(1000))
So(2000, ShouldEqual, realRechargeGold(1300))
So(2000, ShouldEqual, realRechargeGold(1700))
So(1000, ShouldEqual, realRechargeGold(1))
So(1000, ShouldEqual, realRechargeGold(233))
So(2000, ShouldEqual, realRechargeGold(1398))
ts, _ := time.Parse("2006-01-02", "2018-12-01")
So(1, ShouldEqual, day(ts))
So(201812, ShouldEqual, yearMonthNum(ts))
ts, _ = time.Parse("2006-01-02", "2018-11-30")
So(30, ShouldEqual, day(ts))
So(201811, ShouldEqual, yearMonthNum(ts))
})
}
func getContextWithMid(mid int64) context.Context {
md := metadata.MD{
metadata.Mid: mid,
}
return metadata.NewContext(context.Background(), md)
}
func TestGiftService_NeedTipRecharge_Silver(t *testing.T) {
Convey("silver", t, func() {
Convey("day empty", func() {
ctx := getContextWithMid(1)
testGiftService.conf.Gift.RechargeTip.SilverTipDays = []int{}
resp, err := testGiftService.NeedTipRecharge(ctx, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
So(resp.Show, ShouldEqual, 0)
})
Convey("day hit and has coupon", func() {
mid := int64(2)
yearMonth, _ := strconv.ParseInt(time.Now().Format("200601"), 10, 64)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, yearMonth)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, StopPush)
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
if w.CouponBalance < 1 {
t.Logf("own not enouth: %v", w.CouponBalance)
return
}
testGiftService.conf.Gift.RechargeTip.SilverTipDays = append(testGiftService.conf.Gift.RechargeTip.SilverTipDays, day(time.Now()))
t.Logf("%v", testGiftService.conf.Gift.RechargeTip.SilverTipDays)
ctx := getContextWithMid(mid)
resp, err := testGiftService.NeedTipRecharge(ctx, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 1)
})
Convey("day hit and has coupon and set stop push", func() {
mid := int64(2)
yearMonth, _ := strconv.ParseInt(time.Now().Format("200601"), 10, 64)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, yearMonth)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, StopPush)
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
if w.CouponBalance < 1 {
t.Logf("own not enouth: %v", w.CouponBalance)
return
}
testGiftService.conf.Gift.RechargeTip.SilverTipDays = append(testGiftService.conf.Gift.RechargeTip.SilverTipDays, day(time.Now()))
t.Logf("%v", testGiftService.conf.Gift.RechargeTip.SilverTipDays)
ctx := getContextWithMid(mid)
_, err := testGiftService.TipRechargeAction(ctx, &v1.TipRechargeActionReq{
From: v1.From_Silver,
Action: v1.UserAction_StopPush,
})
So(err, ShouldBeNil)
resp, err := testGiftService.NeedTipRecharge(ctx, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 0)
})
})
}
func TestGiftService_NeedTipRecharge_Gold(t *testing.T) {
Convey("normal", t, func() {
mid := int64(2)
ctx := getContextWithMid(mid)
testGiftService.dao.DelUserConf(context.Background(), mid, model.GoldTarget, HasShow)
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
bpGold := int64(w.BcoinBalance * 1000)
t.Logf("own : %d", bpGold)
if bpGold < 3*1000 {
t.Logf("own not enouth: %d", bpGold)
return
}
lw, _ := testGiftService.dao.LiveWallet(context.Background(), mid, "android")
if lw.GoldPayCnt > 0 {
t.Logf("goldPayCnt enouth: %d", lw.GoldPayCnt)
return
}
req := &v1.NeedTipRechargeReq{
From: v1.From_Gold,
NeedGold: 666,
Platform: "android",
}
resp, err := testGiftService.NeedTipRecharge(ctx, req)
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 1)
So(resp.Bp, ShouldEqual, w.BcoinBalance)
So(resp.BpCoupon, ShouldEqual, w.CouponBalance)
So(resp.RechargeGold, ShouldEqual, 1000)
})
}
func TestGiftService_NeedTipRecharge(t *testing.T) {
Convey("silver condition", t, func() {
Convey("day empty", func() {
testGiftService.dao.DelUserConf(context.Background(), 1, model.SilverTarget, StopPush)
testGiftService.conf.Gift.RechargeTip.SilverTipDays = []int{}
resp, err := testGiftService.silverNeedTipRecharge(context.Background(), 1, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
So(resp.Show, ShouldEqual, 0)
})
Convey("day hit and has coupon", func() {
mid := int64(3)
yearMonth, _ := strconv.ParseInt(time.Now().Format("200601"), 10, 64)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, yearMonth)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, StopPush)
time.Sleep(time.Millisecond * 10) // 因为是异步设置所以需要一点时间延迟
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
if w.CouponBalance < 1 {
t.Logf("own not enouth: %v", w.CouponBalance)
return
}
testGiftService.conf.Gift.RechargeTip.SilverTipDays = append(testGiftService.conf.Gift.RechargeTip.SilverTipDays, day(time.Now()))
t.Logf("%v", testGiftService.conf.Gift.RechargeTip.SilverTipDays)
resp, err := testGiftService.silverNeedTipRecharge(context.Background(), mid, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 1)
time.Sleep(time.Millisecond * 20) // 因为是异步设置所以需要一点时间延迟
resp, err = testGiftService.silverNeedTipRecharge(context.Background(), mid, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 0)
})
Convey("day hit and has no coupon", func() {
mid := int64(20)
yearMonth, _ := strconv.ParseInt(time.Now().Format("200601"), 10, 64)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, yearMonth)
testGiftService.dao.DelUserConf(context.Background(), mid, model.SilverTarget, StopPush)
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
if w.CouponBalance > 1 {
t.Logf("own enouth: %v", w.CouponBalance)
return
}
testGiftService.conf.Gift.RechargeTip.SilverTipDays = append(testGiftService.conf.Gift.RechargeTip.SilverTipDays, day(time.Now()))
t.Logf("%v", testGiftService.conf.Gift.RechargeTip.SilverTipDays)
resp, err := testGiftService.silverNeedTipRecharge(context.Background(), mid, &v1.NeedTipRechargeReq{
From: v1.From_Silver,
NeedGold: 0,
Platform: "android",
})
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 0)
})
})
Convey("gold condition", t, func() {
mid := int64(3)
testGiftService.dao.DelUserConf(context.Background(), mid, model.GoldTarget, HasShow)
w, _ := testGiftService.dao.PayCenterWallet(context.Background(), mid, "android")
bpGold := int64(w.BcoinBalance * 1000)
t.Logf("own : %d", bpGold)
if bpGold < 3*1000 {
t.Logf("own not enouth: %d", bpGold)
return
}
lw, _ := testGiftService.dao.LiveWallet(context.Background(), mid, "android")
if lw.GoldPayCnt > 0 {
t.Logf("goldPayCnt enouth: %d", lw.GoldPayCnt)
return
}
req := &v1.NeedTipRechargeReq{
From: v1.From_Gold,
NeedGold: 1,
Platform: "android",
}
ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*300)
resp, err := testGiftService.goldNeedTipRecharge(ctx, mid, req)
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 1)
So(resp.Bp, ShouldEqual, w.BcoinBalance)
So(resp.BpCoupon, ShouldEqual, w.CouponBalance)
So(resp.RechargeGold, ShouldEqual, 1000)
cancel()
time.Sleep(time.Millisecond * 20) // 因为是异步设置所以需要一点时间延迟
testGiftService.dao.DelUserConf(context.Background(), mid, model.GoldTarget, HasShow)
req.NeedGold = 1230
ctx, cancel = context.WithTimeout(context.Background(), time.Millisecond*300)
resp, err = testGiftService.goldNeedTipRecharge(ctx, mid, req)
cancel()
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 1)
So(resp.Bp, ShouldEqual, w.BcoinBalance)
So(resp.BpCoupon, ShouldEqual, w.CouponBalance)
So(resp.RechargeGold, ShouldEqual, 2000)
time.Sleep(time.Millisecond * 10) // 因为是异步设置所以需要一点时间延迟
testGiftService.dao.DelUserConf(context.Background(), mid, model.GoldTarget, HasShow)
req.NeedGold = bpGold + 1
ctx, cancel = context.WithTimeout(context.Background(), time.Millisecond*300)
resp, err = testGiftService.goldNeedTipRecharge(ctx, mid, req)
cancel()
So(err, ShouldBeNil)
t.Logf("resp:%+v", resp)
So(resp.Show, ShouldEqual, 0)
})
}

View File

@@ -0,0 +1,63 @@
package v1
import (
"context"
v1pb "go-common/app/interface/live/app-room/api/http/v1"
"go-common/app/interface/live/app-room/conf"
"go-common/app/interface/live/app-room/dao"
"go-common/app/service/live/xuserex/api/grpc/v1"
"go-common/library/ecode"
)
// RoomNoticeService struct
type RoomNoticeService struct {
conf *conf.Config
// optionally add other properties here, such as dao
dao *dao.Dao
}
//NewRoomNoticeService init
func NewRoomNoticeService(c *conf.Config) (s *RoomNoticeService) {
s = &RoomNoticeService{
conf: c,
dao: dao.New(c),
}
return s
}
// 房间提示 相关服务
// BuyGuard implementation
// 是否弹出大航海购买提示
func (s *RoomNoticeService) BuyGuard(ctx context.Context, req *v1pb.RoomNoticeBuyGuardReq) (resp *v1pb.RoomNoticeBuyGuardResp, err error) {
resp = &v1pb.RoomNoticeBuyGuardResp{}
UID := req.GetUid()
targetID := req.GetTargetId()
if UID <= 0 || targetID <= 0 {
err = ecode.ParamInvalid
return
}
ret, err := s.dao.XuserexAPI.BuyGuard(ctx, &v1.RoomNoticeBuyGuardReq{
Uid: UID,
TargetId: targetID,
})
if err != nil {
return
}
if ret == nil {
return
}
resp = &v1pb.RoomNoticeBuyGuardResp{
ShouldNotice: ret.GetShouldNotice(),
Begin: ret.GetBegin(),
End: ret.GetEnd(),
Now: ret.GetNow(),
Title: ret.GetTitle(),
Content: ret.GetContent(),
Button: ret.GetButton(),
}
return
}

View File

@@ -0,0 +1,25 @@
package v1
import (
"go-common/app/interface/live/app-room/conf"
"go-common/library/log"
"os"
"testing"
)
var (
testGiftService *GiftService
s *GiftService
)
func TestMain(m *testing.M) {
conf.ConfPath = "../../cmd/test.toml"
if err := conf.Init(); err != nil {
panic(err)
}
log.Init(conf.Conf.Log)
defer log.Close()
testGiftService = NewGiftService(conf.Conf)
s = testGiftService
os.Exit(m.Run())
}