智能仲裁后端服务

BestsignOpenApiClient.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. package com.ruoyi.bestsign.utils;
  2. import com.alibaba.fastjson.JSON;
  3. import com.alibaba.fastjson.JSONObject;
  4. import lombok.Data;
  5. import lombok.extern.slf4j.Slf4j;
  6. import org.springframework.beans.factory.annotation.Value;
  7. import org.springframework.stereotype.Component;
  8. import java.io.IOException;
  9. /**
  10. * 上上签混合云SDK客户端
  11. */
  12. @Component
  13. @Data
  14. @Slf4j
  15. public class BestsignOpenApiClient {
  16. /**
  17. * 开发者id
  18. */
  19. @Value("${ssq.developerId}")
  20. private String developerId;
  21. /**
  22. * 开发者私钥
  23. */
  24. @Value("${ssq.privateKey}")
  25. private String privateKey;
  26. /**
  27. * Host地址
  28. */
  29. @Value("${ssq.serverHost}")
  30. private String serverHost;
  31. private static String urlSignParams = "?developerId=%s&rtick=%s&signType=rsa&sign=%s";
  32. // public BestsignOpenApiClient(String developerId, String privateKey,
  33. // String serverHost) {
  34. // this.developerId = developerIds;
  35. // this.privateKey = privateKey;
  36. // this.serverHost = serverHost;
  37. // }
  38. /**
  39. * POST方法示例
  40. * 个人用户注册
  41. *
  42. * @param account 用户账号
  43. * @param name 姓名
  44. * @param mail 用来接收通知邮件的电子邮箱
  45. * @param mobile 用来接收通知短信的手机号码
  46. * @param identity 证件号码
  47. * @param identityType 枚举值:0-身份证,目前仅支持身份证
  48. * @param contactMail 电子邮箱
  49. * @param contactMobile 手机号码
  50. * @param province 省份
  51. * @param city 城市
  52. * @param address 地址
  53. * @return 异步申请任务单号
  54. * @throws IOException
  55. */
  56. public String userPersonalReg(String account, String name, String mail,
  57. String mobile, String identity, String identityType,
  58. String contactMail, String contactMobile, String province,
  59. String city, String address) throws Exception {
  60. String host = this.serverHost;
  61. String method = "/user/reg/";
  62. // 组装请求参数,作为requestbody
  63. JSONObject requestBody = new JSONObject();
  64. requestBody.put("account", account);
  65. requestBody.put("name", name);
  66. requestBody.put("userType", "1");
  67. requestBody.put("mail", mail);
  68. requestBody.put("mobile", mobile);
  69. JSONObject credential = new JSONObject();
  70. credential.put("identity", identity);
  71. credential.put("identityType", identityType);
  72. credential.put("contactMail", contactMail);
  73. credential.put("contactMobile", contactMobile);
  74. credential.put("province", province);
  75. credential.put("city", city);
  76. credential.put("address", address);
  77. requestBody.put("credential", credential);
  78. //是否申请证书
  79. requestBody.put("applyCert", "2");
  80. // 生成一个时间戳参数
  81. String rtick = RSAUtils.getRtick();
  82. // 计算参数签名
  83. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  84. this.privateKey, this.serverHost, method, rtick, null,
  85. requestBody.toJSONString());
  86. // 签名参数追加为url参数
  87. String fullUrlParams = String.format(urlSignParams, this.developerId,
  88. rtick, paramsSign);
  89. // 发送POST请求
  90. String responseBody = HttpClientSender.sendHttpPost(this.serverHost, method,
  91. fullUrlParams, requestBody.toJSONString());
  92. System.out.println(responseBody);
  93. // 返回结果解析
  94. JSONObject userObj = JSON.parseObject(responseBody);
  95. // 返回errno为0,表示成功,其他表示失败
  96. if (userObj.getIntValue("errno") == 0) {
  97. JSONObject data = userObj.getJSONObject("data");
  98. if (data != null) {
  99. //对返回data进行处理
  100. String taskId = data.getString("taskId");
  101. return taskId;
  102. }
  103. } else {
  104. //接口返回异常
  105. System.out.println(userObj.getIntValue("errno"));
  106. System.out.println(userObj.getString("errmsg"));
  107. }
  108. return userObj.toJSONString();
  109. }
  110. /**
  111. * GET方法示例
  112. * 下载合同PDF文件
  113. *
  114. * @param contractId 合同编号
  115. * @return
  116. * @throws Exception
  117. */
  118. public byte[] contractDownload(String contractId) throws Exception {
  119. String host = this.serverHost;
  120. String method = "/storage/contract/download/";
  121. // 组装url参数
  122. String urlParams = "contractId=" + contractId;
  123. // 生成一个时间戳参数
  124. String rtick = RSAUtils.getRtick();
  125. // 计算参数签名
  126. String paramsSign = RSAUtils.calcRsaSign(this.developerId,
  127. this.privateKey, host, method, rtick, urlParams, null);
  128. // 签名参数追加为url参数
  129. urlParams = String.format(urlSignParams, this.developerId, rtick,
  130. paramsSign) + "&" + urlParams;
  131. // 发送请求
  132. byte[] responseBody = HttpClientSender.sendHttpGet(host, method,
  133. urlParams);
  134. // 返回结果解析
  135. return responseBody;
  136. }
  137. }