...
|
...
|
@@ -31,7 +31,9 @@ import java.util.concurrent.TimeUnit; |
|
|
@Service("UnionServiceImpl_8")
|
|
|
public class BilibiliServiceImpl extends UnionServiceImpl implements IUnionService {
|
|
|
static Logger log = LoggerFactory.getLogger(BilibiliServiceImpl.class);
|
|
|
static final String burl = "https://cm.bilibili.com/conv/api/conversion/ad/v1";
|
|
|
// static final String burl = "https://cm.bilibili.com/conv/api/conversion/ad/v1";
|
|
|
static final String burl = "https://cm.bilibili.com/conv/api/conversion/ad/cb/v1?";
|
|
|
|
|
|
static final String UNION_KEY_BILIBILI_PRE = "UNION:KEY:bilibili:sercret";
|
|
|
|
|
|
@Resource
|
...
|
...
|
@@ -47,10 +49,17 @@ public class BilibiliServiceImpl extends UnionServiceImpl implements IUnionServi |
|
|
if (bo == null) {
|
|
|
bo = new ClickUnionRequestBO();
|
|
|
}
|
|
|
if(StringUtils.isNotEmpty(bo.getClient_type())){
|
|
|
//0 表示 Android, 1表示 iOS, 2 表示 Windows Phone, 3 表示其他
|
|
|
if (bo.getClient_type().equals("0")) {
|
|
|
bo.setInterfaceType("addMonitor_android");
|
|
|
}else if (bo.getClient_type().equals("1")) {
|
|
|
bo.setInterfaceType("addMonitor_ios");
|
|
|
}
|
|
|
}
|
|
|
String mac = request.getParameter("mac");
|
|
|
// String ip = request.getParameter("ip");
|
|
|
String callBackUrl = request.getParameter("callback");
|
|
|
bo.setCallbackurl(callBackUrl);
|
|
|
// String callBackUrl = request.getParameter("callback");
|
|
|
// bo.setCallbackurl(callBackUrl);
|
|
|
log.info("bilibili request is {},mac is {}",bo,mac);
|
|
|
return bo;
|
|
|
}
|
...
|
...
|
@@ -61,22 +70,24 @@ public class BilibiliServiceImpl extends UnionServiceImpl implements IUnionServi |
|
|
List<String> urlParam = new ArrayList<>();
|
|
|
urlParam.add("conv_type=APP_ACTIVE");
|
|
|
urlParam.add("conv_time="+DateUtil.getCurrentTimeSecond());
|
|
|
urlParam.add("ts="+DateUtil.getCurrentTimeSecond());
|
|
|
// urlParam.add("ts="+DateUtil.getCurrentTimeSecond());
|
|
|
// urlParam.add("conv_time=1547800171");
|
|
|
// urlParam.add("ts=1547800171");
|
|
|
//1- 代表 iOS ,2-代表 Android
|
|
|
if(StringUtils.isNotEmpty(clickBO.getIdfa())){
|
|
|
urlParam.add("device_type=1");
|
|
|
}else if(StringUtils.isNotEmpty(clickBO.getImei())){
|
|
|
urlParam.add("device_type=2");
|
|
|
}
|
|
|
// if(StringUtils.isNotEmpty(clickBO.getIdfa())){
|
|
|
// urlParam.add("device_type=1");
|
|
|
// }else if(StringUtils.isNotEmpty(clickBO.getImei())){
|
|
|
// urlParam.add("device_type=2");
|
|
|
// }
|
|
|
urlParam.add("client_ip="+clickBO.getClientIp());
|
|
|
urlParam.add("track_id="+clickBO.getClickId());
|
|
|
urlParam.add("app_key="+clickBO.getAppid());
|
|
|
String secret = getSecret(clickBO.getAppid(),activateUnionRequestBO.getClient_type());
|
|
|
String signUrl = signUrl(urlParam, secret);
|
|
|
log.info("bilibili signUrl={}",signUrl);
|
|
|
return signUrl;
|
|
|
// urlParam.add("app_key="+clickBO.getAppid());
|
|
|
// String secret = getSecret(clickBO.getAppid(),activateUnionRequestBO.getClient_type());
|
|
|
// String signUrl = signUrl(urlParam, secret);
|
|
|
// log.info("bilibili signUrl={}",signUrl);
|
|
|
String callbackUrl = callbackUrl(urlParam);
|
|
|
log.info("bilibili callbackUrl={}",callbackUrl);
|
|
|
return callbackUrl;
|
|
|
}
|
|
|
|
|
|
private String signUrl(List<String> params,String secret){
|
...
|
...
|
@@ -90,6 +101,11 @@ public class BilibiliServiceImpl extends UnionServiceImpl implements IUnionServi |
|
|
urlBuilder.append(paramUrl).append("&sign=").append(sign);
|
|
|
return urlBuilder.toString();
|
|
|
}
|
|
|
private String callbackUrl(List<String> params){
|
|
|
StringBuilder paramsSb = new StringBuilder();
|
|
|
paramsSb.append(Joiner.on("&").join(params));
|
|
|
return burl+paramsSb.toString();
|
|
|
}
|
|
|
|
|
|
private String getSecret(String appKey,String clientType) {
|
|
|
Integer virtualUid = BilibiliVirtualUidEnum.getVirtualUidByAppKey(appKey);
|
...
|
...
|
@@ -119,8 +135,9 @@ public class BilibiliServiceImpl extends UnionServiceImpl implements IUnionServi |
|
|
if (resp.getLeft() == 200) {
|
|
|
JSONObject data = JSONObject.parseObject(resp.getRight());
|
|
|
if (data.getInteger("code") != 0) {
|
|
|
//返回码, 0 为正常, -1 表示签名认证失败, -2 表示 app_key 未分配
|
|
|
activeUnion.warn("BilibiliServiceImpl visitCallbackUrl error,url is {},resp is {}.",url,resp);
|
|
|
//返回码, 0 为正常, -1 表示签名认证失败, -2 表示 app_key 未分配--已废弃版本
|
|
|
// 0-为正常, 400-为缺少必填参,2.5最新版本
|
|
|
activeUnion.warn("BilibiliServiceImpl visitCallbackUrl error,2.5V,url is {},resp is {}.",url,resp);
|
|
|
return Pair.of(303, "BilibiliServiceImpl visitCallbackUrl error");
|
|
|
}
|
|
|
}
|
...
|
...
|
|