说明:
本帖是利用支付宝沙箱测试获取会员信息接口,demo中会配置个人的沙箱账号信息,方便大家测试。
测试环境:JAVA1.5+,eclipse
接口文档:【查看】
沙箱环境测试改正式环境测试请修改网关为下方值
正式环境网关:[url]https://openapi.alipay.com/gateway.do[/url]
demo示例代码下载:
download:获取会员信息demo.zip
测试流程(声明:demo仅做参考使用):
1.生成应用,配置密钥可参考该文档:[url]https://openclub.alipay.com/read.php?tid=1606&fid=25[/url]
2.用户信息授权获取auth_token ,可参照该贴:[url]https://openclub.alipay.com/read.php?tid=1813&fid=43[/url]
3.调用接口获取用户信息,接口名称:alipay.user.info.share
将获取到的访问令牌赋值给auth_token 进行查询
import com.alipay.api.AlipayApiException;import com.alipay.api.AlipayClient;import com.alipay.api.DefaultAlipayClient;import com.alipay.api.request.AlipayUserInfoShareRequest;import com.alipay.api.response.AlipayUserInfoShareResponse;import com.alipay.config.AlipayConfig; /** * alipay.user.info.share(支付宝会员授权信息查询接口) * 参考文档:[url]https://docs.open.alipay.com/api_2/alipay.user.info.share[/url] * @author wb-wly251833 * */public class alipayUserInfoShare { 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(); String auth_token = "composeB7de1a0c875c445ca869957019c10cX75"; try { AlipayUserInfoShareResponse userinfoShareResponse = alipayClient.execute(request, auth_token); System.out.println(userinfoShareResponse.getBody()); } catch (AlipayApiException e) { //处理异常 e.printStackTrace(); } }}
查询结果:
{"alipay_user_info_share_response":{"code":"10000","msg":"Success","avatar":"https:\/\/tfs.alipay.net\/images\/partner\/T1SpFXXexkXXXXXXXX","gender":"f","is_certified":"T","is_student_certified":"F","user_id":"2088102169462753","user_status":"T","user_type":"2"},"sign":"dkiOqFJ2rDajnw1VlYpVUKB4JTiuTZNoSN6JOb8WWrr59BTmxvetHAggkm/IODab2ym23d0eCJQOIVBwMciT3U0MJW8q48/B0BqCssdbmdb64DQ1FW54H8RaDllRYaygrS7aQNstd9bdrRmF9IbWrfZqW491I9rLbmO5WOrczOgWYtA6L6ZmUnW/6+Gsi3gVgR+xJz4eGlLt37bP/t/+Ak1I97lOwav4QeZPKiK1Tltv01pGrg6GJHuw0zcJcAewtwi0KHG2Z1DHQrBNveAWmOncJAZeTUCm5VchfbdnpFuzcfFfQZdxWcJYECmQJlUgH2i8nLLG1HhxOyCyCF8seA=="}
如果令牌过期则会报‘访问令牌已过期’:
{"alipay_user_info_share_response":{"code":"20001","msg":"Insufficient Token Permissions","sub_code":"aop.auth-token-time-out","sub_msg":"访问令牌已过期"},"sign":"AO/VlZB49fMpyJSF9IsJpYc8RPYWmIpvQ4fpODVkqi06Vae1UR7romey6WA73nYq9IR0maXXnkgNv0oiZ4RL4N7aVdKowxPBoQ13SBeBw2r+V1IENwnlxXrtUjKHS2J9hWBRk7P3SNOJgKHnNPHs0sVIyGFaJMigXb+V+G/DG3lBOrjdaeal3Z5xPzw3cFrHHgqe0z6VAY6hlB+8RChsLlFYaL+Hsor28b8h3WRaPUFEv5akfkxi0228sqx/q+moRPh3f4RGmyXLPluHQWIaRvu/Uyp7oy6199o/qfVy0h0XINZ+ctlVjB0t9i9Pe58qKxfHFqjguT2e2S+udGfXrw=="}