本文整理汇总了Java中com.taobao.api.ApiException类的典型用法代码示例。如果您正苦于以下问题:Java ApiException类的具体用法?Java ApiException怎么用?Java ApiException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApiException类属于com.taobao.api包,在下文中一共展示了ApiException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SendPhoneToCustom
import com.taobao.api.ApiException; //导入依赖的package包/类
@RequestMapping(path = "/phone/send", method = RequestMethod.POST)
public PhoneVo SendPhoneToCustom(@RequestBody PhoneVo vo) throws ApiException {
System.err.println(vo.getPhone());
vo.setCode(RandomStringUtils.randomNumeric(6));
// 24619654
String url = "https://eco.taobao.com/router/rest";
String appkey = "";
String secret = "a68a283919212762db0f58132e1c76bd";
TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
req.setExtend("123456");
req.setSmsType("normal");
req.setSmsFreeSignName("数盟");
req.setSmsParamString("{\"code\":\"" + vo.getCode() + "\"}");
req.setRecNum(vo.getPhone());
req.setSmsTemplateCode("SMS_94715134");
AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
System.out.println(rsp.getBody());
return vo;
}
示例2: sendText
import com.taobao.api.ApiException; //导入依赖的package包/类
public static String sendText(String content) {
try {
Map<String, String> msgcontent = new HashMap<>();
msgcontent.put("content", content);
DingTalkClient client = new DefaultDingTalkClient("https://eco.taobao.com/router/rest");
CorpMessageCorpconversationAsyncsendRequest req = new CorpMessageCorpconversationAsyncsendRequest();
req.setMsgtype("text");
req.setAgentId(Utils.parseLong(agentid, null));
req.setToAllUser(true);
req.setMsgcontent(JSON.toJSONString(msgcontent));
CorpMessageCorpconversationAsyncsendResponse rsp = client.execute(req, getToken());
System.out.println(rsp.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
return null;
}
示例3: toResponse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public <T extends TaobaoResponse> T toResponse(String rsp, Class<T> clazz) throws ApiException {
JSONReader reader = new JSONValidatingReader(new ExceptionErrorListener());
Object rootObj = reader.read(rsp);
if (rootObj instanceof Map<?, ?>) {
Map<?, ?> rootJson = (Map<?, ?>) rootObj;
Collection<?> values = rootJson.values();
for (Object rspObj : values) {
if (rspObj instanceof Map<?, ?>) {
Map<?, ?> rspJson = (Map<?, ?>) rspObj;
return fromJson(rspJson, clazz);
}
}
}
return null;
}
示例4: parse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public TdcResponse parse(String rsp) throws ApiException {
JXTdcResponse jxRsp = new JXTdcResponse();
Map<String, Object> resultMap = new HashMap<String, Object>();
XmlReader xmlreader = new XmlReader();
try {
StringReader sr = new StringReader(rsp);
InputSource is = new InputSource(sr);
Document document = XmlUtils.getDocument(is, null);
Element root = document.getDocumentElement();
Map<String, Object> parserMap = xmlreader.dom2Map(root);
if (root.getNodeName().equals(Constants.ERROR_RESPONSE)) {
jxRsp.setErrorCode((String) parserMap.get(Constants.ERROR_CODE));
jxRsp.setMsg((String) parserMap.get(Constants.ERROR_MSG));
jxRsp.setSubCode((String) parserMap.get(Constants.ERROR_SUB_CODE));
jxRsp.setSubMsg((String) parserMap.get(Constants.ERROR_SUB_MSG));
} else {
resultMap.put(root.getNodeName(), parserMap);
}
} catch (Exception e) {
throw new ApiException(e);
}
jxRsp.setResultMap(resultMap);
jxRsp.setBody(rsp);
return jxRsp;
}
示例5: parse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public TdcResponse parse(String rsp) throws ApiException {
TdcResponse rsponse = new TdcResponse();
JSONReader reader = new JSONValidatingReader(new ExceptionErrorListener());
Object rootObj = reader.read(rsp);
if (rootObj instanceof Map<?, ?>) {
Map<?, ?> rootJson = (Map<?, ?>) rootObj;
if (rootJson.containsKey(Constants.ERROR_RESPONSE)) {
Map<?, ?> result = (Map<?, ?>) rootJson.get(Constants.ERROR_RESPONSE);
rsponse.setErrorCode((String) result.get(Constants.ERROR_CODE));
rsponse.setMsg((String) result.get(Constants.ERROR_MSG));
rsponse.setSubCode((String) result.get(Constants.ERROR_SUB_CODE));
rsponse.setSubMsg((String) result.get(Constants.ERROR_SUB_MSG));
}
}
rsponse.setBody(rsp);
return rsponse;
}
示例6: parse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public TdcResponse parse(String rsp) throws ApiException {
JXTdcResponse jxRsp = new JXTdcResponse();
JSONReader reader = new JSONValidatingReader(new ExceptionErrorListener());
Object rootObj = reader.read(rsp);
if (rootObj instanceof Map<?, ?>) {
Map<?, ?> rootJson = (Map<?, ?>) rootObj;
if (rootJson.containsKey(Constants.ERROR_RESPONSE)) {
Map<?, ?> result = (Map<?, ?>) rootJson.get(Constants.ERROR_RESPONSE);
jxRsp.setErrorCode((String) result.get(Constants.ERROR_CODE));
jxRsp.setMsg((String) result.get(Constants.ERROR_MSG));
jxRsp.setSubCode((String) result.get(Constants.ERROR_SUB_CODE));
jxRsp.setSubMsg((String) result.get(Constants.ERROR_SUB_MSG));
} else {
jxRsp.setResultMap(rootJson);
}
}
jxRsp.setBody(rsp);
return jxRsp;
}
示例7: childNodeToString
import com.taobao.api.ApiException; //导入依赖的package包/类
/**
* Converts the Node/Element instance to XML payload.
*
* @param node the node/element instance to convert
* @return the XML payload representing the node/element
* @throws ApiException problem converting XML to string
*/
public static String childNodeToString(Node node) throws ApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
props.setProperty(OutputKeys.ENCODING, DEFAULT_CHARSET);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = escapeXml(writer.toString());
} catch (TransformerException e) {
throw new ApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例8: nodeToString
import com.taobao.api.ApiException; //导入依赖的package包/类
/**
* Converts the Node/Document/Element instance to XML payload.
*
* @param node the node/document/element instance to convert
* @return the XML payload representing the node/document/element
* @throws ApiException problem converting XML to string
*/
public static String nodeToString(Node node) throws ApiException {
String payload = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.ENCODING, DEFAULT_CHARSET);
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
tf.setOutputProperties(props);
StringWriter writer = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(writer));
payload = escapeXml(writer.toString());
} catch (TransformerException e) {
throw new ApiException("XML_TRANSFORM_ERROR", e);
}
return payload;
}
示例9: saveToXml
import com.taobao.api.ApiException; //导入依赖的package包/类
/**
* Saves the node/document/element as XML file.
*
* @param doc the XML node/document/element to save
* @param file the XML file to save
* @param charset the string encoding charset
* @throws ApiException problem persisting XML file
*/
public static void saveToXml(Node doc, File file, String charset) throws ApiException {
Writer writer = null;
try {
Transformer tf = TransformerFactory.newInstance().newTransformer();
Properties props = tf.getOutputProperties();
props.setProperty(OutputKeys.METHOD, XMLConstants.XML_NS_PREFIX);
props.setProperty(OutputKeys.INDENT, LOGIC_YES);
tf.setOutputProperties(props);
DOMSource dom = new DOMSource(doc);
writer = new OutputStreamWriter(getOutputStream(file), charset);
Result result = new StreamResult(writer);
tf.transform(dom, result);
} catch (Exception e) {
throw new ApiException("XML_WRITE_FILE_ERROR", e);
} finally {
closeStream(writer);
}
}
示例10: xmlToHtml
import com.taobao.api.ApiException; //导入依赖的package包/类
/**
* Transforms the XML content to XHTML/HTML format string with the XSL.
*
* @param payload the XML payload to convert
* @param xsltFile the XML stylesheet file
* @return the transformed XHTML/HTML format string
* @throws ApiException problem converting XML to HTML
*/
public static String xmlToHtml(String payload, File xsltFile) throws ApiException {
String result = null;
try {
Source template = new StreamSource(xsltFile);
Transformer transformer = TransformerFactory.newInstance().newTransformer(template);
Properties props = transformer.getOutputProperties();
props.setProperty(OutputKeys.OMIT_XML_DECLARATION, LOGIC_YES);
transformer.setOutputProperties(props);
StreamSource source = new StreamSource(new StringReader(payload));
StreamResult sr = new StreamResult(new StringWriter());
transformer.transform(source, sr);
result = sr.getWriter().toString();
} catch (TransformerException e) {
throw new ApiException("XML_TRANSFORM_ERROR", e);
}
return result;
}
示例11: addProtocalMustParams
import com.taobao.api.ApiException; //导入依赖的package包/类
private <T extends AliyunResponse> void addProtocalMustParams(AliyunRequest<T> request,
TaobaoHashMap protocalMustParams) throws Exception {
String[] strArray = request.getApiMethodName().split("\\.");
if (strArray.length < 5) {
throw new ApiException("Wrong api name.");
}
String action = strArray[3];
protocalMustParams.put(AliyunConstants.ACTION, action);
String version = strArray[4];
protocalMustParams.put(AliyunConstants.VERSION, version);
protocalMustParams.put(AliyunConstants.ACCESS_KEY_ID, accessKeyId);
protocalMustParams.put(AliyunConstants.FORMAT, format);
Long timestamp = request.getTimestamp();// 允许用户设置时间戳
if (timestamp == null) {
timestamp = System.currentTimeMillis();
}
protocalMustParams.put(AliyunConstants.TIME_STAMP, formatIso8601Date(new Date(timestamp)));
protocalMustParams.put(AliyunConstants.SIGNATURE_METHOD, signatureMethod);
protocalMustParams.put(AliyunConstants.SIGNATURE_VERSION, signatureVersion);
protocalMustParams.put(AliyunConstants.SIGNATURE_NONCE, UUID.randomUUID().toString()); // 可以使用UUID作为SignatureNonce
}
示例12: getSellerInfo
import com.taobao.api.ApiException; //导入依赖的package包/类
public void getSellerInfo() {
// 实例化TopClient类
TaobaoClient client = new DefaultTaobaoClient(serverUrl, appkey, appSecret);
// 实例化具体API对应的Request类
UserSellerGetRequest req = new UserSellerGetRequest();
req.setFields("nick, user_id, type");
// req.setNick("sandbox_c_1");
// 执行API请求并打印结果
UserSellerGetResponse response;
try {
response = client.execute(req, sessionkey);
System.out.println("result: " + response.getBody());
} catch (ApiException e) {
e.printStackTrace();
}
}
示例13: sentValidCodeSms
import com.taobao.api.ApiException; //导入依赖的package包/类
/**
* 发送验证码
* @param mobileNum 手机号
* @param validCode 验证码内容
* @param signName 短信签名
* @param templateNum 模板号
* @param opeateName 操作名称(日志用)
* @return 发送是否成功
*/
private boolean sentValidCodeSms(String mobileNum, String validCode,String signName,String templateNum,String opeateName){
AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
req.setSmsType("normal");
req.setSmsFreeSignName(signName);
req.setSmsParamString("{\"code\":\"" + validCode + "\",\"product\":\" "+SMS_PRODUCT_NAME+" \"}");
req.setRecNum(mobileNum);
req.setSmsTemplateCode(templateNum);
AlibabaAliqinFcSmsNumSendResponse rsp ;
try {
rsp = getSmsClient().execute(req);
if (rsp==null){
log.error("验证码-"+opeateName+"-失败:返回结果为null,mobile:{} validCode{}",mobileNum,validCode);
return false;
}else{
if(!rsp.isSuccess()){
log.error("验证码-"+opeateName+"-失败:返回结果失败:,mobile:{} code:{} response:{}",mobileNum,validCode, ReflectionToStringBuilder.toString(rsp, ToStringStyle.SIMPLE_STYLE));
return false;
}
}
} catch (ApiException e) {
log.error("验证码-"+opeateName+"-失败:短信发送异常,mobile:"+mobileNum+" code:"+validCode, e);
}
log.info("验证码-"+opeateName+":发送成功,mobile:{} validCode:{}",mobileNum,validCode);
return true;
}
示例14: parse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public T parse(String rsp) throws ApiException {
Converter converter;
if (this.simplify) {
converter = new SimplifyJsonConverter();
} else {
converter = new JsonConverter();
}
return converter.toResponse(rsp, clazz);
}
示例15: toResponse
import com.taobao.api.ApiException; //导入依赖的package包/类
@Override
public <T extends TaobaoResponse> T toResponse(String rsp, Class<T> clazz) throws ApiException {
JSONReader reader = new JSONValidatingReader(new ExceptionErrorListener());
Object rootObj = reader.read(rsp);
if (rootObj instanceof Map<?, ?>) {
Map<?, ?> rootJson = (Map<?, ?>) rootObj;
Object errorJson = rootJson.get(Constants.ERROR_RESPONSE);
if (errorJson instanceof Map<?, ?>) {
return fromJson((Map<?, ?>) errorJson, clazz);
} else {
return fromJson(rootJson, clazz);
}
}
return null;
}