|
|
package com.yoho.unions.server.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yoho.service.model.union.request.ActivateUnionRequestBO;
|
|
|
import com.yoho.service.model.union.request.ClickUnionRequestBO;
|
|
|
import com.yoho.unions.common.utils.HttpUtils;
|
|
|
import com.yoho.unions.server.service.IUnionService;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
/**
|
|
|
* Created by mingdan.ge on 2019/5/7.
|
|
|
*/
|
|
|
@Service("UnionServiceImpl_9")
|
|
|
public class XiaoMiServiceImpl extends UnionServiceImpl implements IUnionService {
|
|
|
public static Logger log = LoggerFactory.getLogger(XiaoMiServiceImpl.class);
|
|
|
public static final String callBackUrl = "http://trail.e.mi.com/api/callback?";
|
|
|
|
|
|
public ClickUnionRequestBO clickHttpRequestTOBO(HttpServletRequest request, ClickUnionRequestBO bo){
|
|
|
|
|
|
if (request == null) {
|
|
|
return null;
|
|
|
}
|
|
|
if (bo == null) {
|
|
|
bo = new ClickUnionRequestBO();
|
|
|
String imei = request.getParameter("imei");
|
|
|
bo.setImei(imei);
|
|
|
}
|
|
|
bo.setInterfaceType("addMonitor_android");
|
|
|
log.info("Xiaomi request is {}",bo);
|
|
|
return bo;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* http://trail.e.mi.com/api/callback?callback=FgAWng4YJDE0NDI1OTZkLWNiNTEtNDFlYy05YzFmLTBiNzA4OTkzNDU0OBggMDFhNjI2MGVhZGY1ZDVmNzkxNjZkNjkyN2E1ZWQ4ODEVAgA=&imei=01a6260eadf5d5f79166d6927a5ed881&conv_time=1557133077000
|
|
|
* */
|
|
|
@Override
|
|
|
public String getCallbackUrl(ClickUnionRequestBO clickBO, ActivateUnionRequestBO activateUnionRequestBO) {
|
|
|
String url= callBackUrl+"imei="+clickBO.getImei()+"&conv_time="+System.currentTimeMillis()+"&callback="+clickBO.getCallback();
|
|
|
log.info("Xiaomi callBackUrl is {}",url);
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Pair<Integer, String> visitCallbackUrl(String url) {
|
|
|
log.info("Xiaomi visitCallbackUrl url is : {}", url);
|
|
|
|
|
|
try {
|
|
|
Pair<Integer, String> resp= HttpUtils.httpGet(url);
|
|
|
if (resp.getLeft() == 200) {
|
|
|
JSONObject data = JSONObject.parseObject(resp.getRight());
|
|
|
if (data.getInteger("code") != 0) {
|
|
|
//返回码: 0 为正常,-2表示参数格式不合要求,-7表示callback 中解析后的 imei 和 url 中的不一致
|
|
|
activeUnion.warn("XiaoMiServiceImpl visitCallbackUrl error,url is {},resp is {}.",url,resp);
|
|
|
return Pair.of(303, "XiaoMiServiceImpl visitCallbackUrl error");
|
|
|
}
|
|
|
}
|
|
|
return resp;
|
|
|
} catch (Exception e) {
|
|
|
log.error("XiaoMiServiceImpl.visitCallbackUrl exception,url={},e={}" , url, e);
|
|
|
return Pair.of(500, "调用第三方回调url异常");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} |
...
|
...
|
|