智能仲裁后端服务

BestsignOpenApiClient.java 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. package com.ruoyi.bestsign.utils;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import com.ruoyi.bestsign.domain.ArbitrSignatuVO;
  6. import lombok.Data;
  7. import lombok.extern.slf4j.Slf4j;
  8. import org.springframework.beans.factory.annotation.Value;
  9. import org.springframework.stereotype.Component;
  10. import javax.validation.constraints.NotNull;
  11. import java.io.IOException;
  12. /**
  13. * 上上签混合云SDK客户端
  14. */
  15. @Component
  16. @Data
  17. @Slf4j
  18. public class BestsignOpenApiClient {
  19. /**
  20. * 开发者id
  21. */
  22. @Value("${ssq.developerId}")
  23. private String developerId;
  24. /**
  25. * 开发者私钥
  26. */
  27. @Value("${ssq.privateKey}")
  28. private String privateKey;
  29. /**
  30. * Host地址
  31. */
  32. @Value("${ssq.serverHost}")
  33. private String serverHost;
  34. /**
  35. * 签名参数
  36. */
  37. private static String urlSignParams = "?developerId=%s&rtick=%s&signType=rsa&sign=%s";
  38. // public BestsignOpenApiClient(String developerId, String privateKey,
  39. // String serverHost) {
  40. // this.developerId = developerIds;
  41. // this.privateKey = privateKey;
  42. // this.serverHost = serverHost;
  43. // }
  44. /**
  45. * POST方法示例
  46. * 个人用户注册
  47. *
  48. * @param account 用户账号
  49. * @param name 姓名
  50. * @param mail 用来接收通知邮件的电子邮箱
  51. * @param mobile 用来接收通知短信的手机号码
  52. * @param identity 证件号码
  53. * @param identityType 枚举值:0-身份证,目前仅支持身份证
  54. * @param contactMail 电子邮箱
  55. * @param contactMobile 手机号码
  56. * @param province 省份
  57. * @param city 城市
  58. * @param address 地址
  59. * @param method 地址
  60. * @return 异步申请任务单号
  61. * @throws IOException
  62. */
  63. public JSONObject userPersonalReg(String account, String name, String mail,
  64. String mobile, String identity, String identityType,
  65. String contactMail, String contactMobile, String province,
  66. String city, String address, @NotNull String method) throws Exception {
  67. //body参数
  68. JSONObject requestBody = new JSONObject();
  69. //用户帐号
  70. requestBody.put("account", account);
  71. //用户名称
  72. requestBody.put("name", name);
  73. //用户类型
  74. requestBody.put("userType", "1");
  75. //用户邮箱
  76. requestBody.put("mail", mail);
  77. //用户手机号
  78. requestBody.put("mobile", mobile);
  79. //用户证件信息对象
  80. JSONObject credential = new JSONObject();
  81. //用户证件号
  82. credential.put("identity", identity);
  83. //用户证件类型
  84. credential.put("identityType", identityType);
  85. requestBody.put("credential", credential);
  86. //是否申请证书
  87. requestBody.put("applyCert", "1");
  88. // 生成一个时间戳参数
  89. String rtick = RSAUtils.getRtick();
  90. // 计算参数签名
  91. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  92. this.privateKey, this.serverHost, method, rtick, null,
  93. requestBody.toJSONString());
  94. // 签名参数追加为url参数
  95. String fullUrlParams = String.format(urlSignParams, this.developerId,
  96. rtick, paramsSign);
  97. // 发送POST请求
  98. String responseBody = HttpClientSender.sendHttpPost(this.serverHost, method,
  99. fullUrlParams, requestBody.toJSONString());
  100. System.out.println(responseBody);
  101. // 返回结果解析
  102. JSONObject userObj = JSON.parseObject(responseBody);
  103. System.out.println(JSON.toJSONString(userObj));
  104. return userObj;
  105. // 返回errno为0,表示成功,其他表示失败
  106. // if (userObj.getIntValue("errno") == 0) {
  107. // JSONObject data = userObj.getJSONObject("data");
  108. // if (data != null) {
  109. // //对返回data进行处理
  110. // String taskId = data.getString("taskId");
  111. // return taskId;
  112. // }
  113. // return null;
  114. // } else {
  115. // //接口返回异常
  116. // System.out.println(userObj.getIntValue("errno"));
  117. // System.out.println(userObj.getString("errmsg"));
  118. // throw new Exception(userObj.getIntValue("errno") + ":"
  119. // + userObj.getString("errmsg"));
  120. // }
  121. }
  122. /**
  123. * GET方法示例
  124. * 下载合同PDF文件
  125. *
  126. * @param contractId 合同编号
  127. * @return
  128. * @throws Exception
  129. */
  130. public byte[] contractDownload(String contractId) throws Exception {
  131. String host = this.serverHost;
  132. String method = "/storage/contract/download/";
  133. // 组装url参数
  134. String urlParams = "contractId=" + contractId;
  135. // 生成一个时间戳参数
  136. String rtick = RSAUtils.getRtick();
  137. // 计算参数签名
  138. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  139. this.privateKey, host, method, rtick, urlParams, null);
  140. // 签名参数追加为url参数
  141. urlParams = String.format(urlSignParams, this.developerId, rtick,
  142. paramsSign) + "&" + urlParams;
  143. // 发送请求
  144. byte[] responseBody = HttpClientSender.sendHttpGet(host, method,
  145. urlParams);
  146. // 返回结果解析
  147. return responseBody;
  148. }
  149. public String selectApplyStatus(String account, String taskId) throws Exception {
  150. String methodInvoke = "/user/async/applyCert/status/";
  151. JSONObject requestParam = new JSONObject();
  152. //用户账号
  153. requestParam.put("account", account);
  154. //任务单号
  155. requestParam.put("taskId", taskId);
  156. String timestamsParam = RSAUtils.getRtick();
  157. // 计算参数签名
  158. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  159. this.privateKey, this.serverHost, methodInvoke, timestamsParam, null,
  160. requestParam.toJSONString());
  161. // 签名参数追加为url参数
  162. String fullUrlParams = String.format(urlSignParams, this.developerId,
  163. timestamsParam, paramsSign);
  164. String responseResult = HttpClientSender.sendHttpPost(this.serverHost, methodInvoke,
  165. fullUrlParams, requestParam.toJSONString());
  166. JSONObject responseObj = JSON.parseObject(responseResult);
  167. // 返回errno为0,表示成功,其他表示失败
  168. if (responseObj.getIntValue("errno") == 0) {
  169. JSONObject data = responseObj.getJSONObject("data");
  170. if (data != null) {
  171. String message = data.getString("message");
  172. String status = data.getString("status");
  173. return status;
  174. }
  175. } else {
  176. log.error("查询申请状态异常:" + responseObj.toJSONString());
  177. }
  178. return responseObj.toJSONString();
  179. }
  180. /**
  181. * 获取签署链接
  182. *
  183. * @param arbitrSignatuVO
  184. * @return
  185. * @throws Exception
  186. */
  187. public String getSignLink(ArbitrSignatuVO arbitrSignatuVO) throws Exception {
  188. String methodInvoke = "/contract/send/";
  189. JSONObject requestParam = new JSONObject();
  190. requestParam.put("contractId", arbitrSignatuVO.getContractNum());
  191. requestParam.put("signer", arbitrSignatuVO.getSignerAccout());
  192. JSONArray signatureArray = new JSONArray();
  193. JSONObject signatuItem = new JSONObject();
  194. signatuItem.put("pageNum", arbitrSignatuVO.getPageNumSigner());
  195. //x坐标
  196. signatuItem.put("x", arbitrSignatuVO.getPageNumSignerX());
  197. //y坐标
  198. signatuItem.put("y", arbitrSignatuVO.getPageNumSignerY());
  199. signatureArray.add(signatuItem);
  200. requestParam.put("signaturePositions", signatureArray);
  201. String timestamsParam = RSAUtils.getRtick();
  202. // 计算参数签名
  203. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  204. this.privateKey, this.serverHost, methodInvoke, timestamsParam, null,
  205. requestParam.toJSONString());
  206. // 签名参数追加为url参数
  207. String fullUrlParams = String.format(urlSignParams, this.developerId,
  208. timestamsParam, paramsSign);
  209. String responseResult = HttpClientSender.sendHttpPost(this.serverHost, methodInvoke,
  210. fullUrlParams, requestParam.toJSONString());
  211. JSONObject responseObj = JSON.parseObject(responseResult);
  212. // 返回errno为0,表示成功,其他表示失败
  213. if (responseObj.getIntValue("errno") == 0) {
  214. JSONObject data = responseObj.getJSONObject("data");
  215. if (data != null) {
  216. String signLink = data.getString("url");
  217. return signLink;
  218. }
  219. } else {
  220. log.error("获取签署链接异常:" + responseObj.toJSONString());
  221. }
  222. return responseObj.toJSONString();
  223. }
  224. /**
  225. * 完成签署
  226. *
  227. * @param arbitrSignatuVO
  228. * @return
  229. * @throws Exception
  230. */
  231. public String finishSign(ArbitrSignatuVO arbitrSignatuVO) throws Exception {
  232. String methodInvoke = "/storage/contract/lock/";
  233. JSONObject requestParam = new JSONObject();
  234. requestParam.put("contractId", arbitrSignatuVO.getContractNum());
  235. String timestamsParam = RSAUtils.getRtick();
  236. // 计算参数签名
  237. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  238. this.privateKey, this.serverHost, methodInvoke, timestamsParam, null,
  239. requestParam.toJSONString());
  240. // 签名参数追加为url参数
  241. String fullUrlParams = String.format(urlSignParams, this.developerId,
  242. timestamsParam, paramsSign);
  243. String responseResult = HttpClientSender.sendHttpPost(this.serverHost, methodInvoke,
  244. fullUrlParams, requestParam.toJSONString());
  245. JSONObject responseObj = JSON.parseObject(responseResult);
  246. // 返回errno为0,表示成功,其他表示失败
  247. if (responseObj.getIntValue("errno") == 0) {
  248. return "完成签名";
  249. } else {
  250. log.error("完成签署异常:" + responseObj.toJSONString());
  251. }
  252. return responseObj.toJSONString();
  253. }
  254. }