支付宝生活号获取用户授权

为了下次不用再去看一遍官方文档,简单的做一下笔记。想了解更多的细节,请移步支付宝官方文档

1、用户授权,拼接的url,如下:

获取用户信息的授权scope=auth_user:

https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=auth_user&redirect_uri=ENCODED_URL?state=STATE

业务页面使用的静默授权scope=auth_base:

https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=auth_base&redirect_uri=ENCODED_URL?state=STATE

参数解析:

APPID:注册的时候会有的APPID

scope:auth_user / auth_base 

ENCODED_URL:encode之后的需要跳转回去的链接

STATE:用于检查

2、用户授权之后跳转到重定向链接ENCODED_URL并加上参数,这时我们获取到了auth_code,示例链接如下:

http:

//example.com/doc/toAuthPage.html?app_id=2014101500013658&source=alipay_wallet&scope=auth_user&auth_code=ca34ea491e7146cc87d25fca24c4cD11

3、使用auth_code换取接口access_token及用户userId

接口名称:alipay.system.oauth.token

alipay.system.oauth.token(换取授权访问令牌) | API

//请求

REQUEST URL: https://openapi.alipay.com/gateway.do
REQUEST METHOD: POST
CONTENT:
    app_id=2014070100171525
    method=alipay.system.oauth.token
    charset=GBK
    sign_type=RSA2
    timestamp=2014-01-01 08:08:08
    sign=rXaTEfJ7WTDsP1DWRPHARW3uOr19+fzlngMCJBvbhP1XPEa9qZwGGng9oMDloABpJMT2SGeOj46+BUkqCGRO9fH90Vci3hOH01BfYnbhJz3ADK2h7gpjlponx4/sxELN6f2GXi51XKiHKnxMA9XpLLo68q+roY0M/ZFQ1UdnqeM=
    version=1.0
    grant_type=authorization_code
    code=4b203fe6c11548bcabd8da5bb087a83b
    refresh_token=201208134b203fe6c11548bcabd8da5bb087a83b

//返回


{
    "alipay_system_oauth_token_response": {
        "access_token": "publicpBa869cad0990e4e17a57ecf7c5469a4b2",
        "user_id": "2088411964574197",
        "alipay_user_id": "20881007434917916336963360919773",
        "expires_in": 300,
        "re_expires_in": 300,
        "refresh_token": "publicpB0ff17e364f0743c79b0b0d7f55e20bfc"
    },
    "sign": "xDffQVBBelDiY/FdJi4/a2iQV1I7TgKDFf/9BUCe6+l1UB55YDOdlCAir8CGlTfa0zLYdX0UaYAa43zY2jLhCTDG+d6EjhCBWsNY74yTdiM95kTNsREgAt4PkOkpsbyZVXdLIShxLFAqI49GIv82J3YtzBcVDDdDeqFcUhfasII="
}

4、调用接口获取用户信息

接口名称:alipay.user.info.share

alipay.user.info.share(支付宝会员授权信息查询接口) | API

scope=auth_base时,不需要第四步

你可能感兴趣的:(支付宝生活号,前端)