栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Java调用用户芝麻信用分

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Java调用用户芝麻信用分

本文实例为大家分享了Java调用用户芝麻信用分的具体代码,供大家参考,具体内容如下

1.导入芝麻信用API:zmxy-sdk-java-20180824112425.jar 和 fastjson-1.2.48.jar

2.代码如下:

package com.zhima;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.antgroup.zmxy.openplatform.api.DefaultZhimaClient;
import com.antgroup.zmxy.openplatform.api.ZhimaApiException;
import com.antgroup.zmxy.openplatform.api.internal.util.RSACoderUtil;
import com.antgroup.zmxy.openplatform.api.request.ZhimaAuthInfoAuthorizeRequest;
import com.antgroup.zmxy.openplatform.api.request.ZhimaAuthInfoAuthqueryRequest;
import com.antgroup.zmxy.openplatform.api.request.ZhimaCreditScoreGetRequest;
import com.antgroup.zmxy.openplatform.api.response.ZhimaAuthInfoAuthqueryResponse;
import com.antgroup.zmxy.openplatform.api.response.ZhimaCreditScoreGetResponse;

public class Demo {

 //芝麻开放平台地址

 private static final String URL  = "https://zmopenapi.zmxy.com.cn/openapi.do";

 //商户应用 Id

 private static final String APPID = "";

 //商户 RSA 私钥

 private static final String PRIKEY = "";

 //芝麻 RSA 公钥

 private static final String PUBKEY = "";

 //统一字符集

 private static final String CHARSET = "UTF-8";

 

 public void testZhimaAuthInfoAuthorize() {

  ZhimaAuthInfoAuthorizeRequest req = new ZhimaAuthInfoAuthorizeRequest();

  req.setIdentityType("2");// 身份标识

  req.setChannel("apppc"); // PC端

  // 必要参数 state: 用于给商户提供透传的参数,芝麻会将此参数透传给商户

  req.setBizParams("{"auth_code":"M_APPPC_CERT","state":"100111211"}");

  req.setIdentityParam(
   "{"certNo":"330621198710114617","certType":"IDENTITY_CARD","name":"陈金赛"}");// 必要参数  

  DefaultZhimaClient client = new DefaultZhimaClient(URL, APPID, CHARSET, PRIKEY, PUBKEY);

  try {

   String url = client.generatePageRedirectInvokeUrl(req);

   System.out.println(url);

  } catch (ZhimaApiException e) {

   e.printStackTrace();

  }

 }

 

 public void testZhimaAuthInfoReq() {

  ZhimaAuthInfoAuthqueryRequest req = new ZhimaAuthInfoAuthqueryRequest();

  // 0:芝麻信用开放账号ID 1:按照手机号进行授权 2:按照身份证+姓名进行授权 3通过公安网验证进行授权 4.通过人脸验证进行授权

  req.setIdentityType("2");

  req.setIdentityParam(
   "{"certNo":"522121198710114617","certType":"IDENTITY_CARD","name":"但镜宇"}");// 必要参数  

  DefaultZhimaClient client = new DefaultZhimaClient(URL, APPID, CHARSET, PRIKEY, PUBKEY);

  try {

   // 如果正常返回,直接在对象里面获取结果值

   ZhimaAuthInfoAuthqueryResponse response = client.execute(req);

   System.out.println(JSON.toJSON(response));

   

  } catch (ZhimaApiException e) {

   e.printStackTrace();

  }

 }

 

 public static void testQueryScore() throws ZhimaApiException {

  ZhimaCreditScoreGetRequest creditScoreGetRequest = new ZhimaCreditScoreGetRequest();

  creditScoreGetRequest.setPlatform("zmop"); // 开放平台,zmop代表芝麻开放平台

  creditScoreGetRequest.setChannel("apppc"); // pc端

  //transactionId,该标记是商户每次请求的唯一标识。建议使用uuid进行传递,

  creditScoreGetRequest.setTransactionId(UUID.randomUUID().toString());

  creditScoreGetRequest.setProductCode("w1010100100000000001"); // 商户配置那块儿的产品Code

  creditScoreGetRequest.setOpenId("268816113399909561399995894"); // appid,每个人的标识

  DefaultZhimaClient client = new DefaultZhimaClient(URL, APPID, CHARSET, PRIKEY, PUBKEY);

  // 如果正常返回,直接在对象里面获取结果值

  ZhimaCreditScoreGetResponse creditScoreGetResponse = client.execute(creditScoreGetRequest);

  System.out.println(JSON.toJSON(creditScoreGetResponse));

  

 }

 

 public static void testPageAuth() throws Exception {

  ZhimaAuthInfoAuthorizeRequest authInfoAuthorizeRequest = new ZhimaAuthInfoAuthorizeRequest();

  authInfoAuthorizeRequest.setChannel("apppc"); // PC端

  authInfoAuthorizeRequest.setPlatform("zmop"); // 开放平台

  // 0:芝麻信用开放账号ID 1:按照手机号进行授权 2:按照身份证+姓名进行授权 3通过公安网验证进行授权 4.通过人脸验证进行授权

  authInfoAuthorizeRequest.setIdentityType("2");

  Map identityParams = new HashMap();

  identityParams.put("certNo", "61042619850403354X"); // 证件号码

  identityParams.put("name", "张三"); // 姓名

  identityParams.put("certType", "IDENTITY_CARD"); // 证件类型

  authInfoAuthorizeRequest.setIdentityParam(JSONObject.toJSonString(identityParams));

  DefaultZhimaClient client = new DefaultZhimaClient(URL, APPID, CHARSET, PRIKEY, PUBKEY);

  String pageAuthUrl = client.generatePageRedirectInvokeUrl(authInfoAuthorizeRequest);

  System.out.println(pageAuthUrl);

 }

 

 public void testZhimaCreditWatchlistGet() {

  ZhimaCreditScoreGetRequest req = new ZhimaCreditScoreGetRequest();

  req.setProductCode("w1010100100000000001");// 必要参数  

  req.setOpenId("268816231939676969685782895");// 必要参数  

  DefaultZhimaClient client = new DefaultZhimaClient(URL, APPID, CHARSET, PRIKEY, PUBKEY);

  try {

   // 如果正常返回,直接在对象里面获取结果值

   ZhimaCreditScoreGetResponse response = client.execute(req);

   System.out.println(JSON.toJSON(response));

  } catch (ZhimaApiException e) {

   e.printStackTrace();

  }

 }

 

 public static void parseFromReturnUrl(String url) throws Exception {

  int index = url.indexOf("");

  String urlParamString = url.substring(index + 1);

  String[] paraPairs = urlParamString.split("&");

  String encryptedParam = "";

  for (String paramPair : paraPairs) {

   String[] splits = paramPair.split("=");

   if ("params".equals(splits[0])) {

    encryptedParam = splits[1];

   }

  }

  String decryptedParam = RSACoderUtil.decrypt(URLDecoder.decode(encryptedParam, CHARSET),

   PRIKEY, CHARSET);

  //通过浏览器返回时,不需要decode

  System.out.println(URLDecoder.decode(decryptedParam, CHARSET));

  

 }

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持考高分网。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/139666.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号