第三方应用授权接入流程(JAVA版)

简介: 第三方应用授权注意事项:[url]https://openclub.alipay.com/read.php?tid=14575&fid=68[/url]一、调用接口1、访问授权,获取app_auth_code获取app_auth_code方式:[url]https://openclub.

第三方应用授权注意事项[url]https://openclub.alipay.com/read.php?tid=14575&fid=68[/url]

一、调用接口

1、访问授权,获取app_auth_code

获取app_auth_code方式:[url]https://openclub.alipay.com/read.php?tid=14581&fid=68[/url]

注:沙箱测试时,只能使用应用授权URL拼接的方式;

沙箱授权URL规则:[url]https://openauth.alipay[/url]dev.com/oauth2/appToAppAuth.htm?app_id=APPID&redirect_uri=ENCODED_URL

3、换取应用授权令牌接口

参数说明:

(1)grant_type:

authorization_code表示换取app_auth_token。 

refresh_token表示刷新app_auth_token。

(2)code:授权码,grant_type的值为authorization_code,该值必须填写。

参数值为授权后获取的app_auth_code;

(3)refresh_token:刷新令牌,grant_type值为refresh_token,该值不能为空。

参数值为此接口的响应参数app_refresh_token(至少需要通过grant_type=authorization_code调用此接口一次才能获取)。

public static void main(String[] args) throws AlipayApiException {		AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);		AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest();		//授权成功后,使用app_auth_code换取app_auth_token		AlipayOpenAuthTokenAppModel model = new AlipayOpenAuthTokenAppModel();		//换取令牌,不改		model.setGrantType("authorization_code");		//app_auth_code参数		model.setCode("603d0219f1884fc4b66093900e6b8X89");		/*//刷新令牌		model.setRefreshToken("a3dcea3a35a342858391dfeaa336cE75");*/		request.setBizModel(model);	    try {	    	AlipayOpenAuthTokenAppResponse response = alipayClient.execute(request);			System.out.println(response.getBody());		} catch (AlipayApiException e) {		    //处理异常		    e.printStackTrace();		}}

响应参数:

{"alipay_open_auth_token_app_response":{"code":"10000","msg":"Success","app_auth_token":"201904BBf9c9781043854fe58c25b4b378350A89","app_refresh_token":"201904BBa095c4366ba74acba2dd971244632F89","auth_app_id":"2018042501227906","expires_in":31536000,"re_expires_in":32140800,"tokens":[{"app_auth_token":"201904BBf9c9781043854fe58c25b4b378350A89","app_refresh_token":"201904BBa095c4366ba74acba2dd971244632F89","auth_app_id":"2018042501227906","expires_in":31536000,"re_expires_in":32140800,"user_id":"2088102175794899"}],"user_id":"2088102175794899"},"sign":"MFnHtA+aZaH+pJuQfIqdZx1ESEhd6QpaHcOPABZOCT+H+KQbSfZdKBPjhZecPDYNgi8MAbIuQ3W0ZV/c9AEF7a2JRFxMWl9h3j67eA5MGJTOt6o6zaKKA7iQY7ZaQvMuihCAJtiY8+Mx9I/SN6wSHpn7PyB6REtTc/DX8AXfO328ek3D/xBGJL0ZOhZwNR8f9PVd9LkjOvbWNkhSo4x6hZtiWpu+0A4hvz7IKrtDaPxLCAtXZGbABx6tnUit4E3JjJ6qfWVsfASLraK5faJIf8+c7TPep30DcWlVw76wcohrwAG9wGL2f/xHEPAKUpX2tZi2p83cH2+u6RuSI4XqUQ=="}

4、查询AppAuthToken的授权信息

参数说明:

app_auth_token:换取应用授权令牌接口返回的响应参数app_auth_token。

public static void main(String[] args) throws AlipayApiException {   AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);		AlipayOpenAuthTokenAppQueryRequest request = new AlipayOpenAuthTokenAppQueryRequest();		/****************************传参方法二*********************		AlipayOpenAuthTokenAppQueryModel model = new AlipayOpenAuthTokenAppQueryModel();		model.setAppAuthToken("appAuthToken");		request.setBizModel(model);		*/		/****************************传参方法一********************/		request.setBizContent("{\"app_auth_token\":\"201904BBf9c9781043854fe58c25b4b378350A89\"}");				AlipayOpenAuthTokenAppQueryResponse response = alipayClient.execute(request);		System.out.println("授权信息:"+response.getBody());}

响应参数:

{"alipay_open_auth_token_app_query_response":{"code":"10000","msg":"Success","auth_app_id":"2018042501227906","auth_end":"2020-04-15 15:54:59","auth_methods":["ant.merchant.expand.indirect.modify","alipay.system.oauth.token","alipay.fund.auth.operation.detail.query","alipay.ebpp.pdeduct.sign.query","koubei.marketing.campaign.activity.offline","zhima.auth.info.authquery","alipay.offline.provider.shopaction.record","alipay.offline.market.shop.create","alipay.trade.refund","ssdata.dataservice.risk.rainscore.query","alipay.user.info.auth","alipay.commerce.cityfacilitator.voucher.generate","koubei.marketing.data.intelligent.effect.query","alipay.ebpp.pdeduct.bill.pay.status","alipay.marketing.campaign.cash.trigger","alipay.pass.template.add","koubei.marketing.data.indicator.query","alipay.eco.cplife.basicservice.initialize","zhima.credit.watchlistii.get","koubei.marketing.campaign.intelligent.promo.batchquery","alipay.eco.cplife.notice.delete","alipay.fund.trans.toaccount.transfer","zhima.credit.score.brief.get","alipay.user.info.share","alipay.eco.edu.kt.billing.modify","koubei.marketing.data.message.deliver","alipay.marketing.tool.fengdie.activity.query","koubei.marketing.data.customreport.save","alipay.eco.cplife.roominfo.upload","alipay.pass.instance.add","alipay.eco.cplife.community.batchquery","koubei.marketing.campaign.intelligent.promo.query","alipay.marketing.tool.fengdie.editor.query","alipay.eco.mycar.parking.parkinglotinfo.query","alipay.trade.precreate","alipay.eco.cplife.roominfo.query","alipay.ebpp.invoice.sycn","alipay.boss.prod.submerchant.create","zhima.customer.certification.query","zoloz.authentication.customer.facemanage.create","koubei.marketing.campaign.intelligent.promo.create","koubei.marketing.data.smartactivity.config","zhima.customer.certification.initialize","alipay.eco.edu.kt.parent.query","alipay.trade.create","alipay.eco.cplife.community.modify","alipay.trade.customs.declare","zhima.merchant.data.upload.initialize","alipay.eco.edu.kt.billing.send","koubei.marketing.campaign.item.merchantactivity.modify","alipay.eco.mycar.parking.parkinglotinfo.create","alipay.eco.cplife.bill.modify","alipay.offline.provider.useraction.record","alipay.trade.order.settle","koubei.marketing.campaign.intelligent.promo.consult","koubei.marketing.campaign.intelligent.promo.modify","alipay.ebpp.invoice.apply.result.sync","alipay.marketing.cdp.advertise.operate","zoloz.authentication.customer.facemanage.delete","koubei.marketing.campaign.crowd.delete","alipay.trade.close","alipay.eco.cplife.residentinfo.delete","monitor.heartbeat.syn","alipay.eco.mycar.parking.order.sync","alipay.commerce.medical.instcard.createandpay","alipay.trade.customs.query","alipay.marketing.cdp.advertise.modify","alipay.ebpp.pdeduct.async.pay","alipay.eco.mycar.parking.enterinfo.sync","alipay.ebpp.invoice.user.trade.query","alipay.boss.prod.submerchant.modify","alipay.eco.edu.kt.student.modify","alipay.eco.cplife.bill.sync","zoloz.authentication.smilepay.initialize","alipay.trade.query","alipay.ebpp.invoice.apply","alipay.eco.edu.kt.schoolinfo.modify","koubei.marketing.campaign.activity.create","zhima.customer.certification.certify","alipay.eco.cplife.community.details.query","alipay.eco.cplife.notice.publish","koubei.marketing.campaign.crowd.batchquery","alipay.commerce.cityfacilitator.voucher.refund","alipay.eco.mycar.parking.parkinglotinfo.update","alipay.ebpp.pdeduct.sign.add","koubei.marketing.data.customreport.batchquery","alipay.ebpp.invoice.info.send","alipay.eco.mycar.parking.exitinfo.sync","alipay.eco.mycar.parking.vehicle.query","alipay.eco.cplife.community.create","alipay.eco.cplife.residentinfo.upload","koubei.marketing.data.customreport.query","koubei.marketing.campaign.item.merchantactivity.create","zhima.customer.certification.material.certify","ant.merchant.expand.indirect.create","alipay.pass.instance.update","zoloz.authentication.customer.ftoken.query","alipay.ebpp.invoice.title.sync","alipay.offline.market.shop.batchquery","alipay.eco.cplife.bill.batch.upload","zhima.data.feedbackurl.query","alipay.trade.pay","alipay.fund.auth.operation.cancel","alipay.ebpp.pdeduct.sign.cancel","zhima.credit.antifraud.verify","alipay.eco.mycar.parking.config.query","alipay.marketing.tool.fengdie.activity.create","alipay.offline.market.applyorder.batchquery","alipay.eco.cplife.bill.batchquery","alipay.marketing.campaign.cash.status.modify","alipay.marketing.campaign.cash.list.query","alipay.security.risk.customerrisk.query","alipay.offline.material.image.upload","alipay.eco.cplife.roominfo.delete","alipay.ebpp.pdeduct.sign.validate","alipay.fund.auth.order.voucher.create","alipay.ebpp.invoice.file.sync.retry","alipay.offline.market.shop.modify","alipay.eco.cplife.basicservice.modify","alipay.marketing.cdp.advertise.query","alipay.data.dataservice.bill.downloadurl.query","alipay.commerce.medical.information.upload","koubei.marketing.campaign.crowd.count","alipay.offline.market.shop.category.query","alipay.trade.wap.pay","koubei.marketing.campaign.activity.batchquery","alipay.eco.edu.kt.billing.query","zhima.merchant.single.data.upload","alipay.commerce.medical.card.query","alipay.offline.market.shop.summary.batchquery","alipay.eco.mycar.parking.config.set","alipay.ebpp.invoice.file.query","alipay.eco.edu.kt.student.query","alipay.open.auth.token.app.query","alipay.trade.app.pay","alipay.ebpp.invoice.title.list.get","ant.merchant.expand.indirect.transfer","koubei.marketing.campaign.crowd.create","koubei.marketing.data.smartactivity.forecast","alipay.ebpp.bill.add","koubei.marketing.campaign.intelligent.shop.consult","alipay.commerce.cityfacilitator.voucher.batchquery","alipay.offline.market.shop.querydetail","alipay.fund.trans.order.query","alipay.security.risk.rainscore.query","zhima.customer.contract.initialize","zhima.credit.score.get","alipay.ebpp.pdeduct.pay","koubei.marketing.data.intelligent.indicator.query","zhima.data.batch.feedback","alipay.trade.fastpay.refund.query","alipay.boss.prod.submerchant.query","alipay.eco.cplife.bill.delete","alipay.marketing.tool.fengdie.template.query","koubei.marketing.campaign.item.merchantactivity.batchquery","koubei.marketing.data.customreport.detail.query","alipay.trade.orderinfo.sync","alipay.security.data.info.securitydata.query","alipay.commerce.cityfacilitator.station.query","alipay.marketing.facetoface.decode.use","alipay.trade.refund.apply","alipay.security.risk.customerrisk.send","ant.merchant.expand.indirect.query","koubei.marketing.campaign.tags.query","alipay.user.userinfo.share","alipay.trade.page.pay","alipay.ebpp.invoice.info.get","alipay.open.auth.token.app","alipay.marketing.campaign.cash.create","alipay.ebpp.invoice.info.applyid.query","koubei.marketing.data.customreport.delete","alipay.pass.template.update","alipay.marketing.cdp.advertise.create","alipay.fund.auth.order.unfreeze","alipay.trade.cancel","koubei.marketing.campaign.item.merchantactivity.close","alipay.eco.cplife.pay.result.query","alipay.marketing.campaign.cash.detail.query","koubei.marketing.campaign.item.merchantactivity.query","koubei.marketing.campaign.activity.modify","alipay.ebpp.invoice.merchantlist.enter.apply","koubei.marketing.campaign.intelligent.promo.delete","alipay.commerce.medical.instcard.bind","alipay.eco.mycar.parking.order.update","koubei.marketing.campaign.crowd.modify","koubei.marketing.campaign.intelligent.template.consult","koubei.marketing.campaign.crowd.detail.query","alipay.ebpp.industry.kms.pubkey.query","alipay.ebpp.bill.get","koubei.marketing.data.smartmanagement.diagnose","zoloz.authentication.customer.smilepay.initialize","koubei.marketing.data.trade.habbit.query","alipay.fund.auth.order.freeze","koubei.trade.order.consult","zhima.merchant.closeloop.data.upload","koubei.marketing.campaign.activity.query","koubei.marketing.campaign.recruit.shop.query","zhima.credit.watchlist.brief.get","alipay.ebpp.invoice.title.dynamic.get"],"auth_start":"2019-04-16 15:54:59","expires_in":31536000,"status":"valid","user_id":"2088102175794899"},"sign":"JIzmwzQF9tyWC+gVSQEtgPrgbv0QTLE5zw56SQkyKxvKzz9a/XhuPgEfMOjOaPviRuzlaf876LKRjqaY9oVui3McAnt5pL9uz/mHseh5t9cTIXFDPBmdTkGstjSpkUIBV6LYUBw8F+atvngzCSP7VcVPd4RpfLQRaB30YxlFr2HYRD1wTBvQFP7XXkJZMQCII0kECQGAY77hqNEF7oJHThY38MLbd/xBKWawfkYONnUgeyO0qNi5IGVShi+/RWZ4O/KWRjuRXi0mq/7wtPLA0H45S7/DLS6ImQ39UF/2nskRW6iISYm4JJ7gLODc2k3eFmWr014iMctfxPLTbxm8cA=="}

二、显示效果

沙箱无法查询,正式环境显示如下

 

如果还是报错,请按如下方式进行提问:

正确提问方式:使用环境(沙箱还是正式环境)+接口名称(中文+英文)+ 请求参数 + 报错信息详情

目录
相关文章
|
19天前
|
缓存 监控 Java
Java线程池提交任务流程底层源码与源码解析
【11月更文挑战第30天】嘿,各位技术爱好者们,今天咱们来聊聊Java线程池提交任务的底层源码与源码解析。作为一个资深的Java开发者,我相信你一定对线程池并不陌生。线程池作为并发编程中的一大利器,其重要性不言而喻。今天,我将以对话的方式,带你一步步深入线程池的奥秘,从概述到功能点,再到背景和业务点,最后到底层原理和示例,让你对线程池有一个全新的认识。
50 12
|
1月前
|
小程序 前端开发 算法
|
1月前
|
Java API 开发者
Java如何实现企业微信审批流程
大家好,我是V哥。本文分享如何在企业微信中实现审批流程,通过调用企业微信的开放API完成。主要内容包括获取Access Token、创建审批模板、发起审批流程和查询审批结果。提供了一个Java示例代码,帮助开发者快速上手。希望对你有帮助,关注V哥爱编程,编码路上同行。
|
2月前
|
SQL IDE Java
入门Cloud Toolkit:简化你的Java应用开发与部署流程
【10月更文挑战第19天】作为一名长期从事Java开发的程序员,我一直致力于寻找能够简化日常开发工作的工具。在众多工具中,阿里巴巴推出的Cloud Toolkit引起了我的注意。这款免费的插件旨在帮助开发者更轻松地进行开发、测试及部署工作,尤其是在与云服务交互时表现尤为出色。本文将从个人的角度出发,介绍Cloud Toolkit的基本功能及其使用技巧,希望能帮助初学者快速上手这款实用工具。
31 1
|
2月前
|
前端开发 安全 Java
java发布公告的实现流程
构建一个Java公告发布系统涉及到前端界面设计、后端业务逻辑处理、数据库设计与交互、安全性保障等多个环节。通过采用现代的开发框架和最佳实践,可以高效地开发出既安全又易于维护的系统。随着需求的增长,系统还可以进一步扩展,比如增加评论功能、通知订阅、多语言支持等。
47 1
|
2月前
|
运维 Cloud Native Java
Java项目部署的发展流程
本文介绍了四种不同的应用部署方式:传统部署、虚拟化部署、容器化部署和云原生部署。每种方式的特点、部署流程及优缺点进行了详细说明。传统部署直接在物理机上运行应用,存在资源利用率低和运维成本高的问题;虚拟化部署通过虚拟机实现资源隔离和复用,但有性能损失和单点故障风险;容器化部署则提供轻量级、可移植的应用环境,具备良好的隔离性和一致性;云原生部署结合了容器化和微服务架构,实现高效运维和灵活扩展。
Java项目部署的发展流程
|
4月前
|
运维 Cloud Native Java
Java项目部署的发展流程
本文对比分析了四种不同的应用部署方式:传统部署、虚拟化部署、容器化部署及云原生部署。传统部署直接在物理机上运行程序,存在资源复用难等问题。虚拟化部署通过虚拟机技术实现了资源的有效隔离与利用,但可能会造成性能损失。容器化部署则进一步提升了应用的可移植性和资源利用率,减轻了运维负担。云原生部署结合容器化、微服务等技术,实现了应用的快速迭代、高效运维和灵活扩展,适用于现代互联网应用的开发与部署。每种方式均针对其特点进行了详细的流程描述与优缺点分析。
|
4月前
|
Java
在Java编程的广阔天地中,条件语句是控制程序流程、实现逻辑判断的重要工具。
在Java编程中,if-else与switch作为核心条件语句,各具特色。if-else以其高度灵活性,适用于复杂逻辑判断,支持多种条件组合;而switch在多分支选择上表现优异,尤其适合处理枚举类型或固定选项集,通过内部跳转表提高执行效率。两者各有千秋:if-else擅长复杂逻辑,switch则在多分支选择中更胜一筹。理解它们的特点并在合适场景下使用,能够编写出更高效、易读的Java代码。
40 1
|
4月前
|
Java
Java 流程控制15道练习题(选择&循环)
Java 流程控制15道练习题(选择&循环)
109 10
|
4月前
|
存储 安全 Java
【Java 第四篇章】流程控制、容器
本文档详细介绍了Java中的流程控制、集合类型、数组声明及容器的声明与遍历等内容。在流程控制部分,包括了if、if...else、if...else if...else、switch等语句的使用方法,并提供了具体示例。接着,文档对比分析了Java中单列集合(如HashSet、LinkedHashSet、TreeSet等)与双列集合(如HashMap、LinkedHashMap、Hashtable等)的特点及底层实现原理。此外,还介绍了如何声明与初始化数组,并提供了多种循环结构的使用示例。最后,通过具体的代码示例展示了不同集合类型的声明、基本操作(如添加、删除、更新、查找)以及遍历方法。
24 0