2023-10-05 12:25:52 +08:00
|
|
|
package com.ruoyi.bestsign.utils;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import lombok.Data;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
2023-10-05 20:03:21 +08:00
|
|
|
import javax.validation.constraints.NotNull;
|
2023-10-05 12:25:52 +08:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 上上签混合云SDK客户端
|
|
|
|
|
*/
|
|
|
|
|
@Component
|
|
|
|
|
@Data
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class BestsignOpenApiClient {
|
|
|
|
|
/**
|
|
|
|
|
* 开发者id
|
|
|
|
|
*/
|
|
|
|
|
@Value("${ssq.developerId}")
|
|
|
|
|
private String developerId;
|
|
|
|
|
/**
|
|
|
|
|
* 开发者私钥
|
|
|
|
|
*/
|
2023-10-05 20:03:21 +08:00
|
|
|
// @Value("${ssq.privateKey}")
|
|
|
|
|
private String privateKey="MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCiDRuz+dxqkWqHdov0hK+KEWLw/e8MQSqkZZ4c01Yr6cSmQiWyV8Xin0u5S/EA02FWxpjLi1nLriVtOBhZGsoryFmcJrwzSnQ5PORP/HhfcAWFE/Y+3qSQS1OiU7e5wbReCgEUvx4GHZuhdu8cOvq5DG9l33YFZrIEMBTmnf8eKT54STx0tjcKl7U6B6nsiThy3zVtpWXVv6H1HGmxC0KT4EQ388s/PFjrwmk+GFb3EpKCns/GQHf7QrtNz1ZOgCXfgQiQ+91/tcngzUH+zMCIxn5lS+ENAxVI6Ev3W9Y0QHtKwmO4ORVuAskJYzBB2xKI/gw8+PUXNziMAKXuoUAjAgMBAAECggEAd7yHw6vTG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C1zE3BPOo29uAf9BQTumPxe51U64egttW/nif5FH4v4Gentmxb2B2ckdOs/u9zIWz3JPfHU7RqMyMokuWrQ6lMoiSYpH3MSHoavLyAEhAnpceX3oktXgpYHO9d8MfON3XKJl23ip";
|
2023-10-05 12:25:52 +08:00
|
|
|
/**
|
|
|
|
|
* Host地址
|
|
|
|
|
*/
|
|
|
|
|
@Value("${ssq.serverHost}")
|
|
|
|
|
private String serverHost;
|
2023-10-05 20:03:21 +08:00
|
|
|
/**
|
|
|
|
|
* 签名参数
|
|
|
|
|
*/
|
2023-10-05 12:25:52 +08:00
|
|
|
private static String urlSignParams = "?developerId=%s&rtick=%s&signType=rsa&sign=%s";
|
|
|
|
|
|
|
|
|
|
// public BestsignOpenApiClient(String developerId, String privateKey,
|
|
|
|
|
// String serverHost) {
|
|
|
|
|
// this.developerId = developerIds;
|
|
|
|
|
// this.privateKey = privateKey;
|
|
|
|
|
// this.serverHost = serverHost;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST方法示例
|
|
|
|
|
* 个人用户注册
|
|
|
|
|
*
|
|
|
|
|
* @param account 用户账号
|
|
|
|
|
* @param name 姓名
|
|
|
|
|
* @param mail 用来接收通知邮件的电子邮箱
|
|
|
|
|
* @param mobile 用来接收通知短信的手机号码
|
|
|
|
|
* @param identity 证件号码
|
|
|
|
|
* @param identityType 枚举值:0-身份证,目前仅支持身份证
|
|
|
|
|
* @param contactMail 电子邮箱
|
|
|
|
|
* @param contactMobile 手机号码
|
|
|
|
|
* @param province 省份
|
|
|
|
|
* @param city 城市
|
|
|
|
|
* @param address 地址
|
2023-10-05 20:03:21 +08:00
|
|
|
* @param method 地址
|
2023-10-05 12:25:52 +08:00
|
|
|
* @return 异步申请任务单号
|
|
|
|
|
* @throws IOException
|
|
|
|
|
*/
|
2023-10-05 20:03:21 +08:00
|
|
|
public JSONObject userPersonalReg(String account, String name, String mail,
|
2023-10-05 12:25:52 +08:00
|
|
|
String mobile, String identity, String identityType,
|
|
|
|
|
String contactMail, String contactMobile, String province,
|
2023-10-05 20:03:21 +08:00
|
|
|
String city, String address,@NotNull String method) throws Exception {
|
|
|
|
|
//body参数
|
2023-10-05 12:25:52 +08:00
|
|
|
JSONObject requestBody = new JSONObject();
|
|
|
|
|
|
2023-10-05 20:03:21 +08:00
|
|
|
//用户帐号
|
|
|
|
|
requestBody.put("account", account);
|
|
|
|
|
//用户名称
|
|
|
|
|
requestBody.put("name", name);
|
|
|
|
|
//用户类型
|
|
|
|
|
requestBody.put("userType", "1");
|
|
|
|
|
//用户邮箱
|
|
|
|
|
requestBody.put("mail",mail);
|
|
|
|
|
//用户手机号
|
|
|
|
|
requestBody.put("mobile", mobile);
|
|
|
|
|
//用户证件信息对象
|
2023-10-05 12:25:52 +08:00
|
|
|
JSONObject credential = new JSONObject();
|
2023-10-05 20:03:21 +08:00
|
|
|
//用户证件号
|
2023-10-05 12:25:52 +08:00
|
|
|
credential.put("identity", identity);
|
2023-10-05 20:03:21 +08:00
|
|
|
//用户证件类型
|
2023-10-05 12:25:52 +08:00
|
|
|
credential.put("identityType", identityType);
|
|
|
|
|
requestBody.put("credential", credential);
|
2023-10-05 20:03:21 +08:00
|
|
|
|
2023-10-05 12:25:52 +08:00
|
|
|
//是否申请证书
|
2023-10-05 20:03:21 +08:00
|
|
|
requestBody.put("applyCert", "1");
|
2023-10-05 12:25:52 +08:00
|
|
|
// 生成一个时间戳参数
|
|
|
|
|
String rtick = RSAUtils.getRtick();
|
|
|
|
|
// 计算参数签名
|
|
|
|
|
String paramsSign = RSAUtils.calcRsaSign(this.developerId,
|
|
|
|
|
this.privateKey, this.serverHost, method, rtick, null,
|
|
|
|
|
requestBody.toJSONString());
|
|
|
|
|
// 签名参数追加为url参数
|
|
|
|
|
String fullUrlParams = String.format(urlSignParams, this.developerId,
|
|
|
|
|
rtick, paramsSign);
|
|
|
|
|
|
|
|
|
|
// 发送POST请求
|
|
|
|
|
String responseBody = HttpClientSender.sendHttpPost(this.serverHost, method,
|
|
|
|
|
fullUrlParams, requestBody.toJSONString());
|
|
|
|
|
System.out.println(responseBody);
|
|
|
|
|
// 返回结果解析
|
|
|
|
|
JSONObject userObj = JSON.parseObject(responseBody);
|
2023-10-05 20:03:21 +08:00
|
|
|
System.out.println(JSON.toJSONString(userObj));
|
|
|
|
|
return userObj;
|
2023-10-05 12:25:52 +08:00
|
|
|
// 返回errno为0,表示成功,其他表示失败
|
2023-10-05 20:03:21 +08:00
|
|
|
// if (userObj.getIntValue("errno") == 0) {
|
|
|
|
|
// JSONObject data = userObj.getJSONObject("data");
|
|
|
|
|
// if (data != null) {
|
|
|
|
|
// //对返回data进行处理
|
|
|
|
|
// String taskId = data.getString("taskId");
|
|
|
|
|
// return taskId;
|
|
|
|
|
// }
|
|
|
|
|
// return null;
|
|
|
|
|
// } else {
|
|
|
|
|
// //接口返回异常
|
|
|
|
|
// System.out.println(userObj.getIntValue("errno"));
|
|
|
|
|
// System.out.println(userObj.getString("errmsg"));
|
|
|
|
|
// throw new Exception(userObj.getIntValue("errno") + ":"
|
|
|
|
|
// + userObj.getString("errmsg"));
|
|
|
|
|
// }
|
2023-10-05 12:25:52 +08:00
|
|
|
}
|
|
|
|
|
|
2023-10-05 20:19:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-10-05 12:25:52 +08:00
|
|
|
/**
|
|
|
|
|
* GET方法示例
|
|
|
|
|
* 下载合同PDF文件
|
|
|
|
|
*
|
|
|
|
|
* @param contractId 合同编号
|
|
|
|
|
* @return
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public byte[] contractDownload(String contractId) throws Exception {
|
|
|
|
|
String host = this.serverHost;
|
|
|
|
|
String method = "/storage/contract/download/";
|
|
|
|
|
|
|
|
|
|
// 组装url参数
|
|
|
|
|
String urlParams = "contractId=" + contractId;
|
|
|
|
|
|
|
|
|
|
// 生成一个时间戳参数
|
|
|
|
|
String rtick = RSAUtils.getRtick();
|
|
|
|
|
// 计算参数签名
|
|
|
|
|
String paramsSign = RSAUtils.calcRsaSign(this.developerId,
|
|
|
|
|
this.privateKey, host, method, rtick, urlParams, null);
|
|
|
|
|
// 签名参数追加为url参数
|
|
|
|
|
urlParams = String.format(urlSignParams, this.developerId, rtick,
|
|
|
|
|
paramsSign) + "&" + urlParams;
|
|
|
|
|
// 发送请求
|
|
|
|
|
byte[] responseBody = HttpClientSender.sendHttpGet(host, method,
|
|
|
|
|
urlParams);
|
|
|
|
|
// 返回结果解析
|
|
|
|
|
return responseBody;
|
|
|
|
|
}
|
2023-10-05 20:19:57 +08:00
|
|
|
|
|
|
|
|
public String selectApplyStatus(String account, String taskId) throws Exception {
|
|
|
|
|
String methodInvoke = "/user/async/applyCert/status/";
|
|
|
|
|
JSONObject requestParam = new JSONObject();
|
|
|
|
|
|
|
|
|
|
//用户账号
|
|
|
|
|
requestParam.put("account", account);
|
|
|
|
|
//任务单号
|
|
|
|
|
requestParam.put("taskId", taskId);
|
|
|
|
|
String timestamsParam = RSAUtils.getRtick();
|
|
|
|
|
// 计算参数签名
|
|
|
|
|
String paramsSign = RSAUtils.calcRsaSign(this.developerId,
|
|
|
|
|
this.privateKey, this.serverHost, methodInvoke, timestamsParam, null,
|
|
|
|
|
requestParam.toJSONString());
|
|
|
|
|
// 签名参数追加为url参数
|
|
|
|
|
String fullUrlParams = String.format(this.urlSignParams, this.developerId,
|
|
|
|
|
timestamsParam, paramsSign);
|
|
|
|
|
|
|
|
|
|
String responseResult = HttpClientSender.sendHttpPost(this.serverHost, methodInvoke,
|
|
|
|
|
fullUrlParams, requestParam.toJSONString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JSONObject responseObj = JSON.parseObject(responseResult);
|
|
|
|
|
// 返回errno为0,表示成功,其他表示失败
|
|
|
|
|
if (responseObj.getIntValue("errno") == 0) {
|
|
|
|
|
JSONObject data = responseObj.getJSONObject("data");
|
|
|
|
|
if (data != null) {
|
|
|
|
|
String message = data.getString("message");
|
|
|
|
|
String status = data.getString("status");
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
log.error("查询申请状态异常:"+responseObj.toJSONString());
|
|
|
|
|
}
|
|
|
|
|
return responseObj.toJSONString();
|
|
|
|
|
}
|
2023-10-05 12:25:52 +08:00
|
|
|
}
|