本文整理汇总了Java中com.alipay.api.AlipayResponse类的典型用法代码示例。如果您正苦于以下问题:Java AlipayResponse类的具体用法?Java AlipayResponse怎么用?Java AlipayResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AlipayResponse类属于com.alipay.api包,在下文中一共展示了AlipayResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
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;
}
示例2: dumpResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
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());
}
}
示例3: dumpResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
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());
}
}
示例4: oauthSuccessProcess
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 解析授权前访问的地址,解析所需的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("未设置授权后回调地址");
}
}
}
示例5: getClearJson
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 解析支付宝授权后的响应对象,获取对应简洁的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;
}
}
示例6: logErrorScene
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 发生特别错误时记录完整错误现场
*/
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());
}
示例7: getResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
@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;
}
}
示例8: logErrorScene
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
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());
}
示例9: prepay
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
private String prepay(AlipayModel alipay, String returnUrl, AlipayRequest<? extends AlipayResponse> request) {
request.setNotifyUrl(root + "/alipay/notice");
if (!validator.isEmpty(returnUrl))
request.setReturnUrl(returnUrl);
try {
return newAlipayClient(alipay).pageExecute(request).getBody();
} catch (Throwable e) {
logger.warn(e, "执行支付宝付款时发生异常!");
return null;
}
}
示例10: getUserInfo
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 该方法是用户确定授权后的获取用户信息的方法;
* 方法先解析请求参数,获取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; // 返回空,正常时不会执行此语句
}
示例11: toResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
throws AlipayApiException {
Element root = XmlUtils.getRootElementFromString(rsp);
return getModelFromXML(root, clazz);
}
示例12: toResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
throws AlipayApiException;
示例13: parseResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
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);
}
示例14: toResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 把字符串转换为响应对象。
*
* @param <T> 领域泛型
* @param rsp 响应字符串
* @param clazz 领域类型
* @return 响应对象
* @throws TopException
*/
public <T extends AlipayResponse> T toResponse(String rsp, Class<T> clazz)
throws AlipayApiException;
示例15: parseResponse
import com.alipay.api.AlipayResponse; //导入依赖的package包/类
/**
* 把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);
}