HttpKit 基于Jfianl 调用第三方接口案例



public class LanxunService {

    private Logger logger = Logger.getLogger(getClass());

    @Inject
    TblcodemstDao codemstDao;

    public boolean uploadFile(String item_id, String filename) throws Exception {
        // 源地址路径
        Tblcodemst code = codemstDao.selectByTypeNoDel("SOURCE_PLAYBACK_VIDEO_PATH");
        String source_path;
        if (code.content1.endsWith("/")) {
            source_path = code.content1 + filename;
        } else {
            source_path = code.content1 + "/" + filename;
        }
        // 发布播放地址路径
        code = codemstDao.selectByTypeNoDel("PUBLISH_PLAYBACK_VIDEO_PATH");
        String publish_path;
        if (code.content1.endsWith("/")) {
            publish_path = code.content1 + filename;
        } else {
            publish_path = code.content1 + "/" + filename;
        }

        // 蓝汛用户名
        code = codemstDao.selectByTypeAndSortNoDel("LANXUN_INFO", 0);
        String cust_id = code.content2;

        // 蓝汛密码
        code = codemstDao.selectByTypeAndSortNoDel("LANXUN_INFO", 1);
        String passwd = code.content2;

        // 对称加密Key
        code = codemstDao.selectByTypeAndSortNoDel("LANXUN_INFO", 2);
        String deckey = code.content2;

        try {
            cust_id = DesUtil.Decrypt(cust_id, deckey);
            passwd = DesUtil.Decrypt(passwd, deckey);
        } catch (Exception ex) {
            logger.error("蓝讯信息对称解密时发生系统异常", ex);
            throw ex;
        }

        String md5 = CryptUtil.getMD5(item_id + cust_id + "chinacache" + passwd);
        String data = "op=publish&context=" + cust_id
                + "" + md5 + "" + source_path
                + "" + publish_path + "";
        String result = HttpKit.post("http://vbu.fds.ccgslb.net:8080/fds/soap/receiveTask.php", data);
        if (StringUtils.isEmpty(result)) {
            return false;
        }

        result = StringUtils.substringBetween(result, "", "");
        if (!"SUCCESS".equals(result)) {
            return false;
        }
        return true;
    }
}


=============================
回调函数:
public void getXmlResult() {
        String result = "FAILURE";
        Map requestParams = getRequest().getParameterMap();
        logger.debug("蓝讯异步回调:");
        logger.debug(requestParams);
        String xml = requestParams.get("context")[0];
        String status = StringUtils.substringBetween(xml, "", "");
        Short delFlg = 3;
        switch (status) {
        case "download failed":
            delFlg = 3;
            break;
        case "download finish":
            delFlg = 4;
            break;
        case "sync finish":
            delFlg = 0;
            break;
        default:
            break;
        }

        String item_id = StringUtils.substringBetween(xml, "");

        Tblplayback playback = playbackDao.lockById(item_id);
        if (playback != null) {
            playback.delFlg = delFlg;
            playback.updDat = utilDao.getCurTimestamp();
            playback.updUsrId = "LanXun";
            int res = playbackDao.update(playback);
            if (res > 0) {
                result = "SUCCESS";
            }
        }

        renderText("" + result + "");
    }
++++++++++++++++++++++++++++++ 

包含heard :

public static JSONObject messageHistory(String date) {
        StringBuilder data = new StringBuilder();
        data.append("date=").append(date);

        System.out.println("messageHistory data:" + data);
        String json = HttpKit.post(URL_MESSAGE_HISTORY, data.toString(), getHeaders());
        System.out.println("messageHistory result:" + json);
        JSONObject result = JSONObject.parseObject(json);
        if (!"200".equals(result.getString("code"))) {
            throw new ServiceException((int) result.get("code"), "『融云』查询聊天室消息失败");
        }
        return result;
    }

    private static Map getHeaders() {
        String nonce = String.valueOf((int) (Math.random() * 1000000));
        String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
        StringBuilder toSign = new StringBuilder(APP_SECRET).append(nonce).append(timestamp);
        String sign = CryptUtil.SHA1(toSign.toString());

        Map headers = new HashMap();
        headers.put("RC-App-Key", APP_KEY);
        headers.put("RC-Nonce", nonce);
        headers.put("RC-Timestamp", timestamp);
        headers.put("RC-Signature", sign);
        return headers;
    }

你可能感兴趣的:(第三方接口)