一、先编写对应的protobuf文件
syntax = "proto3";
import "google/protobuf/wrappers.proto";
option java_package = "com.qw.ad.controller.rta.proto";
option java_outer_classname = "RtaApi";
enum PlatformType {
PLATFORM_UNKNOWN = 0;
ANDROID = 1;
IOS = 2;
}
enum DeviceType {
DEVICE_UNKNOWN = 0;
PHONE = 1;
TABLET = 2;
}
enum GenderType {
GENDER_UNKNOWN = 0;
MALE = 1;
FEMALE = 2;
}
enum DidType {
IMEI = 0;
IMEI_MD5 = 1;
ANDROID_ID = 2;
ANDROID_ID_MD5 = 3;
IDFA = 4;
IDFA_MD5 = 5;
OAID = 6;
OAID_MD5 = 7;
}
enum EnableStrategy {
DISABLE = 0;
ENABLE_DEFAULT = 1;
ENABLE_Type_2 = 2;
ENABLE_Type_3 = 3;
ENABLE_Type_4 = 4;
ENABLE_Type_5 = 5;
}
message Device {
string imei_md5 = 1;
string android_id_md5 = 2;
string oaid = 3;
string idfa = 4;
}
message Req {
PlatformType platform = 1;
string did = 2; // 安卓为imei,ios为idfa,站内必传字段
int64 slot_id = 3; //广告位ID
int32 age = 4; // 0(<18), 1(18~23), 2(24~30), 3(31~40) 4(41~49), 5(>50)
GenderType gender = 5;
string city = 6;
string model = 7;
repeated string install_list = 8;//安装包名列表,只包含关注包名
DidType did_type = 9; //did_type:imei,imei_md5,idfa,Android id,站内必传字段
int32 experiment = 10; //实验分组 1~n
DeviceType device_type = 11;
string req_id = 12; // 站内必传字段
string source = 13; // 站内必传字段
repeated int64 rta_ids = 14; // 站内必传字段
EnableStrategy enable_strategy = 15; // 联合实验的参数,站内必传字段
int64 tt_did = 16; //联运使用
Device device = 17; //新版设备信息
}
message UserInfo {
enum UserType {
EMPTY = 0;
PRICE_COEF = 1;
DEFAULT = 2;
RTA_BID = 7; //穿山甲使用
}
enum PidType {
PidType_0 = 0;
PidType_1 = 1;
PidType_2 = 2;
PidType_3 = 3;
PidType_4 = 4;
}
enum ActionType {
ACTION_DEFAULT = 0; // 待补充,尽量与站内转化行为一致
IN_APP_ORDER = 20; // app内下单
CUSTOMER_EFFECTIVE = 26; //有效获客
LOAN_CREDIT = 105; // 授信
}
message UserQuality {
UserType user_type = 1; // 对用户的分类,与rta广告的分类相对应
double quality = 2;
};
message ActionQuality {
ActionType action_type = 1; // 对用户转化行为的分类
double quality = 2; // value range [0, 1]
};
message PidList {
PidType pid_type = 1; // 商品列表的重要程度,0代表最重要
repeated int64 pids = 2; // 商品列表
int64 platform_id = 3; // 商品库id
}
bool is_interested = 1; // 是否对这个用户感兴趣,标识是否投放用的字段,站内必传
repeated UserQuality user_scores = 2; // 对用户的一些评判
int64 rta_id = 3; //rit_id,站内必传
repeated PidList pid_lists = 4; // RTA+DPA 相关的数据
repeated ActionQuality action_scores = 5; // 对用户转化行为的一些评判
}
message Rsp {
int32 status_code = 1;// 0代表成功,其他表示错误 ,站内必传字段
repeated int64 exclude_advertiser_id = 2 [packed = true];// 禁止投放的账户ID
repeated int64 exclude_ad_id = 3 [packed = true];// 禁止投放的广告ID
int64 rta_bid = 4;
int32 cache_duration = 5; //缓存时长:小时
string req_id = 6;
repeated UserInfo user_infos = 7; // 站内必传字段
int64 ts = 8; // 时间戳ms
google.protobuf.Int32Value bid_type = 9; // 0表示参竞,1表示设备不参竞,2表示slot_id不参竞,结合缓存时长使用
}
二、根据对应的protobuf文件生成对应的java类
前提是已经安装了protobuf程序,去到对应的protobuf目录下面,打开cmd,输入以下命令就可以生成对应的java类
protoc --java_out=. 文件名称.proto
三、SprignBoot整合Demo
参考:https://gitee.com/jsjack_wang/springboot-demo dev-protobuf分支