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

相关文章

C++中RAII资源获取即初始化

《C++中RAII资源获取即初始化》RAII通过构造/析构自动管理资源生命周期,确保安全释放,本文就来介绍一下C++中的RAII技术及其应用,具有一定的参考价值,感兴趣的可以了解一下... 目录一、核心原理与机制二、标准库中的RAII实现三、自定义RAII类设计原则四、常见应用场景1. 内存管理2. 文件操

使用jenv工具管理多个JDK版本的方法步骤

《使用jenv工具管理多个JDK版本的方法步骤》jenv是一个开源的Java环境管理工具,旨在帮助开发者在同一台机器上轻松管理和切换多个Java版本,:本文主要介绍使用jenv工具管理多个JD... 目录一、jenv到底是干啥的?二、jenv的核心功能(一)管理多个Java版本(二)支持插件扩展(三)环境隔

SpringBoot服务获取Pod当前IP的两种方案

《SpringBoot服务获取Pod当前IP的两种方案》在Kubernetes集群中,SpringBoot服务获取Pod当前IP的方案主要有两种,通过环境变量注入或通过Java代码动态获取网络接口IP... 目录方案一:通过 Kubernetes Downward API 注入环境变量原理步骤方案二:通过

基于Python实现一个简单的题库与在线考试系统

《基于Python实现一个简单的题库与在线考试系统》在当今信息化教育时代,在线学习与考试系统已成为教育技术领域的重要组成部分,本文就来介绍一下如何使用Python和PyQt5框架开发一个名为白泽题库系... 目录概述功能特点界面展示系统架构设计类结构图Excel题库填写格式模板题库题目填写格式表核心数据结构

Linux系统中的firewall-offline-cmd详解(收藏版)

《Linux系统中的firewall-offline-cmd详解(收藏版)》firewall-offline-cmd是firewalld的一个命令行工具,专门设计用于在没有运行firewalld服务的... 目录主要用途基本语法选项1. 状态管理2. 区域管理3. 服务管理4. 端口管理5. ICMP 阻断

java对接海康摄像头的完整步骤记录

《java对接海康摄像头的完整步骤记录》在Java中调用海康威视摄像头通常需要使用海康威视提供的SDK,下面这篇文章主要给大家介绍了关于java对接海康摄像头的完整步骤,文中通过代码介绍的非常详细,需... 目录一、开发环境准备二、实现Java调用设备接口(一)加载动态链接库(二)结构体、接口重定义1.类型

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地

使用Python实现获取屏幕像素颜色值

《使用Python实现获取屏幕像素颜色值》这篇文章主要为大家详细介绍了如何使用Python实现获取屏幕像素颜色值,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 一、一个小工具,按住F10键,颜色值会跟着显示。完整代码import tkinter as tkimport pyau

python获取cmd环境变量值的实现代码

《python获取cmd环境变量值的实现代码》:本文主要介绍在Python中获取命令行(cmd)环境变量的值,可以使用标准库中的os模块,需要的朋友可以参考下... 前言全局说明在执行py过程中,总要使用到系统环境变量一、说明1.1 环境:Windows 11 家庭版 24H2 26100.4061

conda安装GPU版pytorch默认却是cpu版本

《conda安装GPU版pytorch默认却是cpu版本》本文主要介绍了遇到Conda安装PyTorchGPU版本却默认安装CPU的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目录一、问题描述二、网上解决方案罗列【此节为反面方案罗列!!!】三、发现的根本原因[独家]3.1 p