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

相关文章

Linux下如何使用C++获取硬件信息

《Linux下如何使用C++获取硬件信息》这篇文章主要为大家详细介绍了如何使用C++实现获取CPU,主板,磁盘,BIOS信息等硬件信息,文中的示例代码讲解详细,感兴趣的小伙伴可以了解下... 目录方法获取CPU信息:读取"/proc/cpuinfo"文件获取磁盘信息:读取"/proc/diskstats"文

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

SpringMVC获取请求参数的方法

《SpringMVC获取请求参数的方法》:本文主要介绍SpringMVC获取请求参数的方法,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下... 目录1、通过ServletAPI获取2、通过控制器方法的形参获取请求参数3、@RequestParam4、@

利用Python快速搭建Markdown笔记发布系统

《利用Python快速搭建Markdown笔记发布系统》这篇文章主要为大家详细介绍了使用Python生态的成熟工具,在30分钟内搭建一个支持Markdown渲染、分类标签、全文搜索的私有化知识发布系统... 目录引言:为什么要自建知识博客一、技术选型:极简主义开发栈二、系统架构设计三、核心代码实现(分步解析

Python获取C++中返回的char*字段的两种思路

《Python获取C++中返回的char*字段的两种思路》有时候需要获取C++函数中返回来的不定长的char*字符串,本文小编为大家找到了两种解决问题的思路,感兴趣的小伙伴可以跟随小编一起学习一下... 有时候需要获取C++函数中返回来的不定长的char*字符串,目前我找到两种解决问题的思路,具体实现如下:

golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法

《golang获取当前时间、时间戳和时间字符串及它们之间的相互转换方法》:本文主要介绍golang获取当前时间、时间戳和时间字符串及它们之间的相互转换,本文通过实例代码给大家介绍的非常详细,感兴趣... 目录1、获取当前时间2、获取当前时间戳3、获取当前时间的字符串格式4、它们之间的相互转化上篇文章给大家介

浅谈配置MMCV环境,解决报错,版本不匹配问题

《浅谈配置MMCV环境,解决报错,版本不匹配问题》:本文主要介绍浅谈配置MMCV环境,解决报错,版本不匹配问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录配置MMCV环境,解决报错,版本不匹配错误示例正确示例总结配置MMCV环境,解决报错,版本不匹配在col

Python获取中国节假日数据记录入JSON文件

《Python获取中国节假日数据记录入JSON文件》项目系统内置的日历应用为了提升用户体验,特别设置了在调休日期显示“休”的UI图标功能,那么问题是这些调休数据从哪里来呢?我尝试一种更为智能的方法:P... 目录节假日数据获取存入jsON文件节假日数据读取封装完整代码项目系统内置的日历应用为了提升用户体验,

微信公众号脚本-获取热搜自动新建草稿并发布文章

《微信公众号脚本-获取热搜自动新建草稿并发布文章》本来想写一个自动化发布微信公众号的小绿书的脚本,但是微信公众号官网没有小绿书的接口,那就写一个获取热搜微信普通文章的脚本吧,:本文主要介绍微信公众... 目录介绍思路前期准备环境要求获取接口token获取热搜获取热搜数据下载热搜图片给图片加上标题文字上传图片

Python FastAPI+Celery+RabbitMQ实现分布式图片水印处理系统

《PythonFastAPI+Celery+RabbitMQ实现分布式图片水印处理系统》这篇文章主要为大家详细介绍了PythonFastAPI如何结合Celery以及RabbitMQ实现简单的分布式... 实现思路FastAPI 服务器Celery 任务队列RabbitMQ 作为消息代理定时任务处理完整