zhou.xiaoning 2 роки тому
батько
коміт
d2cfee14bb

+ 16 - 10
api/v1/account/certification.go

@@ -6,6 +6,7 @@ import (
 	"mtp20access/model/common/response"
 	signService "mtp20access/service/sign"
 	"mtp20access/utils"
+	"net/http"
 
 	"github.com/gin-gonic/gin"
 	"go.uber.org/zap"
@@ -124,13 +125,18 @@ func SignCompleted(c *gin.Context) {
 }
 
 // POST
-// func HandleASignCompleted(c *gin.Context) {
-// 	g := utils.GinUtils{C: c}
-
-// 	if rsp, err := signService.HandleASignCompleted(); err == nil {
-// 		response.OkWithDetailed(rsp, "操作成功", g.C)
-// 	} else {
-// 		global.M2A_LOG.Error(err.Error(), zap.Error(err))
-// 		response.FailWithMessage(err.Error(), c)
-// 	}
-// }
+func HandleASignCompleted(c *gin.Context) {
+	g := utils.GinUtils{C: c}
+	r := request.HandleASignCompletedReq{}
+	g.BindJsonReq(&r)
+	if g.Err != nil {
+		return
+	}
+
+	if err := signService.HandleASignCompleted(r); err == nil {
+		g.C.String(http.StatusOK, "%s", "ok")
+	} else {
+		global.M2A_LOG.Error(err.Error(), zap.Error(err))
+		response.FailWithMessage(err.Error(), c)
+	}
+}

+ 8 - 0
config.j2

@@ -51,6 +51,14 @@ rabbitmq:
   url: '{{rabbitmq_url}}'
   exchange: 'entry'
 
+# 爱签开放平台配置
+asign:
+  url: '{{asign_url}}' # 测试环境 - https://prev.asign.cn/  正式环境 - https://oapi.asign.cn/
+  appId: '{{asign_appId}}'
+  privateKey: '{{asign_privateKey}}'
+  notifyUrl: '{{asign_notifyUrl}}'
+
+
 # 跨域配置
 # 需要配合 server/initialize/router.go#L32 使用
 cors:

+ 1 - 0
config.yaml

@@ -56,6 +56,7 @@ asign:
   url: 'https://prev.asign.cn/' # 测试环境 - https://prev.asign.cn/  正式环境 - https://oapi.asign.cn/
   appId: '290912417'
   privateKey: 'MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAkMD+72J6iAF0ZNV+3t628lsRHfJ80nKZWK5/C7Pg+AZmOIzJlwHsKhRzCvxoxqYHQprhiFzW9l73v9vD9l1JYwIDAQABAkBVijccr01JYdKuY5t9iI8D2NzcnZc1pZMI3NUmzT18Uyg7b9CUvGHlLeg/gdT4QtVd7wIzHYCY4letEcEMh54BAiEAwzNWusj5XiLmty7PI0Hbakx4HtcND1+P0UHLEWqWOuECIQC91zQuL7nStgGzT3HvaeBB5Ouapa39fHRm2nCjHaxwwwIgRR2XdvmUOj23XWMomr5F14SN/7V7fVcD0D8wjNElsmECIDYavV5kb7tj7/wgqkInlKhzC8rZaUsTS0F9BBkY/eptAiAQJ8Saz8YlMIESdHMxANGSog01fECbcZqLFMuNf8SorA=='
+  notifyUrl: 'http://218.17.158.45:15105/api/Account/HandleASignCompleted'
 
 # 跨域配置
 # 需要配合 server/initialize/router.go#L32 使用

+ 1 - 0
config/asign.go

@@ -4,4 +4,5 @@ type Asign struct {
 	URL        string `mapstructure:"url" json:"url" yaml:"url"`                      // 接口地址
 	AppId      string `mapstructure:"appId" json:"appId" yaml:"appId"`                // AppId
 	PrivateKey string `mapstructure:"privateKey" json:"privateKey" yaml:"privateKey"` // 应用私钥
+	NotifyUrl  string `mapstructure:"notifyUrl" json:"notifyUrl" yaml:"notifyUrl"`    // 合同签署完成异步通知
 }

+ 8 - 3
model/account/request/certification.go

@@ -15,6 +15,11 @@ type CreateContractAndAddSignerReq struct {
 	TemplateNo string `json:"templateNo" binding:"required"` // 合同模板编号
 }
 
-// type AddAuthReq struct {
-
-// }
+type HandleASignCompletedReq struct {
+	Action       string `json:"signCompleted"`
+	ContractNo   string `json:"contractNo"`
+	Status       string `json:"status"`
+	SignTime     string `json:"signTime"`
+	Timestamp    string `json:"timestamp"`
+	ValidityTime string `json:"validityTime"`
+}

+ 1 - 0
router/account.go

@@ -10,6 +10,7 @@ func InitAccountPublicRouter(r *gin.RouterGroup) {
 	accountR := r.Group("Account").Use()
 	{
 		accountR.POST("Login", account.Login)
+		accountR.POST("HandleASignCompleted", account.HandleASignCompleted)
 	}
 }
 

+ 1 - 1
service/asign/asign.go

@@ -297,7 +297,7 @@ func CreateContract(contractNo, contractName, templateNo string) (rspData AsignR
 	reqData["signOrder"] = 1 // 1:无序签约(默认
 	reqData["templates"] = []map[string]string{
 		{"templateNo": templateNo}} // 合同模板编号 - 目前只支持一份合同签一份协议
-	reqData["notifyUrl"] = "https://www.baidu.com"
+	reqData["notifyUrl"] = global.M2A_CONFIG.Asign.NotifyUrl
 
 	reqData["api"] = "createContract"
 	reqData["appId"] = global.M2A_CONFIG.Asign.AppId

+ 22 - 12
service/sign/sign.go

@@ -180,7 +180,7 @@ handleASignCompleted 处理爱签合同签署完成后回调通知
 
 req 异步推送参数
 */
-func HandleASignCompleted(req map[string]string) (err error) {
+func HandleASignCompleted(req request.HandleASignCompletedReq) (err error) {
 	/*
 		// 合同签署完成后回调通知示例
 		String publickey = "MFwwDQcccccxxxxmEz/nw27Ln6AP90ZCMPi+iNF1m9mhNECAwEAAQ==";
@@ -204,21 +204,19 @@ func HandleASignCompleted(req map[string]string) (err error) {
 	*/
 
 	// 获取合同编号
-	contractNo, ok := req["contractNo"]
-	if !ok {
+	if req.ContractNo == "" {
 		global.M2A_LOG.Error("【HandleASignCompleted】 获取合同编号失败", zap.Any("req", req))
 		return
 	}
 	// 获取合同状态
-	status, ok := req["status"]
-	if !ok {
+	if req.Status == "" {
 		global.M2A_LOG.Error("【HandleASignCompleted】 获取获取合同状态失败", zap.Any("req", req))
 		return
 	}
-	if status == "2" {
+	if req.Status == "2" {
 		// 已签约
 		// 下载合同
-		r, e := asign.DownloadContract(contractNo)
+		r, e := asign.DownloadContract(req.ContractNo)
 		if e != nil {
 			err = e
 			return
@@ -253,11 +251,23 @@ func HandleASignCompleted(req map[string]string) (err error) {
 			defer f.Close()
 			// 更新数据库记录
 			// 获取用户电子签记录
-			useresignrecord := new(account.Useresignrecord)
-			has, e = global.M2A_DB.Where("CONTRACTNO = ?", contractNo).Get(useresignrecord)
-			if e != nil || !has {
-				err = e
-				global.M2A_LOG.Error("【HandleASignCompleted】 获取用户电子签记录失败", zap.Error(err))
+			// useresignrecord := new(account.Useresignrecord)
+			// has, e = global.M2A_DB.Where("CONTRACTNO = ?", req.ContractNo).Get(useresignrecord)
+			// if e != nil || !has {
+			// 	err = e
+			// 	global.M2A_LOG.Error("【HandleASignCompleted】 获取用户电子签记录失败", zap.Error(err))
+			// 	return
+			// }
+			contractfileaddr := fmt.Sprintf("./uploadFile/%v/%v", folderPath, fileName)
+			sql := fmt.Sprintf(`
+				UPDATE useresignrecord
+				SET RECORDSTATUS = 3,
+					UPDATETIME = SYSDATE,
+					CONTRACTFILEADDR = '%v'
+				WHERE CONTRACTNO = %v  
+			`, contractfileaddr, req.ContractNo)
+			if _, err = global.M2A_DB.Exec(sql); err != nil {
+				global.M2A_LOG.Error("【HandleASignCompleted】 更新用户电子签记录失败", zap.Error(err))
 				return
 			}
 		}