随笔 - 83,  文章 - 6,  评论 - 20,  阅读 - 10万

支付宝官方的用户信息授权,具体地址:https://opendocs.alipay.com/open/289/105656

商户/开发者通过以下的 URL 拼接规则拼接用户授权的 URL 地址,该地址展示给用户,用户需在支付宝端点开 URL 地址,并点击授权,商户/开发者即可获得用户的授权。
url拼接规则:https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_URL 

scope :接口权限值,目前只支持auth_user(获取用户信息网站支付宝登录)、auth_base(用户信息授权)、auth_ecard(商户会员卡)、auth_invoice_info(支付宝闪电开票)、auth_puc_charge(生活缴费)五个值;多个scope时用”,”分隔,如scope为”auth_user,auth_ecard”时,此时获取到的access_token,既可以用来获取用户信息,又可以给用户发送会员卡。

注意:

1.scope为 auth_base(用户信息授权)时,可以静默授权,不需要用户点击授权,其他必需用户点击授权

2.url拼接规则中的redirect_uri 一定要与 开放平台密钥里面的应用的授权回调地址保持一致 

 

 

这样就可以在支付宝上静默获取auth_code(授权code),通过auth_code就可以获取accesstoken 和 用户userid 。

1.获取支付宝auth_code(授权code)拼装URL

1
2
3
4
5
6
7
8
9
10
11
12
/// <summary>
/// 获取支付宝Code(静默授权)
/// https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_URL
/// scope   接口权限值,目前只支持auth_user(获取用户信息、网站支付宝登录)、auth_base(用户信息授权)、auth_ecard(商户会员卡)、auth_invoice_info(支付宝闪电开票)、auth_puc_charge(生活缴费)五个值;多个scope时用”,”分隔,如scope为”auth_user,auth_ecard”时,此时获取到的access_token,既可以用来获取用户信息,又可以给用户发送会员卡。
/// </summary>
/// <param name="redirectUrl"></param>
public string GetAuthorizeUrl(string redirectUrl)
{
    var appId = AlipayConfig.Mini.CONFIG.AppId;
    string url = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=" + appId + "&scope=auth_base&redirect_uri=" + redirectUrl;
    return url;
}

2.auth_code换取access_token与user_id
通过接口 alipay.system.oauth.token 获取access_token及userId。

posted on   £冷☆月№  阅读(1594)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示