副本技能-Ebay系统对接获取Token【多店铺版本】

2024-09-05 02:08

本文主要是介绍副本技能-Ebay系统对接获取Token【多店铺版本】,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

流程逻辑:
1.使用ebay配置获取多店铺的授权连接
2.在页面访问多店铺的授权链接
3.确定授权链接,后端获取店铺访问的token

1.调用自身的服务获取店铺授权链接

https://[访问地址]/ebay/[应用ID]/getEbayShopAuthUrl/[店铺名称]
在这里插入图片描述

2.页面授权多店铺链接

相同的链接,后面店铺名称修改不同,进入页面授权即可
在这里插入图片描述
查看返回结果:自己写的代码,格式可以自己确定
在这里插入图片描述

3.查看自己授权成功后保存的代码

在这里插入图片描述

4.复制出自己的token,找个官方接口调用一把

在这里插入图片描述
在这里插入图片描述
核对后发现接口调用获取的数据和从页面查看的数据完全一样,成功了!

以下为参考代码:


/*** @author :xietian* @version :V1.0* @program :open* @date :Created in 2020-10-02 20:18* @description :Ebay API服务*/
@Slf4j
@Service
public class EbayApiServiceImpl implements IEbayApiService {// 沙箱模式权限范围private static final List<String> SCOPE_LIST_SANDBOX = Arrays.asList(new String[] {"https://api.ebay.com/oauth/api_scope","https://api.ebay.com/oauth/api_scope/buy.order.readonly","https://api.ebay.com/oauth/api_scope/buy.guest.order","https://api.ebay.com/oauth/api_scope/sell.marketing.readonly","https://api.ebay.com/oauth/api_scope/sell.marketing","https://api.ebay.com/oauth/api_scope/sell.inventory.readonly","https://api.ebay.com/oauth/api_scope/sell.inventory","https://api.ebay.com/oauth/api_scope/sell.account.readonly","https://api.ebay.com/oauth/api_scope/sell.account","https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly","https://api.ebay.com/oauth/api_scope/sell.fulfillment","https://api.ebay.com/oauth/api_scope/sell.analytics.readonly","https://api.ebay.com/oauth/api_scope/sell.marketplace.insights.readonly","https://api.ebay.com/oauth/api_scope/commerce.catalog.readonly","https://api.ebay.com/oauth/api_scope/buy.shopping.cart","https://api.ebay.com/oauth/api_scope/buy.offer.auction","https://api.ebay.com/oauth/api_scope/commerce.identity.readonly","https://api.ebay.com/oauth/api_scope/commerce.identity.email.readonly","https://api.ebay.com/oauth/api_scope/commerce.identity.phone.readonly","https://api.ebay.com/oauth/api_scope/commerce.identity.address.readonly","https://api.ebay.com/oauth/api_scope/commerce.identity.name.readonly","https://api.ebay.com/oauth/api_scope/commerce.identity.status.readonly","https://api.ebay.com/oauth/api_scope/sell.finances","https://api.ebay.com/oauth/api_scope/sell.item.draft","https://api.ebay.com/oauth/api_scope/sell.payment.dispute","https://api.ebay.com/oauth/api_scope/sell.item","https://api.ebay.com/oauth/api_scope/sell.reputation","https://api.ebay.com/oauth/api_scope/sell.reputation.readonly","https://api.ebay.com/oauth/api_scope/commerce.notification.subscription","https://api.ebay.com/oauth/api_scope/commerce.notification.subscription.readonly","https://api.ebay.com/oauth/api_scope/buy.guest.order","https://api.ebay.com/oauth/api_scope/buy.item.feed","https://api.ebay.com/oauth/api_scope/buy.marketing","https://api.ebay.com/oauth/api_scope/buy.product.feed","https://api.ebay.com/oauth/api_scope/buy.marketplace.insights","https://api.ebay.com/oauth/api_scope/buy.proxy.guest.order","https://api.ebay.com/oauth/api_scope/buy.item.bulk"});// 生产模式权限范围(需要授权,否则拿不到Token)private static final List<String> SCOPE_LIST_PRODUCTION = Arrays.asList(new String[] {"https://api.ebay.com/oauth/api_scope","https://api.ebay.com/oauth/api_scope/sell.marketing.readonly","https://api.ebay.com/oauth/api_scope/sell.marketing","https://api.ebay.com/oauth/api_scope/sell.inventory.readonly","https://api.ebay.com/oauth/api_scope/sell.inventory","https://api.ebay.com/oauth/api_scope/sell.account.readonly","https://api.ebay.com/oauth/api_scope/sell.account","https://api.ebay.com/oauth/api_scope/sell.fulfillment.readonly","https://api.ebay.com/oauth/api_scope/sell.fulfillment","https://api.ebay.com/oauth/api_scope/sell.analytics.readonly","https://api.ebay.com/oauth/api_scope/sell.finances","https://api.ebay.com/oauth/api_scope/sell.payment.dispute","https://api.ebay.com/oauth/api_scope/commerce.identity.readonly","https://api.ebay.com/oauth/api_scope/commerce.notification.subscription","https://api.ebay.com/oauth/api_scope/commerce.notification.subscription.readonly"});/*** Redis缓存*/@Autowiredprivate BladeRedis bladeRedis;/*** eBay店铺授权Token服务*/@Autowiredprivate IEbayAuthTokenService ebayAuthTokenService;/*** eBay开发者账号服务*/@Autowiredprivate IEbayDeveloperAccountService ebayDeveloperAccountService;/*** eBay店铺账号服务*/@Autowiredprivate IEbayShopAccountService ebayShopAccountService;/*** 获取开发者账号,先查Redis,不存在查Mysql* @param appId* @return*/private EbayDeveloperAccount getEbayDeveloperAccount(String appId) {EbayDeveloperAccount developerAccount = bladeRedis.get(OpenCache.EBAY_DEVELOPER_LIST_KEY + appId);if (ObjectUtils.isNull(developerAccount)) {// 查询开发者配置developerAccount = ebayDeveloperAccountService.getOne(new QueryWrapper<>(new EbayDeveloperAccount() {{this.setAppId(appId);}}));// 不为空就存Redisif (ObjectUtils.isNotNull(developerAccount)) {// 超时时间1小时bladeRedis.setEx(OpenCache.EBAY_DEVELOPER_LIST_KEY + appId, developerAccount, 3600L);}}return developerAccount;}/*** 获取配置* @param developerAccount* @return*/private String getConfigYaml(EbayDeveloperAccount developerAccount) {StringBuffer configYaml = new StringBuffer();configYaml.append("name: ebay-config\n");if ("1".equals(developerAccount.getIsSandbox())) {configYaml.append("api.sandbox.ebay.com:\n");configYaml.append("    appid: " + developerAccount.getAppId() + "\n");configYaml.append("    certid: " + developerAccount.getCertId() + "\n");configYaml.append("    devid: " + developerAccount.getDevId() + "\n");configYaml.append("    redirecturi: " + developerAccount.getRedirectName() + "\n");} else {configYaml.append("api.ebay.com:\n");configYaml.append("    appid: " + developerAccount.getAppId() + "\n");configYaml.append("    certid: " + developerAccount.getCertId() + "\n");configYaml.append("    devid: " + developerAccount.getDevId() + "\n");configYaml.append("    redirecturi: " + developerAccount.getRedirectName() + "\n");}return configYaml.toString();}/*** 通过refreshToken 刷新 accessToken** @param appId* @return accessToken* @throws IOException*/public synchronized void refreshAccessToken(String appId, String shopAccount) throws IOException {// 查询开发者配置EbayDeveloperAccount developerAccount = getEbayDeveloperAccount(appId);String refreshToken = bladeRedis.get(OpenCache.EBAY_OAUTH2_TOKEN_REFRESH_KEY + appId);if (StringUtils.isEmpty(refreshToken)) {log.info("刷新token过期,请重新操作应用[{}] 授权店铺[{}]!", appId, shopAccount);return;}OAuth2Api oauth2Api = new OAuth2Api();OAuthResponse oAuthResponse = null;// 加载eBay的评论数据CredentialUtil.load(getConfigYaml(developerAccount));if ("1".equals(developerAccount.getIsSandbox())) {// 沙箱模式oAuthResponse = oauth2Api.getAccessToken(Environment.SANDBOX, refreshToken, SCOPE_LIST_SANDBOX);} else {// 生产模式oAuthResponse = oauth2Api.getAccessToken(Environment.PRODUCTION, refreshToken, SCOPE_LIST_PRODUCTION);}if (null != oAuthResponse.getAccessToken()) {// 保存tokenString token = oAuthResponse.getAccessToken().get().getToken();Long expire = DateUtil.betweenMs(new Date(), oAuthResponse.getAccessToken().get().getExpiresOn());bladeRedis.setEx(OpenCache.EBAY_OAUTH2_TOKEN_KEY + appId, token, expire);}if (null != oAuthResponse.getRefreshToken()) {// 保存刷新tokenString token = oAuthResponse.getRefreshToken().get().getToken();Long expire = DateUtil.betweenMs(new Date(), oAuthResponse.getRefreshToken().get().getExpiresOn());bladeRedis.setEx(OpenCache.EBAY_OAUTH2_TOKEN_REFRESH_KEY + appId, token, expire);}}/*** 获取ebay用户的访问token和refreshToken* @param appId* @param code*/@Overridepublic synchronized void getEbayToken(String appId, String shopAccount, String code) {// 查询开发者配置EbayDeveloperAccount developerAccount = getEbayDeveloperAccount(appId);OAuth2Api oauth2Api = new OAuth2Api();OAuthResponse oAuthResponse = null;try {// 加载eBay的配置CredentialUtil.load(getConfigYaml(developerAccount));if ("1".equals(developerAccount.getIsSandbox())) {// 沙箱模式oAuthResponse = oauth2Api.exchangeCodeForAccessToken(Environment.SANDBOX, code);} else {// 生产模式oAuthResponse = oauth2Api.exchangeCodeForAccessToken(Environment.PRODUCTION, code);}if (null != oAuthResponse.getAccessToken()) {// 保存tokenString token = oAuthResponse.getAccessToken().get().getToken();Long expire = DateUtil.betweenMs(new Date(), oAuthResponse.getAccessToken().get().getExpiresOn());bladeRedis.setEx(OpenCache.EBAY_OAUTH2_TOKEN_KEY + appId + ":" + shopAccount, token, expire);}if (null != oAuthResponse.getRefreshToken()) {// 保存刷新tokenString token = oAuthResponse.getRefreshToken().get().getToken();Long expire = DateUtil.betweenMs(new Date(), oAuthResponse.getRefreshToken().get().getExpiresOn());bladeRedis.setEx(OpenCache.EBAY_OAUTH2_TOKEN_REFRESH_KEY + appId + ":" + shopAccount, token, expire);}} catch (IOException e) {e.printStackTrace();}}/*** 获取ebay用户店铺的授权链接* @param appId* @param shopAccount*/@Overridepublic synchronized String getEbayShopAuthUrl(String appId, String shopAccount) {// 查询开发者配置EbayDeveloperAccount developerAccount = getEbayDeveloperAccount(appId);OAuth2Api oauth2Api = new OAuth2Api();// 店铺授权链接String authUrl = null;// 加载eBay的配置CredentialUtil.load(getConfigYaml(developerAccount));if ("1".equals(developerAccount.getIsSandbox())) {// 沙箱模式authUrl = oauth2Api.generateUserAuthorizationUrl(Environment.SANDBOX, SCOPE_LIST_SANDBOX, Optional.of(shopAccount));} else {// 生产模式authUrl = oauth2Api.generateUserAuthorizationUrl(Environment.PRODUCTION, SCOPE_LIST_PRODUCTION, Optional.of(shopAccount));}return authUrl;}}

这篇关于副本技能-Ebay系统对接获取Token【多店铺版本】的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1137665

相关文章

如何利用Java获取当天的开始和结束时间

《如何利用Java获取当天的开始和结束时间》:本文主要介绍如何使用Java8的LocalDate和LocalDateTime类获取指定日期的开始和结束时间,展示了如何通过这些类进行日期和时间的处... 目录前言1. Java日期时间API概述2. 获取当天的开始和结束时间代码解析运行结果3. 总结前言在J

在不同系统间迁移Python程序的方法与教程

《在不同系统间迁移Python程序的方法与教程》本文介绍了几种将Windows上编写的Python程序迁移到Linux服务器上的方法,包括使用虚拟环境和依赖冻结、容器化技术(如Docker)、使用An... 目录使用虚拟环境和依赖冻结1. 创建虚拟环境2. 冻结依赖使用容器化技术(如 docker)1. 创

修改若依框架Token的过期时间问题

《修改若依框架Token的过期时间问题》本文介绍了如何修改若依框架中Token的过期时间,通过修改`application.yml`文件中的配置来实现,默认单位为分钟,希望此经验对大家有所帮助,也欢迎... 目录修改若依框架Token的过期时间修改Token的过期时间关闭Token的过期时js间总结修改若依

java获取图片的大小、宽度、高度方式

《java获取图片的大小、宽度、高度方式》文章介绍了如何将File对象转换为MultipartFile对象的过程,并分享了个人经验,希望能为读者提供参考... 目China编程录Java获取图片的大小、宽度、高度File对象(该对象里面是图片)MultipartFile对象(该对象里面是图片)总结java获取图片

Java通过反射获取方法参数名的方式小结

《Java通过反射获取方法参数名的方式小结》这篇文章主要为大家详细介绍了Java如何通过反射获取方法参数名的方式,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录1、前言2、解决方式方式2.1: 添加编译参数配置 -parameters方式2.2: 使用Spring的内部工具类 -

Java如何获取视频文件的视频时长

《Java如何获取视频文件的视频时长》文章介绍了如何使用Java获取视频文件的视频时长,包括导入maven依赖和代码案例,同时,也讨论了在运行过程中遇到的SLF4J加载问题,并给出了解决方案... 目录Java获取视频文件的视频时长1、导入maven依赖2、代码案例3、SLF4J: Failed to lo

CentOS系统Maven安装教程分享

《CentOS系统Maven安装教程分享》本文介绍了如何在CentOS系统中安装Maven,并提供了一个简单的实际应用案例,安装Maven需要先安装Java和设置环境变量,Maven可以自动管理项目的... 目录准备工作下载并安装Maven常见问题及解决方法实际应用案例总结Maven是一个流行的项目管理工具

使用Java实现获取客户端IP地址

《使用Java实现获取客户端IP地址》这篇文章主要为大家详细介绍了如何使用Java实现获取客户端IP地址,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 首先是获取 IP,直接上代码import org.springframework.web.context.request.Requ

java中不同版本JSONObject区别小结

《java中不同版本JSONObject区别小结》本文主要介绍了java中不同版本JSONObject区别小结,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们... 目录1. FastjsON2. Jackson3. Gson4. org.json6. 总结在Jav

C++实现获取本机MAC地址与IP地址

《C++实现获取本机MAC地址与IP地址》这篇文章主要为大家详细介绍了C++实现获取本机MAC地址与IP地址的两种方式,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 实际工作中,项目上常常需要获取本机的IP地址和MAC地址,在此使用两种方案获取1.MFC中获取IP和MAC地址获取