100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > java系统对接方案_阿里巴巴开放平台SDK(java版). 接入授权店铺数据 对接企业内部管

java系统对接方案_阿里巴巴开放平台SDK(java版). 接入授权店铺数据 对接企业内部管

时间:2019-12-05 19:19:27

相关推荐

java系统对接方案_阿里巴巴开放平台SDK(java版). 接入授权店铺数据 对接企业内部管

AlibabaSDK-java

阿里巴巴开放平台SDK. 接入授权店铺数据,对接企业内部管理系统的解决方案

获取授权链接

@Test

public void testGetPreAuthUrl() throws Exception {

PreAuthAPIPlot plot = new PreAuthAPIPlot("******", "1688",

"http://www.eastmall.vip/ali-pre-auth", "******");

String url = plot.getAuthorizationUrl();

System.out.println(url);

}

用授权码换取令牌

@Test

public void testAccessTokenExecutor() throws Exception {

String clientId = "******";

String clientSecret = "******";

String redirectUrl = "http://www.eastmall.vip/ali-pre-auth";

String preAuthCode = "2c823974-63c8-4e5c-b3d5-09a6bacd5057";

AccessTokenExecutor executor = new AccessTokenExecutor(clientId, clientSecret, redirectUrl, preAuthCode);

ResponseEntity result = executor.invoke();

System.out.println(result);

}

刷新令牌

@Test

public void testRefreshTokenExecutor() throws Exception {

String clientId = "******";

String clientSecret = "******";

String refreshToken = "41227eb4-520e-48e0-a432-7d17c870bf6c";

RefreshTokenExecutor executor = new RefreshTokenExecutor(clientId, clientSecret, refreshToken);

ResponseEntity result = executor.invoke();

System.out.println(result);

}

更新令牌,通常如果refresh_token到期前一个月才允许更新令牌

@Test

public void testRenewRefreshTokenExecutor() throws Exception {

String clientId = "******";

String clientSecret = "*******";

String accessToken = "8f4b8fd6-d71b-4a25-8cc3-2ea3a4333f46";

String refreshToken = "41227eb4-520e-48e0-a432-7d17c870bf6c";

RenewRefreshTokenExecutor executor = new RenewRefreshTokenExecutor(clientId, clientSecret, accessToken,

refreshToken);

ResponseEntity result = executor.invoke();

System.out.println(result);

}

取得订单列表(卖家视图)

@Test public void testOrderListOnSellerViewExecutor() throws Exception {

AuthorizationToken token = new AuthorizationToken();

token.setAccess_token("8f4b8fd6-d71b-4a25-8cc3-2ea3a4333f46");

token.setAliId(123456789l);

token.setMemberId("******");

token.setClientId("******");

token.setClientSecret("******");

token.setExpires_in(35999);

token.setRefresh_token("41227eb4-520e-48e0-a432-7d17c870bf6c");

token.setRefresh_token_timeout("1113172954000+0800");

token.setResource_owner("zheming");

ParamsOfOrderListOnSellerView param = new ParamsOfOrderListOnSellerView();

param.setPage(1);

param.setPageSize(20);

// 如果失败,是否再试一次

boolean retryIfFail = true;

OrderListOnSellerViewExecutor executor = new OrderListOnSellerViewExecutor(token, param, retryIfFail);

ResponseEntity result = executor.invoke();

System.out.println(result);

}

取得订单详情(卖家视图)

@Test

public void testOrderOnSellerViewExecutor() throws Exception {

AuthorizationToken token = new AuthorizationToken();

token.setAccess_token("8f4b8fd6-d71b-4a25-8cc3-2ea3a4333f46");

token.setAliId(1234546789l);

token.setMemberId("*******");

token.setClientId("******");

token.setClientSecret("******");

token.setExpires_in(35999);

token.setRefresh_token("41227eb4-520e-48e0-a432-7d17c870bf6c");

token.setRefresh_token_timeout("1113172954000+0800");

token.setResource_owner("zheming");

ParamsOfOrderDetailOnSellerView param = new ParamsOfOrderDetailOnSellerView();

param.setOrderId("159310337253103128");

// 如果失败,是否再试一次

boolean retryIfFail = true;

OrderDetailOnSellerViewExecutor executor = new OrderDetailOnSellerViewExecutor(token, param, retryIfFail);

ResponseEntity result = executor.invoke();

System.out.println(result);

}

令牌刷新后续处理句柄

/*

* 句柄 模拟器

*

*/

public class HandlerSimulator {

/*

*

*/

public void notifyOfHandlerPurpose(Object object) {

System.out.println("notifyOfHandlerPurpose:" + object.toString());

}

}

演示令牌刷新后续处理句柄

@Test

public void testOrderOnSellerViewExecutorWithTokenRefreshHandler() throws Exception {

/*

* 本测试使用内部类,实际工作时调用外部类的方法

*/

HandlerSimulator handlerSimulator = new HandlerSimulator();

AuthorizationToken token = new AuthorizationToken();

token.setAccess_token("****");

token.setAliId(123456789l);

token.setMemberId("b2b-123456");

token.setClientId("******");

token.setClientSecret("******");

token.setExpires_in(35999);

token.setRefresh_token("41227eb4-520e-48e0-a432-7d17c870bf6c");

token.setRefresh_token_timeout("1113172954000+0800");

token.setResource_owner("zheming");

ParamsOfOrderDetailOnSellerView param = new ParamsOfOrderDetailOnSellerView();

param.setOrderId("159310337253103128");

// 如果失败,是否再试一次

boolean retryIfFail = true;

OrderDetailOnSellerViewExecutor executor = new OrderDetailOnSellerViewExecutor(token, param, retryIfFail);

/*

* 注入令牌刷新的后续处理句柄

* 要求,注入的方法必须是处理JSON.toJSON的令牌实体

*/

executor.attachAfterAccessTokenRefreshHandler(handlerSimulator, "notifyOfHandlerPurpose");

ResponseEntity result = executor.invoke();

System.out.println(result);

}

java系统对接方案_阿里巴巴开放平台SDK(java版). 接入授权店铺数据 对接企业内部管理系统的解决方案...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。