文档中心 > 芝麻开放文档测试

芝麻信用-开始接入-开发指南-Java SDK 开发示例

更新时间:2017/02/13 访问次数:1256

傻瓜式教程

新建项目

启动 Eclipse 并新建工程项目 zhimaOpenDemo

图1

配置 SDK

  1. 下载 SDK 并解压缩,并放到 lib 目录下

image

  1. 将引入的 jar 包添加到工程引用目录下:选择 jar 包,右键 | Build Path | Add to Build Path

image

  1. 添加完成

image

调用接口

以芝麻信用分查询为例

  1. 在项目中添加 com.zhima.demo.TestZhimaCreditScoreGet 类,并将下列示例代码复制过去:
package com.zhima.demo;

import com.antgroup.zmxy.openplatform.api.DefaultZhimaClient;
import com.antgroup.zmxy.openplatform.api.ZhimaApiException;
import com.antgroup.zmxy.openplatform.api.request.ZhimaCreditScoreGetRequest;
import com.antgroup.zmxy.openplatform.api.response.ZhimaCreditScoreGetResponse;

public class TestZhimaCreditScoreGet {

    //芝麻开放平台地址
    private String gatewayUrl     = Consts.URL;
    //商户应用 Id
    private String appId          = Consts.APP_ID;
    //商户 RSA 私钥
    private String privateKey     = Consts.PRIVATE_KEY;
    //芝麻 RSA 公钥
    private String zhimaPublicKey = Consts.ZM_PUBLIC_KEY;

    public void testZhimaCreditScoreGet() {
        ZhimaCreditScoreGetRequest req = new ZhimaCreditScoreGetRequest();
        req.setPlatform("zmop");
        req.setTransactionId("201512100936588040000000465158");// 必要参数         
        req.setProductCode("w1010100100000000001");// 必要参数         
        req.setOpenId("26881109623641136250991845");// 必要参数         
        DefaultZhimaClient client = new DefaultZhimaClient(gatewayUrl, appId, privateKey,
            zhimaPublicKey);
        try {
            ZhimaCreditScoreGetResponse response = client.execute(req);
            System.out.println(response.isSuccess());
            System.out.println(response.getBody());
            System.out.println(response.getErrorCode());
            System.out.println(response.getErrorMessage());
        } catch (ZhimaApiException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        TestZhimaCreditScoreGet result = new TestZhimaCreditScoreGet();
        result.testZhimaCreditScoreGet();
    }

}

NOTE: 商户应用 ID,商户 RSA 私钥,芝麻 RSA 公钥获取方式见**创建应用**和**环境配置**部分。

image

如果调用成功,响应如下例所示:

{
  "biz_no": "ZM201505190ad422641448624704506270407",
  "success": true,
  "zm_score": "735"
}

如果调用失败,则响应如下所示:

{
  "success": false,
  "error_code": "ZMOP.invalid_openid_param",
  "error_message": "无效的openId参数"
}

FAQ

关于此文档暂时还没有FAQ
返回
顶部