Java Code Examples for com.alipay.api.AlipayResponse

The following examples show how to use com.alipay.api.AlipayResponse. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: alipay-sdk   Author: wendal   File: JsonConverter.java    License: Apache License 2.0 6 votes vote down vote up
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
                                                                          throws AlipayApiException {
    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;
}
 
Example #2
Source Project: pay   Author: 1991wangliang   File: JsonConverter.java    License: Apache License 2.0 6 votes vote down vote up
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
                                                                          throws AlipayApiException {
    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;
}
 
Example #3
Source Project: MeetingFilm   Author: daydreamdev   File: AbsAlipayService.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
protected AlipayResponse getResponse(AlipayClient client, AlipayRequest request) {
    try {
        AlipayResponse response = client.execute(request);
        if (response != null) {
            log.info(response.getBody());
        }
        return response;

    } catch (AlipayApiException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #4
Source Project: alipay-sdk-java-all   Author: alipay   File: AlipayLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发生特别错误时记录完整错误现场
 */
public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp,
                                 String appSecret) {
    if (!needEnableLogger) {
        return;
    }
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    StringBuilder sb = new StringBuilder();
    sb.append("ErrorScene");
    sb.append("^_^");
    sb.append(tRsp.getErrorCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append(ip);
    sb.append("^_^");
    sb.append(osName);
    sb.append("^_^");
    sb.append(df.format(new Date()));
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append("Body:");
    sb.append((String) rt.get("rsp"));
    blog.error(sb.toString());
}
 
Example #5
Source Project: alipay-sdk-java-all   Author: alipay   File: AlipayLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发生特别错误时记录完整错误现场
 */
public static void logBizSummary(Map<String, Object> rt, AlipayResponse tRsp,
                                 Map<String, Long> costTimeMap) {
    if (!needEnableLogger) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    sb.append("Summary");
    sb.append("^_^");
    sb.append(tRsp.getCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append(costTimeMap.get("prepareCostTime"));
    sb.append("ms,");
    sb.append(costTimeMap.get("requestCostTime"));
    sb.append("ms,");
    sb.append(costTimeMap.get("postCostTime"));
    sb.append("ms");
    blog.info(sb.toString());
}
 
Example #6
Source Project: paascloud-master   Author: paascloud   File: PtcAlipayServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 简单打印应答
 */
private void dumpResponse(AlipayResponse response) {
	if (response != null) {
		log.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
		if (StringUtils.isNotEmpty(response.getSubCode())) {
			log.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
					response.getSubMsg()));
		}
		log.info("body:" + response.getBody());
	}
}
 
Example #7
Source Project: mmall20180107   Author: rancui   File: OrderServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse AlipayResponse) {
    if (AlipayResponse != null) {
        logger.info(String.format("code:%s, msg:%s", AlipayResponse.getCode(), AlipayResponse.getMsg()));
        if (StringUtils.isNotEmpty(AlipayResponse.getSubCode())) {
            logger.info(String.format("subCode:%s, subMsg:%s", AlipayResponse.getSubCode(),
                    AlipayResponse.getSubMsg()));
        }
        logger.info("body:" + AlipayResponse.getBody());
    }
}
 
Example #8
Source Project: mmall20180107   Author: rancui   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse response) {
    if (response != null) {
        log.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
        if (StringUtils.isNotEmpty(response.getSubCode())) {
            log.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
                    response.getSubMsg()));
        }
        log.info("body:" + response.getBody());
    }
}
 
Example #9
Source Project: mmall-kay-Java   Author: LiuKay   File: OrderServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse response) {
    if (response != null) {
        log.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
        if (StringUtils.isNotEmpty(response.getSubCode())) {
            log.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
                    response.getSubMsg()));
        }
        log.info("body:" + response.getBody());
    }
}
 
Example #10
Source Project: mmall-kay-Java   Author: LiuKay   File: Main.java    License: Apache License 2.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse response) {
    if (response != null) {
        log.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
        if (StringUtils.isNotEmpty(response.getSubCode())) {
            log.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
                response.getSubMsg()));
        }
        log.info("body:" + response.getBody());
    }
}
 
Example #11
Source Project: AlipayWechatPlatform   Author: Leibnizhu   File: AlipayOauthSubRouter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解析授权前访问的地址,解析所需的json并编码,最后重定向
 *
 * @param req      HTTP请求对象
 * @param resp     HTTP响应对象
 * @param res      ALipay接口返回的响应
 * @param callback 解析地址后的处理方法
 * @author Leibniz.Hu
 */
private void oauthSuccessProcess(HttpServerRequest req, HttpServerResponse resp, AlipayResponse res, Handler<String> callback) {
    if (res != null) {
        String visitUrl = req.getParam("visitUrl");//getRedirectAddress(request, REMOVE_PARAMS);
        if (visitUrl.length() > 0) {
            visitUrl = TuringBase64Util.decode(visitUrl).replaceAll("[\\s*\t\n\r]", "");
            callback.handle(visitUrl);
            resp.setStatusCode(302).putHeader("Location", visitUrl + (visitUrl.contains("?") ? "&rs=" : "?rs=") + TuringBase64Util.encode(getClearJson(res).toString())).end();
        } else {
            log.error("没有找到授权后回调地址" + req.absoluteURI());
            resp.end("未设置授权后回调地址");
        }
    }
}
 
Example #12
Source Project: AlipayWechatPlatform   Author: Leibnizhu   File: AlipayOauthSubRouter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 解析支付宝授权后的响应对象,获取对应简洁的JSON
 *
 * @param res 支付宝授权后的响应对象
 * @return 简洁的JSON,不包含签名及重复的一些字段
 *
 * @author Leibniz.Hu
 */
private JsonObject getClearJson(AlipayResponse res) {
    JsonObject bodyJson = new JsonObject(res.getBody());
    if (bodyJson.containsKey("alipay_user_info_share_response")) {
        return bodyJson.getJsonObject("alipay_user_info_share_response");
    } else if (bodyJson.containsKey("alipay_system_oauth_token_response")) {
        return bodyJson.getJsonObject("alipay_system_oauth_token_response");
    } else {
        return bodyJson;
    }
}
 
Example #13
Source Project: MMall_JAVA   Author: Liweimin0512   File: OrderServiceImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse response) {
    if (response != null) {
        logger.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
        if (StringUtils.isNotEmpty(response.getSubCode())) {
            logger.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
                    response.getSubMsg()));
        }
        logger.info("body:" + response.getBody());
    }
}
 
Example #14
Source Project: MMall_JAVA   Author: Liweimin0512   File: Main.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void dumpResponse(AlipayResponse response) {
    if (response != null) {
        log.info(String.format("code:%s, msg:%s", response.getCode(), response.getMsg()));
        if (StringUtils.isNotEmpty(response.getSubCode())) {
            log.info(String.format("subCode:%s, subMsg:%s", response.getSubCode(),
                response.getSubMsg()));
        }
        log.info("body:" + response.getBody());
    }
}
 
Example #15
Source Project: alipay-sdk   Author: wendal   File: AlipayLogger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 发生特别错误时记录完整错误现场
 */
public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp,
                                 String appSecret) {
    if (!needEnableLogger) {
        return;
    }
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    StringBuilder sb = new StringBuilder();
    sb.append("ErrorScene");
    sb.append("^_^");
    sb.append(tRsp.getErrorCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append(ip);
    sb.append("^_^");
    sb.append(osName);
    sb.append("^_^");
    sb.append(df.format(new Date()));
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append("Body:");
    sb.append((String) rt.get("rsp"));
    blog.error(sb.toString());
}
 
Example #16
Source Project: wish-pay   Author: fanqinghui   File: AliPayUtil.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
protected static AlipayResponse getResponse(AlipayClient client, AlipayRequest request) {
    try {
        AlipayResponse response = client.execute(request);
        if (response != null) {
            log.info(response.getBody());
        }
        return response;

    } catch (AlipayApiException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example #17
Source Project: pay   Author: 1991wangliang   File: AlipayLogger.java    License: Apache License 2.0 5 votes vote down vote up
public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp,
                                 String appSecret) {
    if (!needEnableLogger) {
        return;
    }
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    StringBuilder sb = new StringBuilder();
    sb.append("ErrorScene");
    sb.append("^_^");
    sb.append(tRsp.getErrorCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append(ip);
    sb.append("^_^");
    sb.append(osName);
    sb.append("^_^");
    sb.append(df.format(new Date()));
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append("Body:");
    sb.append((String) rt.get("rsp"));
    blog.error(sb.toString());
}
 
Example #18
Source Project: MeetingFilm   Author: daydreamdev   File: AbsAlipayTradeService.java    License: Apache License 2.0 4 votes vote down vote up
protected boolean tradeError(AlipayResponse response) {
    return response == null ||
            Constants.ERROR.equals(response.getCode());
}
 
Example #19
Source Project: alipay-sdk-java-all   Author: alipay   File: AlipayLogger.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 发生特别错误时记录完整错误现场
 */
public static void logErrorScene(Map<String, Object> rt, AlipayResponse tRsp,
                                 String appSecret, Map<String, Long> costTimeMap) {
    if (!needEnableLogger) {
        return;
    }
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    df.setTimeZone(TimeZone.getTimeZone(AlipayConstants.DATE_TIMEZONE));
    StringBuilder sb = new StringBuilder();
    sb.append("ErrorScene");
    sb.append("^_^");
    sb.append(tRsp.getErrorCode());
    sb.append("^_^");
    sb.append(tRsp.getSubCode());
    sb.append("^_^");
    sb.append(ip);
    sb.append("^_^");
    sb.append(osName);
    sb.append("^_^");
    sb.append(df.format(new Date()));
    sb.append("^_^");
    sb.append("ProtocalMustParams:");
    appendLog((AlipayHashMap) rt.get("protocalMustParams"), sb);
    sb.append("^_^");
    sb.append("ProtocalOptParams:");
    appendLog((AlipayHashMap) rt.get("protocalOptParams"), sb);
    sb.append("^_^");
    sb.append("ApplicationParams:");
    appendLog((AlipayHashMap) rt.get("textParams"), sb);
    sb.append("^_^");
    sb.append("Body:");
    sb.append((String) rt.get("rsp"));
    sb.append("^_^");
    sb.append(costTimeMap.get("prepareCostTime"));
    sb.append("ms,");
    sb.append(costTimeMap.get("requestCostTime"));
    sb.append("ms,");
    sb.append(costTimeMap.get("postCostTime"));
    sb.append("ms");
    blog.error(sb.toString());
}
 
Example #20
Source Project: AlipayWechatPlatform   Author: Leibnizhu   File: AliPayApi.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
     * 该方法是用户确定授权后的获取用户信息的方法;
     * 方法先解析请求参数,获取auth_code;
     * 获取到auth_code后,用auth_code换取auth_token和openId;
     * 然后,判断用户是否需要获取用户详细信息,如果需要,则用auth_token获取用户详细信息,并返回AlipayUserInfoShareResponse响应对象;
     * 如果不需要,直接返回AlipaySystemOauthTokenResponse响应对象;
     * 其他的意外情况均返回null;
     *
     * @param aliAccountInfo 封装了获取用户详细信息需要用到的数据的对象
     * @param isNeedDetail 是否需要获取详细信息的标识
     * @param request http请求体
     * @return AlipayResponse类型,调用者根据是否需要获取详细信息的标识强转成不同类型的对象,false强转成AlipaySystemOauthTokenResponse,true强转成AlipayUserInfoShareResponse,意外情况返回空
     * Create by quandong
     */
    private static AlipayResponse getUserInfo(AliAccountInfo aliAccountInfo, boolean isNeedDetail, HttpServerRequest request) {
        Map<String, String> params = AliPayApi.getRequestParams(request); // 解析请求参数
        String authCode = params.get("auth_code"); // 获得authCode

        try {
            // 判断是否能获取到authCode
            if(null != authCode && !authCode.equals("")) { // 能获取到authCode
                AlipayClient alipayClient = AliPayCliFactory.getAlipayClient(aliAccountInfo); // 获取支付宝连接
                // 利用authCode获得authToken
                AlipaySystemOauthTokenRequest oauthTokenRequest = new AlipaySystemOauthTokenRequest(); // 创建支付宝系统授权token请求对象
                oauthTokenRequest.setCode(authCode); // 设置auth_code
                oauthTokenRequest.setGrantType("authorization_code"); // 设置同意类型,值为authorization_code时,代表用code换取;值为refresh_token时,代表用refresh_token换取
                AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(oauthTokenRequest); // 向支付宝发送请求并获得响应

                // 判断是否换取到authToken
                if(null != oauthTokenResponse && oauthTokenResponse.isSuccess()) { // 成功获得authToken
                    // 判断是否需要获取用户的详细信息
                    if(isNeedDetail) { // 需要获取用户的详细信息
                        // 利用authToken获取用户信息
                        AlipayUserInfoShareRequest userinfoShareRequest = new AlipayUserInfoShareRequest(); // 创建用户信息共享请求对象
                        AlipayUserInfoShareResponse userinfoShareResponse = alipayClient.execute(userinfoShareRequest, oauthTokenResponse.getAccessToken()); // 向支付宝发送请求并获得响应
//                        AlipayUserUserinfoShareRequest userinfoShareRequest = new AlipayUserUserinfoShareRequest();
//                        AlipayUserUserinfoShareResponse userinfoShareResponse = alipayClient.execute(userinfoShareRequest, oauthTokenResponse.getAccessToken());
//                        LOG.debug("======================用户真实姓名={}======================", userinfoShareResponse.getRealName());

                        // 判断是否能获得用户信息
                        if(null != userinfoShareResponse && userinfoShareResponse.isSuccess()) { // 成功获得用户信息
                            LOG.info("获取用户信息成功:{}", userinfoShareResponse.getBody()); // 获取用户信息成功,打日志
                            return userinfoShareResponse; // 返回响应对象,调用者可以用该对象获取用户的详细信息
                        } else { // 获取用户信息失败
                            LOG.error("获取用户信息失败"); // 获取用户信息失败,打日志
                            return null; // 返回空
                        }
                    } else { // 不需要获取用户的详细信息
                        LOG.info("获取用户openId成功:{}", oauthTokenResponse.getUserId()); // 获取用户openId成功,打日志
                        return oauthTokenResponse; // 返回响应对象,调用者可以用该对象获取用户的openId
                    }
                } else { // 换取不到authToken
                    LOG.error("authCode换取authToken失败"); // authCode换取authToken失败,打日志
                    return null; // 返回空
                }
            } else { // 获取不到authCode
                LOG.error("authCode获取失败"); // authCode获取失败,打日志
                return null; // 返回空
            }
        } catch (AlipayApiException alipayApiException) {
            LOG.error("获取oauthToken或用户信息失败"); // 获取oauthToken或用户信息失败,打日志
            // 自行处理异常
            alipayApiException.printStackTrace();
        }
        return null; // 返回空,正常时不会执行此语句
    }
 
Example #21
Source Project: alipay-sdk   Author: wendal   File: XmlConverter.java    License: Apache License 2.0 4 votes vote down vote up
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
                                                                          throws AlipayApiException {
    Element root = XmlUtils.getRootElementFromString(rsp);
    return getModelFromXML(root, clazz);
}
 
Example #22
Source Project: pay   Author: 1991wangliang   File: Converter.java    License: Apache License 2.0 4 votes vote down vote up
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
throws AlipayApiException;
 
Example #23
Source Project: pay   Author: 1991wangliang   File: XmlConverter.java    License: Apache License 2.0 4 votes vote down vote up
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
                                                                          throws AlipayApiException {
    Element root = XmlUtils.getRootElementFromString(rsp);
    return getModelFromXML(root, clazz);
}
 
Example #24
Source Project: pay   Author: 1991wangliang   File: AlipayUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static <T extends AlipayResponse> T parseResponse(String json, Class<T> clazz)
                                                                                     throws AlipayApiException {
    ObjectJsonParser<T> parser = new ObjectJsonParser<T>(clazz);
    return parser.parse(json);
}
 
Example #25
Source Project: alipay-sdk-java-all   Author: alipay   File: AlipayUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 把JSON字符串解释为对象结构。
 *
 * @param <T>   API响应类型
 * @param json  JSON字符串
 * @param clazz API响应类
 * @return API响应对象
 */
public static <T extends AlipayResponse> T parseResponse(String json, Class<T> clazz)
        throws AlipayApiException {
    ObjectJsonParser<T> parser = new ObjectJsonParser<T>(clazz);
    return parser.parse(json);
}
 
Example #26
Source Project: alipay-sdk   Author: wendal   File: Converter.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 把字符串转换为响应对象。
 * 
 * @param <T> 领域泛型
 * @param rsp 响应字符串
 * @param clazz 领域类型
 * @return 响应对象
 * @throws TopException
 */
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
                                                                          throws AlipayApiException;
 
Example #27
Source Project: alipay-sdk   Author: wendal   File: AlipayUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 把JSON字符串解释为对象结构。
 * 
 * @param <T> API响应类型
 * @param json JSON字符串
 * @param clazz API响应类
 * @return API响应对象
 */
public static <T extends AlipayResponse> T parseResponse(String json, Class<T> clazz)
                                                                                     throws AlipayApiException {
    ObjectJsonParser<T> parser = new ObjectJsonParser<T>(clazz);
    return parser.parse(json);
}