天天看點

擷取會員資訊內建流程一、文檔位址二、開發前準備工作三、接口調用流程四、會員授權資訊查詢接口請求示例五、注意事項六、常見報錯

該接口主要用于擷取支付寶使用者的基礎資訊:使用者ID、昵稱、性别、省份、城市、使用者頭像、使用者類型、使用者狀态、是否實名認證、是否是學生等資訊。

一、文檔位址

官方文檔位址:[url]https://docs.open.alipay.com/284/106001[/url]

二、開發前準備工作

調用步驟:[url]https://openclub.alipay.com/read.php?tid=12194&fid=69[/url]

注意事項:1、支援沙箱測試;2、不需簽約,但需要添加功能;3、支援第三方調用。

擷取會員資訊內建流程一、文檔位址二、開發前準備工作三、接口調用流程四、會員授權資訊查詢接口請求示例五、注意事項六、常見報錯

三、接口調用流程

1、授權URL拼接,擷取access_token

具體調用步驟參考:[url]https://openclub.alipay.com/read.php?tid=14595&fid=68#anchor2[/url]

注:由于該産品是需要實作擷取會員資訊的功能,授權URL拼接的scope必須傳入auth_user。

如scope=auth_user,auth_base。

2、擷取使用者資訊

擷取使用者資訊必須通過alipay.user.info.share(支付寶會員授權資訊查詢接口) 調用擷取。

具體代碼調用方式參見支付寶會員授權資訊查詢接口請求示例。

四、會員授權資訊查詢接口請求示例

1、參數說明

auth_token:alipay.system.oauth.token(換取授權通路令牌) 接口調用傳回的響應參數access_token。

注:該接口不需要設定請求參數,隻需要在公共參數中必傳auth_token

2、JAVA版本請求示例

public static void main(String[] args) throws AlipayApiException {		AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);		//調用接口擷取使用者資訊		AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest();		//需要使用者授權後,将auth_code換取accessToken,注入		String accessToken = "composeBd364827b102144cf992fb7ce6e327X89";		try {			AlipayUserInfoShareResponse response = alipayClient.execute(request, accessToken);			System.out.println(response.getBody());		} catch (AlipayApiException e) {		    //處理異常		    e.printStackTrace();		}}           

響應參數

{"alipay_user_info_share_response":{"code":"10000","msg":"Success","gender":"f","is_certified":"T","is_student_certified":"F","nick_name":"買家沙箱","user_id":"2088102175794899","user_status":"T","user_type":"2"},"sign":"GFOQ5SbhPPSkL1Dmf9snUJxTEeCxngsXOQubURBIDx5C9/sb7CnNmHdSXDru9NPDlvfSQPT+b+iUOVapARafpsdqP6XIdHqQfrLB2jE6YO2ql52J07/yGrUNAwjaaKd/ndBbpljhn9laQATD1sqrwwUGmttiGkyK6cPvW3lH/ndAvbDRkwnKdrLKZGSou3erf0thL6QzlS12XXryTnvEArCuteAsqqDFi81R/PVKyXdl15P9SdVQzhJski5yZ3A1VEO9Vv96bVjVlgUZaIALddjOX4rh100e/mxx7K8qOmjX12r72pFyPrVEAQChRTSx1OxiXureiCScscHKtZdOQg=="}           

3、PHP版本請求示例

$aop = new AopClient ();$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';$aop->appId = 'your app_id';$aop->rsaPrivateKey = '請填寫開發者私鑰去頭去尾去回車,一行字元串';$aop->alipayrsaPublicKey='請填寫支付寶公鑰,一行字元串';$aop->apiVersion = '1.0';$aop->signType = 'RSA2';$aop->postCharset='GBK';$aop->format='json';$request = new AlipayUserInfoShareRequest ();$result = $aop->execute ( $request , 'composeBd364827b102144cf992fb7ce6e327X89'); echo json_encode($result);           
{"alipay_user_info_share_response":{"code":"10000","msg":"Success","gender":"f","is_certified":"T","is_student_certified":"F","nick_name":"買家沙箱","user_id":"2088102175794899","user_status":"T","user_type":"2"},"sign":"GFOQ5SbhPPSkL1Dmf9snUJxTEeCxngsXOQubURBIDx5C9/sb7CnNmHdSXDru9NPDlvfSQPT+b+iUOVapARafpsdqP6XIdHqQfrLB2jE6YO2ql52J07/yGrUNAwjaaKd/ndBbpljhn9laQATD1sqrwwUGmttiGkyK6cPvW3lH/ndAvbDRkwnKdrLKZGSou3erf0thL6QzlS12XXryTnvEArCuteAsqqDFi81R/PVKyXdl15P9SdVQzhJski5yZ3A1VEO9Vv96bVjVlgUZaIALddjOX4rh100e/mxx7K8qOmjX12r72pFyPrVEAQChRTSx1OxiXureiCScscHKtZdOQg=="}           

4、.NET版本請求示例

IAopClient client = new DefaultAopClient(config.gatewayUrl, config.app_id, config.private_key, "json", "1.0", "RSA2", config.alipay_public_key, config.charset, false);AlipayUserInfoShareRequest  request= new AlipayUserInfoShareRequest() ;AlipayUserInfoShareResponse response=client.execute(request,"composeBd364827b102144cf992fb7ce6e327X89");Console.WriteLine(response.Body);           
{"alipay_user_info_share_response":{"code":"10000","msg":"Success","gender":"f","is_certified":"T","is_student_certified":"F","nick_name":"買家沙箱","user_id":"2088102175794899","user_status":"T","user_type":"2"},"sign":"GFOQ5SbhPPSkL1Dmf9snUJxTEeCxngsXOQubURBIDx5C9/sb7CnNmHdSXDru9NPDlvfSQPT+b+iUOVapARafpsdqP6XIdHqQfrLB2jE6YO2ql52J07/yGrUNAwjaaKd/ndBbpljhn9laQATD1sqrwwUGmttiGkyK6cPvW3lH/ndAvbDRkwnKdrLKZGSou3erf0thL6QzlS12XXryTnvEArCuteAsqqDFi81R/PVKyXdl15P9SdVQzhJski5yZ3A1VEO9Vv96bVjVlgUZaIALddjOX4rh100e/mxx7K8qOmjX12r72pFyPrVEAQChRTSx1OxiXureiCScscHKtZdOQg=="}           

五、注意事項

1、auth_token傳參方式

接口調用方式中,設定auth_token的代碼示例:

JAVA:

response = alipayClient.execute(request, accessToken);           

PHP:

$result = $aop->execute($request,$accessToken);            

.net:

response=client.execute(request,accessToken);           

2、服務商代商戶調用擷取使用者資訊

服務商如何代商戶調用擷取使用者資訊:[url]https://openclub.alipay.com/read.php?tid=12762&fid=68[/url]

六、常見報錯

1、Q:傳回響應參數,無nick_name(昵稱)?

A:(1)該使用者為企業賬戶無法擷取昵稱;

  (2)該使用者未設定昵稱;

2、Q:傳回響應參數,無avatar(使用者頭像位址)?

A:該使用者賬戶未設定頭像。

3、Q:如何校驗使用者是否實名認證?

A:根據查詢會員資訊接口傳回的響應參數user_status使用者狀态(Q/T/B/W)進行判斷。

        Q代表快速注冊使用者 

        T代表已認證使用者 

        B代表被當機賬戶 

        W代表已注冊,未激活的賬戶

如果還是報錯,請按如下方式進行提問:

正确提問方式:使用環境(沙箱還是正式環境)+接口名稱(中文+英文)+ 請求參數 + 報錯資訊詳情