支付宝官方的用户信息授权,具体地址: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

/// <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 2020-07-31 15:15  £冷☆月№  阅读(1480)  评论(0编辑  收藏  举报