傻瓜式教程
启动 Eclipse 并新建工程项目 zhimaOpenDemo
lib 目录下以芝麻信用分查询为例
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 公钥获取方式见**创建应用**和**环境配置**部分。
如果调用成功,响应如下例所示:
{
"biz_no": "ZM201505190ad422641448624704506270407",
"success": true,
"zm_score": "735"
}
如果调用失败,则响应如下所示:
{
"success": false,
"error_code": "ZMOP.invalid_openid_param",
"error_message": "无效的openId参数"
}