一、如何获取用户user_id
user_id的获取方法一般有两种:一种是通过调用接口交易成功后的异步通知来获取,一种是使用授权功能来获取
1、通过异步通知来获取
用户调用支付接口支付成功商户可以通过配置异步地址notify_url来接收异步参数,在异步参数中返回的有buyer_id(买家支付宝用户号)这个就是买家的user_id(2088开头的纯16位数字)
以电脑网站支付异步信息为例:
gmt_create=2018-02-28 15:12:13&charset=UTF-8&gmt_payment=2018-02-28 15:12:23¬ify_time=2018-02-28 15:12:23&subject=土豪金&sign=$$$&buyer_id=2088702939584890&invoice_amount=0.01&version=1.0¬ify_id=7d3af4000e3e86a023828b8e4f3a88emvd&fund_bill_list=[{"amount":"0.01","fundChannel":"PCREDIT"}]¬ify_type=trade_status_sync&out_trade_no=20180228151045100596489&total_amount=0.01&trade_status=TRADE_SUCCESS&trade_no=2018022821001004890561282304&auth_app_id=2014110900013222&receipt_amount=0.01&point_amount=0.00&app_id=2014110900013222&buyer_pay_amount=0.01&sign_type=RSA2&seller_id=2088511624560335
2、使用授权功能来获取用户的user_id
第三方应用授权功能和用户信息授权都可以获取到用户的user_id
使用第三方应用授权获取用户的user_id操作步骤:[url]https://openclub.alipay.com/read.php?tid=458[/url]
使用app_auth_code换取app_auth_token 成功获取到app_auth_token 以及user_id,返回信息如下:
{"code":"10000","msg":"Success","app_auth_token":"201802BBf26cfa67f2ec421b842686c1b953fX77","app_refresh_token":"201802BB6fcff0809a9545848fb6d1b2c7e18X77","auth_app_id":"2015102600552291","expires_in":31536000,"re_expires_in":32140800,"tokens":[{"app_auth_token":"201802BBf26cfa67f2ec421b842676c1b953fX78","app_refresh_token":"201802BB6fcff080889545848fb6d1b2c7e18X77","auth_app_id":"2015102600552290","expires_in":31536000,"re_expires_in":32140800,"user_id":"2088802255540772"}],"user_id":"2088802255540772"},"sign":"Njb4hjAYIKR0g4uGJyGGybEs6jJCB4iiypSTj36ZE3/PA4A2MsIVxd7qrc91L0vCZQnt8dZL/N5IXLUAPhsYUczXFaGXyMTdlkyDZUMKayi3+uS9uXd8GSzEbHJYTtj2WSvuHhHjC0SZhQJxAXFy48w8KUdyifd/XAOPiTuBEyPYIvKbNeCGTDKzGHa3jM/+1rCZOB3hIkmgyvYbOjOXlY+PEdSNlbC21SeN6yiofDB4mctjOlEv3iRcaNcXGH+Qz5sQ0h4y5zQU+lNWbhTI1K2d7nxi/2A+EklfZnDinalBNknqWNSaOBKMYTGPVBfGL7Pi/hkdL9Xq582W+cTNpg=="}
使用用户信息授权获取到用户的user_id操作步骤:
PHP版本沙箱测试步骤示例:[url]https://openclub.alipay.com/read.php?tid=1805[/url]
Java版本沙箱测试步骤示例:[url]https://openclub.alipay.com/read.php?tid=1813[/url]
二、user_id,pid,支付宝账号三者之间的关系
user_id和用户的pid是相同的是用户的支付宝账户的唯一标识,即user_id=pid,对应一个支付宝账户。
如有其它疑问,欢迎大家在帖子后面追问!