副本技能-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

相关文章

使用Python实现获取网页指定内容

《使用Python实现获取网页指定内容》在当今互联网时代,网页数据抓取是一项非常重要的技能,本文将带你从零开始学习如何使用Python获取网页中的指定内容,希望对大家有所帮助... 目录引言1. 网页抓取的基本概念2. python中的网页抓取库3. 安装必要的库4. 发送HTTP请求并获取网页内容5. 解

IDEA中Git版本回退的两种实现方案

《IDEA中Git版本回退的两种实现方案》作为开发者,代码版本回退是日常高频操作,IntelliJIDEA集成了强大的Git工具链,但面对reset和revert两种核心回退方案,许多开发者仍存在选择... 目录一、版本回退前置知识二、Reset方案:整体改写历史1、IDEA图形化操作(推荐)1.1、查看提

Linux系统之主机网络配置方式

《Linux系统之主机网络配置方式》:本文主要介绍Linux系统之主机网络配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、查看主机的网络参数1、查看主机名2、查看IP地址3、查看网关4、查看DNS二、配置网卡1、修改网卡配置文件2、nmcli工具【通用

Linux系统之dns域名解析全过程

《Linux系统之dns域名解析全过程》:本文主要介绍Linux系统之dns域名解析全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、dns域名解析介绍1、DNS核心概念1.1 区域 zone1.2 记录 record二、DNS服务的配置1、正向解析的配置

C++常见容器获取头元素的方法大全

《C++常见容器获取头元素的方法大全》在C++编程中,容器是存储和管理数据集合的重要工具,不同的容器提供了不同的接口来访问和操作其中的元素,获取容器的头元素(即第一个元素)是常见的操作之一,本文将详细... 目录一、std::vector二、std::list三、std::deque四、std::forwa

使用Python高效获取网络数据的操作指南

《使用Python高效获取网络数据的操作指南》网络爬虫是一种自动化程序,用于访问和提取网站上的数据,Python是进行网络爬虫开发的理想语言,拥有丰富的库和工具,使得编写和维护爬虫变得简单高效,本文将... 目录网络爬虫的基本概念常用库介绍安装库Requests和BeautifulSoup爬虫开发发送请求解

JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)

《JDK多版本共存并自由切换的操作指南(本文为JDK8和JDK17)》本文介绍了如何在Windows系统上配置多版本JDK(以JDK8和JDK17为例),并通过图文结合的方式给大家讲解了详细步骤,具有... 目录第一步 下载安装JDK第二步 配置环境变量第三步 切换JDK版本并验证可能遇到的问题前提:公司常

Android App安装列表获取方法(实践方案)

《AndroidApp安装列表获取方法(实践方案)》文章介绍了Android11及以上版本获取应用列表的方案调整,包括权限配置、白名单配置和action配置三种方式,并提供了相应的Java和Kotl... 目录前言实现方案         方案概述一、 androidManifest 三种配置方式

nvm如何切换与管理node版本

《nvm如何切换与管理node版本》:本文主要介绍nvm如何切换与管理node版本问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录nvm切换与管理node版本nvm安装nvm常用命令总结nvm切换与管理node版本nvm适用于多项目同时开发,然后项目适配no

Linux系统中配置静态IP地址的详细步骤

《Linux系统中配置静态IP地址的详细步骤》本文详细介绍了在Linux系统中配置静态IP地址的五个步骤,包括打开终端、编辑网络配置文件、配置IP地址、保存并重启网络服务,这对于系统管理员和新手都极具... 目录步骤一:打开终端步骤二:编辑网络配置文件步骤三:配置静态IP地址步骤四:保存并关闭文件步骤五:重