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

来源:互联网 发布:淘宝纪录片 编辑:程序博客网 时间:2024/05/16 19:13
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=<?xml version=\"1.0\" encoding=\"UTF-8\"?><ccsc><cust_id>" + cust_id                + "</cust_id><passwd>" + md5 + "</passwd><item_id value=\"" + item_id + "\"><source_path>" + source_path                + "</source_path><publish_path>" + publish_path + "</publish_path></item_id></ccsc>";        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, "<result>", "</result>");        if (!"SUCCESS".equals(result)) {            return false;        }        return true;    }}
=============================回调函数:public void getXmlResult() {        String result = "FAILURE";        Map<String, String[]> requestParams = getRequest().getParameterMap();        logger.debug("蓝讯异步回调:");        logger.debug(requestParams);        String xml = requestParams.get("context")[0];        String status = StringUtils.substringBetween(xml, "<op_status>", "</op_status>");        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, "<item_id value=\"", "\">");        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("<?xml version=\"1.0\" encoding=\"UTF-8\" ?><ccsc><result>" + result + "</result><detail></detail></ccsc>");    }++++++++++++++++++++++++++++++ 
包含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<String, String> 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<String, String> headers = new HashMap<String, String>();        headers.put("RC-App-Key", APP_KEY);        headers.put("RC-Nonce", nonce);        headers.put("RC-Timestamp", timestamp);        headers.put("RC-Signature", sign);        return headers;    }

0 0
原创粉丝点击