Authored by mingdan.ge

b站2.5+亿起发

... ... @@ -79,8 +79,29 @@ public class StringHideUtils {
return sb.toString();
}
/**
* 显示固定长度,中间部分*代替
* @param resourseStr 源字符串
* @param startNum 前端未隐位数
* @param symbolNum 隐位符号显示位数
* @param symbol 隐位符号
* @param endNum 末尾未隐位数
* */
public static String hideMidString(String resourseStr,int startNum,int symbolNum,char symbol,int endNum){
if (null == resourseStr || resourseStr.length() <= startNum+endNum+symbolNum) {
return resourseStr;
}
StringBuilder sb = new StringBuilder(resourseStr.substring(0,startNum));
for (int i=0;i<symbolNum;i++) {
sb.append(symbol);
}
sb.append(resourseStr.substring(resourseStr.length() - endNum));
return sb.toString();
}
public static void main(String[] args) {
String name = "中国人";
String name = "中国人呢5昵称太长十123";
System.out.println(StringHideUtils.hideMidString(name,6,2,'*',4));
String bankCardNo = "6013821200016974875";
System.out.println(StringHideUtils.hideTailString(name,1,1));
System.out.println(StringHideUtils.hideTailString("名字",1,1));
... ...
... ... @@ -5,7 +5,7 @@
<parent>
<groupId>com.yoho</groupId>
<artifactId>parent</artifactId>
<version>1.5.4-SNAPSHOT</version>
<version>1.5.5-SNAPSHOT</version>
</parent>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-unions</artifactId>
... ...
... ... @@ -106,11 +106,14 @@ public class OrderPushConsumer implements YhConsumer {
userOrders.setTrackingCode(unionCookie.getString("wi"));
}
}
// 亿起发的wi对应的其实就是其他人的channel_code——by2019.04.08
//市场配置的新渠道号,从前台带过来的clientId为渠道号,非上面四个值
if (StringUtils.isBlank(userOrders.getTrackingCode())&&unionCookie.containsKey("wi")) {
userOrders.setTrackingCode(unionCookie.getString("wi"));
logger.info("get wi from unionCookie,clientId is {},unionCookie is {}",clientId,unionCookie);
if (userOrders.getUnionData() != null) {
// 亿起发的wi对应的其实就是其他人的channel_code——by2019.04.08
//市场配置的新渠道号,从前台带过来的clientId为渠道号,非上面四个值
JSONObject unionData = JSONObject.parseObject(userOrders.getUnionData());
if (StringUtils.isBlank(userOrders.getTrackingCode()) && unionData.containsKey("wi")) {
userOrders.setTrackingCode(unionData.getString("wi"));
logger.info("get wi from unionCookie,clientId is {},unionCookie is {}", clientId, unionCookie);
}
}
userOrders.setUserId(unionCookie.getString("fl_uid"));
//多麦需要这个字段
... ...
... ... @@ -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");
}
}
... ...
... ... @@ -243,9 +243,17 @@ public class UnionServiceImpl implements IUnionService, IBusinessExportService,
// 有效时间改成5天
DynamicIntProperty activeTime = DynamicPropertyFactory.getInstance().getIntProperty(invalidTime, 5 * 24);
redisValueCache.set(key, JSON.toJSONString(request), 7 * 24, TimeUnit.HOURS);
if (StringUtils.isNotEmpty(request.getAndroidId())) {
//b站2.5版本点击中参数安卓id的md5(32)
key = UNION_KEY + "_" + request.getAndroidId().substring(0,31);
redisValueCache.set(key, JSON.toJSONString(request), 7 * 24, TimeUnit.HOURS);
}
//把IP作为key,也保存到redis
key = UNION_KEY + "_" + request.getClientIp() + "_" + request.getAppkey();
//把IP作为key,也保存到redis
if (StringUtils.isNotEmpty(request.getIp())) {
key = UNION_KEY + "_" + request.getIp() + "_" + request.getAppkey();
}
redisValueCache.set(key, JSON.toJSONString(request), activeTime.get(), TimeUnit.HOURS);
clickUnion.info("clickUnion set redis second success. with key={}, value={}", key, JSON.toJSONString(request));
... ... @@ -386,6 +394,14 @@ public class UnionServiceImpl implements IUnionService, IBusinessExportService,
clickInfo.setUnion_type(request.getChannelId());
value = JSON.toJSONString(clickInfo);
}
if (StringUtils.isEmpty(value) && ClientTypeEnum.ANDROID.getName().equals(request.getClient_type())
&&StringUtils.isBlank(request.getImei())) {
//尝试用安卓udid的md5取31获取下(b站点击数据存储了一份在安卓id的md5曲31位key)
//当安卓获取不到imei时,udid为安卓id的md5取31位
key = UNION_KEY + "_" + request.getUdid().substring(0, 31);
value = redisValueCache.get(key, String.class);
activeUnion.info("activateUnion, get androidId redis with key={}, value={}", key, value);
}
if (StringUtils.isEmpty(value)) {
if(StringUtils.isEmpty(request.getClientIp())){
... ...