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=<?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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值