渠道系统和 OA系统待办事项接口

OA待办、已办、以及通过ltpatoken查找用户拼音接口


接口采用http  get方式,将需要的参数传入   Content-Type:application/json;charset=UTF-8  (getMethod.addRequestHeader("Content-type","application/json; charset=utf-8");)
1、待办、已办

例子:

待办:
http://10.183.2.31:8080/OAMessageSender/rest/OAMessageService/sendOAMessage?sender=lzjiangyuanmei&recipient=xiaokaixi&systemcode=2004&task=1&href=http://lzqdzc.sc.ctc.com:8080/HRM/fromOA.html&title=test


参数说明:
sender:OA待办发送人
recipient:OA待办接收人
systemcode:为该系统分配的唯一编码
task: 1:发送待办  2:发送已办
href: 接收人收到待办以后,从OA点击待办的链接
title:待办的标题 (对中文使用URLEncoder.encode("代办")处理)
uniid(发送已办时使用):为每一条待办生成的唯一编码,发送已办时需要带上编码


返回数据
status:请求成功或失败 success   fail
errorCode:错误信息
description:描述
uniid(发送待办时会返回):为每一条待办生成的唯一编码,发送已办时需要带上编码




已办:
http://10.183.2.31:8080/OAMessageSender/rest/OAMessageService/sendOAMessage?sender=liujianping&recipient=xiaokaixi&systemcode=2004&task=2&href=http://lzqdzc.sc.ctc.com:8080/HRM/fromOA.html&title=test&uniid=14327126172408315

说明:发送已办使用参数与待办类似,发送已办的数据类容与待办需要一一对应.



2、通过ltpatoken查找用户拼音接口


http://localhost:8080/OAMessageSender/rest/DecodeTokenService/decodeToken?token=xxxxxxxxxxxxxxxxxxxxxxx


参数说明:
token:为通过获取用户本地cookie中ltpatoken字段获取,返回用户的拼音.


返回参数举例
{"status":"true","description":"获取拼音成功","errorCode":null,"data":"xiaokaixi"}


3、查询待办发送状态
http://localhost:8080/OAMessageSender/rest/OAMessageService/queryOAMessage?uniid=14327126172408315&task=1
参数说明
uniid:为每一条待办生成的唯一编码,发送已办时需要带上编码

task:1待办 2已办


在开发过程中,遇到的问题:

1.get post:开始用post方式发送http请求,始终发送不成功,因为接口中声明需要用get方式;

2.编码问题:OA系统显示的都是问号,上网查询,使用如下方式解决:

(1). 对中文参数使用URLEncoder.encode(src);来编码; 
(2) 设置GetMethod编码格式为utf-8:get_method.addRequestHeader("Content-type" , "text/html; charset=utf-8"); 


工具代码如下:

package com.wxweven.utils;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 
 * Module: HttpClientUtil.java Description:
 * 以get/post的方式发送数据到指定的http接口---利用httpclient.jar包---HTTP接口的调用 Company: Author:
 * ptp Date: Feb 22, 2012
 */

public class OAUtils {

	private static final Log logger = LogFactory.getLog(OAUtils.class);

	/**
	 * get方式
	 * 
	 * @param param1
	 * @param param2
	 * @return
	 */
	public static String getHttp(String url, Map<String, String> params) {
		String responseMsg = "";

		// 1.构造HttpClient的实例
		HttpClient httpClient = new HttpClient();

		String sender = params.get("sender");
		String recipient = params.get("recipient");
		String systemcode = params.get("systemcode");
		String task = params.get("task");
		String href = params.get("href");
		String title = params.get("title");
		String uniid = params.get("uniid");

		url += "?sender=" + sender + "&recipient=" + recipient + "&systemcode="
				+ systemcode + "&task=" + task + "&href=" + href + "&title="
				+ title + "&uniid=" + uniid;

		// 2.创建GetMethod的实例
		GetMethod getMethod = new GetMethod(url);

		// 使用系统系统的默认的恢复策略
		getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
				new DefaultHttpMethodRetryHandler());
		getMethod.addRequestHeader("Content-type",
				"application/json; charset=utf-8");
		try {
			// 3.执行getMethod,调用http接口
			httpClient.executeMethod(getMethod);

			// 4.读取内容
			byte[] responseBody = getMethod.getResponseBody();

			// 5.处理返回的内容
			responseMsg = new String(responseBody);
			// logger.info(responseMsg);

		} catch (HttpException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			// 6.释放连接
			getMethod.releaseConnection();
		}
		return responseMsg;
	}

	/**
	 * 测试的main方法
	 * 
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		Map<String, String> params = new HashMap<String, String>();
		params.put("sender", "lzjiangyuanmei");
		params.put("recipient", "xiaokaixi");
		params.put("systemcode", "2004");
		params.put("task", "2");
		params.put("href",
				"http://lzqdzc.sc.ctc.com:8080/qdzc/home_ssoRequest.action");
		params.put("title", URLEncoder.encode("代办任务"));
		params.put("uniid", "14364065302071434");
		String url = "http://10.183.2.31:8080/OAMessageSender/rest/OAMessageService/sendOAMessage";

		String response = OAUtils.getHttp(url, params);

		logger.info("response:" + response);
	}
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值