taobao open api 开发笔记。

我用springmvc,所以这里的代码基于springmvc的。今天调用了一下alisoft.validateUser这个最基本的接口,调试成功返回状态码code:9999。平台编码可以在 http://isp.alisoft.com/apidoc/api/apiIndex.html 平台错误代码一览 找到。

这里需要调用到阿里软件的jar包。地址在这里
http://wiki.isv.alisoft.com/index.php/%E8%B5%84%E6%BA%90

API文档可以在这里找到 http://isp.alisoft.com/apidoc/api/apiIndex.html



import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.alisoft.sip.sdk.isv.Constants;
import com.alisoft.sip.sdk.isv.RestConnector;
import com.alisoft.sip.sdk.isv.SignatureUtil;
import com.alisoft.sip.sdk.isv.SipResult;

@Controller
@RequestMapping("/login.do")
public class LoginController {
	@RequestMapping
	public ModelAndView execute(HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, String> map = new HashMap<String, String>();// 输入各个参数
		String sip_timestamp = Constants.SIP_TIMESTAMP_FORMATER
				.format(new Date());
		map.put("token", request.getParameter("token"));
		map.put("appId", request.getParameter("app_id"));
		map.put("userId", request.getParameter("user_id"));
		map.put("appInstanceId", request.getParameter("app_instance_id"));
		map.put("sip_sessionid", request.getSession(true).getId());
		map.put("sip_appkey", APPConstant.APP_ID);
		map.put("sip_appsecret", APPConstant.CERT_CODE);
		map.put("sip_apiname", APPConstant.ALISOFT_VALIDATE_USER);
		map.put("sip_timestamp", sip_timestamp);
		String sign = SignatureUtil.Signature(map, map.get("sip_appsecret"));
		map.put("sip_sign", sign);
		Properties prop = new Properties();
		prop.setProperty(Constants.PARAMETER_APPKEY, APPConstant.APP_ID);
		prop.setProperty(Constants.PARAMETER_APPSECRET, APPConstant.CERT_CODE);
		RestConnector.setConfig(prop);
		RestConnector conn = new RestConnector();
		try {
			SipResult result = conn.invoke(APPConstant.ALISOFT_VALIDATE_USER,
					APPConstant.API_URL, map, Constants.HTTP_METHOD_POST);
			String code = result.getStatus().getCode();
			return new ModelAndView("code", "code", code);
		} catch (Exception e) {
			return new ModelAndView("error", "error", e.getMessage());
		}

	}

}


通过了。不过有2个问题。RestConnector.setConfig(prop);这个在api文档里面没看到说明。还是从阿里的论坛里找到的一段代码。

你可能感兴趣的:(html,Web,PHP,servlet)