api.go 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. package asign
  2. import (
  3. "encoding/json"
  4. "mtp2_if/config"
  5. "mtp2_if/logger"
  6. "github.com/fatih/structs"
  7. )
  8. // APIPersonBankCard4 个人银行卡四要素认证
  9. func APIPersonBankCard4(req APIPersonBankCard4Req) (rsp *APIRsp[APIBankCard4Rsp], err error) {
  10. apiUrl := config.SerCfg.AsignCfg.Url + "/auth/person/bankCard4"
  11. reqMap := structs.Map(req)
  12. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  13. rspBody, err := HttpPost(apiUrl, reqMap)
  14. if err != nil {
  15. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  16. return
  17. }
  18. rspStr := string(rspBody)
  19. if len(rspStr) == 0 {
  20. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  21. return
  22. }
  23. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  24. rsp = new(APIRsp[APIBankCard4Rsp])
  25. err = json.Unmarshal(rspBody, rsp)
  26. return
  27. }
  28. // APICompanyBankCard4 企业法人银行卡四要素认证
  29. func APICompanyBankCard4(req APICompanyBankCard4Req) (rsp *APIRsp[APIBankCard4Rsp], err error) {
  30. apiUrl := config.SerCfg.AsignCfg.Url + "/auth/company/bankCard4"
  31. reqMap := structs.Map(req)
  32. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  33. rspBody, err := HttpPost(apiUrl, reqMap)
  34. if err != nil {
  35. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  36. return
  37. }
  38. rspStr := string(rspBody)
  39. if len(rspStr) == 0 {
  40. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  41. return
  42. }
  43. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  44. rsp = new(APIRsp[APIBankCard4Rsp])
  45. err = json.Unmarshal(rspBody, rsp)
  46. return
  47. }
  48. // APICaptchaVerify 认证验证码校验
  49. func APICaptchaResend(req APICaptchaResendReq) (rsp *APIRsp[interface{}], err error) {
  50. apiUrl := config.SerCfg.AsignCfg.Url + "/auth/captcha/resend"
  51. reqMap := structs.Map(req)
  52. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  53. rspBody, err := HttpPost(apiUrl, reqMap)
  54. if err != nil {
  55. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  56. return
  57. }
  58. rspStr := string(rspBody)
  59. if len(rspStr) == 0 {
  60. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  61. return
  62. }
  63. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  64. rsp = new(APIRsp[interface{}])
  65. err = json.Unmarshal(rspBody, rsp)
  66. return
  67. }
  68. // APICaptchaVerify 认证验证码校验
  69. func APICaptchaVerify(req APICaptchaVerifyReq) (rsp *APIRsp[APICaptchaVerifyRsp], err error) {
  70. apiUrl := config.SerCfg.AsignCfg.Url + "/auth/captcha/verify"
  71. reqMap := structs.Map(req)
  72. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  73. rspBody, err := HttpPost(apiUrl, reqMap)
  74. if err != nil {
  75. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  76. return
  77. }
  78. rspStr := string(rspBody)
  79. if len(rspStr) == 0 {
  80. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  81. return
  82. }
  83. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  84. rsp = new(APIRsp[APICaptchaVerifyRsp])
  85. err = json.Unmarshal(rspBody, rsp)
  86. return
  87. }
  88. // APIGetUser 查询用户信息
  89. func APIGetUser(req APIGetUserReq) (rsp *APIRsp[[]APIGetUserRsp], err error) {
  90. apiUrl := config.SerCfg.AsignCfg.Url + "/user/getUser"
  91. reqMap := structs.Map(req)
  92. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  93. rspBody, err := HttpPost(apiUrl, reqMap)
  94. if err != nil {
  95. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  96. return
  97. }
  98. rspStr := string(rspBody)
  99. if len(rspStr) == 0 {
  100. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  101. return
  102. }
  103. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  104. rsp = new(APIRsp[[]APIGetUserRsp])
  105. err = json.Unmarshal(rspBody, rsp)
  106. return
  107. }
  108. // APIAddPersonalUser 添加个人用户(V2)
  109. func APIAddPersonalUser(req APIAddPersonalUserReq) (rsp *APIRsp[APIAddUserRsp], err error) {
  110. apiUrl := config.SerCfg.AsignCfg.Url + "/v2/user/addPersonalUser"
  111. reqMap := structs.Map(req)
  112. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  113. rspBody, err := HttpPost(apiUrl, reqMap)
  114. if err != nil {
  115. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  116. return
  117. }
  118. rspStr := string(rspBody)
  119. if len(rspStr) == 0 {
  120. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  121. return
  122. }
  123. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  124. rsp = new(APIRsp[APIAddUserRsp])
  125. err = json.Unmarshal(rspBody, rsp)
  126. return
  127. }
  128. // APIAddEnterpriseUser 添加企业用户(V2)
  129. func APIAddEnterpriseUser(req APIAddEnterpriseUserReq) (rsp *APIRsp[APIAddUserRsp], err error) {
  130. apiUrl := config.SerCfg.AsignCfg.Url + "/v2/user/addEnterpriseUser"
  131. reqMap := structs.Map(req)
  132. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  133. rspBody, err := HttpPost(apiUrl, reqMap)
  134. if err != nil {
  135. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  136. return
  137. }
  138. rspStr := string(rspBody)
  139. if len(rspStr) == 0 {
  140. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  141. return
  142. }
  143. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  144. rsp = new(APIRsp[APIAddUserRsp])
  145. err = json.Unmarshal(rspBody, rsp)
  146. return
  147. }
  148. // APITemplateList 查询模板列表
  149. func APITemplateList(req APITemplateListReq) (rsp *APIRsp[APITemplateListRsp], err error) {
  150. apiUrl := config.SerCfg.AsignCfg.Url + "/template/list"
  151. reqMap := structs.Map(req)
  152. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  153. rspBody, err := HttpPost(apiUrl, reqMap)
  154. if err != nil {
  155. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  156. return
  157. }
  158. rspStr := string(rspBody)
  159. if len(rspStr) == 0 {
  160. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  161. return
  162. }
  163. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  164. rsp = new(APIRsp[APITemplateListRsp])
  165. err = json.Unmarshal(rspBody, rsp)
  166. return
  167. }
  168. // APICreateContract 上传待签署文件
  169. func APICreateContract(req APICreateContractReq) (rsp *APIRsp[APICreateContractRsp], err error) {
  170. apiUrl := config.SerCfg.AsignCfg.Url + "/contract/createContract"
  171. reqMap := structs.Map(req)
  172. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  173. rspBody, err := HttpPost(apiUrl, reqMap)
  174. if err != nil {
  175. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  176. return
  177. }
  178. rspStr := string(rspBody)
  179. if len(rspStr) == 0 {
  180. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  181. return
  182. }
  183. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  184. rsp = new(APIRsp[APICreateContractRsp])
  185. err = json.Unmarshal(rspBody, rsp)
  186. return
  187. }
  188. // APIAddSigner 添加签署方
  189. func APIAddSigner(req []APIAddSignerReq) (rsp *APIRsp[APIAddSignerRsp], err error) {
  190. apiUrl := config.SerCfg.AsignCfg.Url + "/contract/addSigner"
  191. reqArray := make([]map[string]interface{}, 0)
  192. for _, item := range req {
  193. reqArray = append(reqArray, structs.Map(item))
  194. }
  195. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqArray)
  196. rspBody, err := HttpPost2(apiUrl, reqArray)
  197. if err != nil {
  198. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  199. return
  200. }
  201. rspStr := string(rspBody)
  202. if len(rspStr) == 0 {
  203. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  204. return
  205. }
  206. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  207. rsp = new(APIRsp[APIAddSignerRsp])
  208. err = json.Unmarshal(rspBody, rsp)
  209. return
  210. }
  211. // APIContractStatus 查询合同状态
  212. func APIContractStatus(req APIContractStatusReq) (rsp *APIRsp[APIContractStatusRsp], err error) {
  213. apiUrl := config.SerCfg.AsignCfg.Url + "/contract/status"
  214. reqMap := structs.Map(req)
  215. logger.GetLogger().Info("调用接口 "+apiUrl+" 请求, request:", reqMap)
  216. rspBody, err := HttpPost(apiUrl, reqMap)
  217. if err != nil {
  218. logger.GetLogger().Error("调用接口 "+apiUrl+" 错误, error:", err.Error())
  219. return
  220. }
  221. rspStr := string(rspBody)
  222. if len(rspStr) == 0 {
  223. logger.GetLogger().Error("调用接口 " + apiUrl + " 错误, response为空")
  224. return
  225. }
  226. logger.GetLogger().Info("调用接口 "+apiUrl+" 返回, response:", rspStr)
  227. rsp = new(APIRsp[APIContractStatusRsp])
  228. err = json.Unmarshal(rspBody, rsp)
  229. return
  230. }