支付宝移动端H5登录授权API实现解决方案文档
今天有个业务需求:在移动端绑定支付宝账号,查看了支付宝的官方文档,提供了PC登录和APP登录的API
PC拼接授权页面url
url拼接规则:
https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=商户的APPID&scope=auth_user&redirect_uri=ENCODED_URL&state=init
先尝试了使用上面PC的链接访问,移动端直接提示请在 “支付宝客户端打开链接”
经过搜索,以及支付宝技术的支持,找到了解决方案:
调用支付宝APP协议:
alipays://platformapi/startapp?appId=20000067&url=【上面PC拼接链接的 url encode】
对它做encode, 最后生成如:
alipays://platformapi/startapp?appId=20000067&url=https%3A%2F%2Fopenauth.alipay.com%2Foauth2%2FpublicAppAuthorize.htm%3Fapp_id%3D2018100861620581%26scope%3Dauth_user%26redirect_uri%3Dhttps%253A%252F%252Fwww.xxx.com