certification.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. package account
  2. import (
  3. "errors"
  4. "mtp20access/global"
  5. "mtp20access/model/account/request"
  6. "mtp20access/model/common/response"
  7. signService "mtp20access/service/sign"
  8. "mtp20access/utils"
  9. "net/http"
  10. "net/url"
  11. "github.com/gin-gonic/gin"
  12. "go.uber.org/zap"
  13. )
  14. // QueryUserESignRecord 查询用户电子签记录表
  15. // @Summary 查询用户电子签记录表
  16. // @Security ApiKeyAuth
  17. // @accept application/json
  18. // @Produce application/json
  19. // @Success 200 {object} response.Response{data=[]account.Useresignrecord,msg=string} "出参"
  20. // @Router /Account/QueryUserESignRecord [get]
  21. // @Tags 账户服务
  22. func QueryUserESignRecord(c *gin.Context) {
  23. g := utils.GinUtils{C: c}
  24. // 获取请求账号信息
  25. claims := g.GetClaims()
  26. if g.Err != nil {
  27. return
  28. }
  29. if rsp, err := signService.QueryUserESignRecord(claims.UserID); err == nil {
  30. response.OkWithDetailed(rsp, "查询成功", g.C)
  31. } else {
  32. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  33. response.FailWithMessage(err.Error(), c)
  34. }
  35. }
  36. // AddUser 实名认证添加用户
  37. // @Summary 实名认证添加用户
  38. // @Security ApiKeyAuth
  39. // @accept application/json
  40. // @Produce application/json
  41. // @Param data body request.AddUserReq true "入参"
  42. // @Success 200 {object} response.Response{msg=string} "出参"
  43. // @Router /Account/AddUser [post]
  44. // @Tags 账户服务
  45. func AddUser(c *gin.Context) {
  46. g := utils.GinUtils{C: c}
  47. r := request.AddUserReq{}
  48. g.BindJsonReq(&r)
  49. if g.Err != nil {
  50. return
  51. }
  52. // 获取请求账号信息
  53. claims := g.GetClaims()
  54. if g.Err != nil {
  55. return
  56. }
  57. if err := signService.AddUser(r, claims.UserID); err == nil {
  58. response.Ok(g.C)
  59. } else {
  60. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  61. response.FailWithMessage(err.Error(), c)
  62. }
  63. }
  64. // CreateContractAndAddSigner 上传待签署文件和添加签署方
  65. // @Summary 上传待签署文件和添加签署方
  66. // @Security ApiKeyAuth
  67. // @accept application/json
  68. // @Produce application/json
  69. // @Param data body request.CreateContractAndAddSignerReq true "入参"
  70. // @Success 200 {object} response.Response{data=string,msg=string} "出参"
  71. // @Router /Account/CreateContractAndAddSigner [post]
  72. // @Tags 账户服务
  73. func CreateContractAndAddSigner(c *gin.Context) {
  74. g := utils.GinUtils{C: c}
  75. r := request.CreateContractAndAddSignerReq{}
  76. g.BindJsonReq(&r)
  77. if g.Err != nil {
  78. return
  79. }
  80. // 获取请求账号信息
  81. claims := g.GetClaims()
  82. if g.Err != nil {
  83. return
  84. }
  85. if rsp, err := signService.CreateContractAndAddSigner(r, claims.UserID); err == nil {
  86. response.OkWithDetailed(rsp, "操作成功", g.C)
  87. } else {
  88. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  89. response.FailWithMessage(err.Error(), c)
  90. }
  91. }
  92. // SignCompleted 提交实名认证
  93. // @Summary 提交实名认证
  94. // @Security ApiKeyAuth
  95. // @accept application/json
  96. // @Produce application/json
  97. // @Success 200 {object} response.Response{msg=string} "出参"
  98. // @Router /Account/SignCompleted [post]
  99. // @Tags 账户服务
  100. func SignCompleted(c *gin.Context) {
  101. g := utils.GinUtils{C: c}
  102. // 获取请求账号信息
  103. claims := g.GetClaims()
  104. if g.Err != nil {
  105. return
  106. }
  107. if err := signService.SignCompleted(claims.UserID); err == nil {
  108. response.OkWithMessage("提交成功", g.C)
  109. } else {
  110. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  111. response.FailWithMessage(err.Error(), c)
  112. }
  113. }
  114. // 爱签合同签署完成后异步通知 POST
  115. func HandleASignCompleted(c *gin.Context) {
  116. g := utils.GinUtils{C: c}
  117. // global.M2A_LOG.Info("[HandleASignCompleted] 接收爱签爱签合同签署完成后异步通知", zap.Any("url", g.C.Request.URL))
  118. action, ok := g.C.GetPostForm("action")
  119. if !ok {
  120. err := errors.New("[HandleASignCompleted] 获取action失败")
  121. response.FailWithMessage(err.Error(), c)
  122. return
  123. }
  124. contractNo, ok := g.C.GetPostForm("contractNo")
  125. if !ok {
  126. err := errors.New("[HandleASignCompleted] 获取contractNo失败")
  127. response.FailWithMessage(err.Error(), c)
  128. return
  129. }
  130. status, ok := g.C.GetPostForm("status")
  131. if !ok {
  132. err := errors.New("[HandleASignCompleted] 获取status失败")
  133. response.FailWithMessage(err.Error(), c)
  134. return
  135. }
  136. if action == "signCompleted" {
  137. if err := signService.HandleASignCompleted(contractNo, status); err == nil {
  138. g.C.String(http.StatusOK, "%s", "ok")
  139. } else {
  140. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  141. response.FailWithMessage(err.Error(), c)
  142. }
  143. } else {
  144. err := errors.New("[HandleASignCompleted] 暂不支持的action")
  145. response.FailWithMessage(err.Error(), c)
  146. }
  147. }
  148. // WillFace 个人意愿核身认证
  149. // @Summary 个人意愿核身认证
  150. // @Security ApiKeyAuth
  151. // @accept application/json
  152. // @Produce application/json
  153. // @Param data body request.WillFaceReq true "入参"
  154. // @Success 200 {object} response.Response{data=string,msg=string} "出参"
  155. // @Router /Account/WillFace [post]
  156. // @Tags 账户服务
  157. func WillFace(c *gin.Context) {
  158. g := utils.GinUtils{C: c}
  159. r := request.WillFaceReq{}
  160. g.BindJsonReq(&r)
  161. if g.Err != nil {
  162. return
  163. }
  164. // 获取请求账号信息
  165. claims := g.GetClaims()
  166. if g.Err != nil {
  167. return
  168. }
  169. if rsp, err := signService.WillFace(r, claims.UserID); err == nil {
  170. response.OkWithDetailed(rsp, "操作成功", g.C)
  171. } else {
  172. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  173. response.FailWithMessage(err.Error(), c)
  174. }
  175. }
  176. // 爱签个人意愿核身认证接口异步通知 GET
  177. func HandleWillFace(c *gin.Context) {
  178. g := utils.GinUtils{C: c}
  179. global.M2A_LOG.Info("[HandleWillFace] 接收爱签个人意愿核身认证接口异步通知", zap.Any("url", g.C.Request.URL))
  180. sign := g.C.Query("sign")
  181. result := g.C.Query("result")
  182. msg := g.C.Query("msg")
  183. recordId := g.C.Query("recordId")
  184. if sign == "" || result == "" || msg == "" || recordId == "" {
  185. g.C.String(http.StatusOK, "提交信息失败,请关闭此页面稍后重试")
  186. return
  187. }
  188. if result != "1" {
  189. // 认证失败
  190. t, _ := url.QueryUnescape(msg)
  191. if t == "" {
  192. t = "提交信息失败,请关闭此页面稍后重试."
  193. }
  194. g.C.String(http.StatusOK, t)
  195. return
  196. }
  197. if err := signService.HandleWillFace(sign, result, msg, recordId); err == nil {
  198. g.C.String(http.StatusOK, "提交信息成功,请关闭此页面")
  199. } else {
  200. global.M2A_LOG.Error(err.Error(), zap.Error(err))
  201. // response.FailWithMessage(err.Error(), c)
  202. g.C.String(http.StatusOK, "提交信息失败,请关闭此页面稍后重试")
  203. }
  204. }