|
|
@@ -9,9 +9,11 @@ import (
|
|
|
"mtp20access/model/account/request"
|
|
|
"mtp20access/model/account/response"
|
|
|
"mtp20access/service/asign"
|
|
|
+ "os"
|
|
|
"strconv"
|
|
|
"time"
|
|
|
|
|
|
+ "github.com/gofrs/uuid"
|
|
|
"go.uber.org/zap"
|
|
|
)
|
|
|
|
|
|
@@ -85,7 +87,7 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
|
|
|
if useresignrecord.CONTRACTNO == "" {
|
|
|
// 生成合同编号
|
|
|
// #{userid} || '_' || to_char(sysdate, 'yyyyMMddhh24miss') || '_' || seq_useresignrecord.currval,
|
|
|
- contractNo := fmt.Sprintf("%d_%s_%v", userId, time.Now().Format("2006-01-02 15:04:05"), useresignrecord.RECORDID)
|
|
|
+ contractNo := fmt.Sprintf("%d_%s_%v", userId, time.Now().Format("20060102150405"), useresignrecord.RECORDID)
|
|
|
// 调用爱签API-上传待签署文件(https://{host}/contract/createContract)
|
|
|
r, e := asign.CreateContract(
|
|
|
contractNo,
|
|
|
@@ -105,7 +107,7 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
|
|
|
useresignrecord.CONTRACTNO = contractNo
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
- SET SIGNURL = '%v'
|
|
|
+ SET contractNo = '%v',
|
|
|
UPDATETIME = SYSDATE
|
|
|
WHERE RECORDID = %v
|
|
|
`, useresignrecord.CONTRACTNO, useresignrecord.RECORDID)
|
|
|
@@ -138,7 +140,7 @@ func CreateContractAndAddSigner(req request.CreateContractAndAddSignerReq, userI
|
|
|
// 将返回的合同编号写入数据库
|
|
|
sql := fmt.Sprintf(`
|
|
|
UPDATE useresignrecord
|
|
|
- SET SIGNURL = '%v'
|
|
|
+ SET SIGNURL = '%v',
|
|
|
UPDATETIME = SYSDATE
|
|
|
WHERE RECORDID = %v
|
|
|
`, useresignrecord.SIGNURL, useresignrecord.RECORDID)
|
|
|
@@ -160,43 +162,87 @@ handleASignCompleted 处理爱签合同签署完成后回调通知
|
|
|
req 异步推送参数
|
|
|
*/
|
|
|
func HandleASignCompleted(req map[string]string) (err error) {
|
|
|
- // 合同签署完成后回调通知示例
|
|
|
- // String publickey = "MFwwDQcccccxxxxmEz/nw27Ln6AP90ZCMPi+iNF1m9mhNECAwEAAQ==";
|
|
|
- // String remark = ""; // 若被拒签则会返回拒签原因,拒签原因不参与签名
|
|
|
- // Map <String, String> map = new HashMap<>();
|
|
|
- // map.put("action", "signCompleted");
|
|
|
- // map.put("contractNo", "20221114142140345");
|
|
|
- // map.put("status", "2");
|
|
|
- // map.put("signTime", "2022-11-14 14:22:00");
|
|
|
- // map.put("timestamp", "1668406920005");
|
|
|
- // map.put("validityTime", "2022-11-24 23:59:59");
|
|
|
- // String json = JSONObject.toJSONString(map, SerializerFeature.MapSortField);
|
|
|
- // System.out.println("数据:" + json);
|
|
|
- // // 计算签名
|
|
|
- // try {
|
|
|
- // String sign = "feFfcprGjdmDDqRmxK5qlWlMncX0mc6LJ5agebOGIx2QiAern+6ZRg/SBHOgvHp/+1ywVRdyKNUKxPneETwKPw==";
|
|
|
- // System.out.println(RSAUtils.rsaSignCheck(sign, json, publickey));
|
|
|
- // } catch (Exception e) {
|
|
|
- // e.printStackTrace();
|
|
|
- // }
|
|
|
+ /*
|
|
|
+ // 合同签署完成后回调通知示例
|
|
|
+ String publickey = "MFwwDQcccccxxxxmEz/nw27Ln6AP90ZCMPi+iNF1m9mhNECAwEAAQ==";
|
|
|
+ String remark = ""; // 若被拒签则会返回拒签原因,拒签原因不参与签名
|
|
|
+ Map <String, String> map = new HashMap<>();
|
|
|
+ map.put("action", "signCompleted");
|
|
|
+ map.put("contractNo", "20221114142140345");
|
|
|
+ map.put("status", "2");
|
|
|
+ map.put("signTime", "2022-11-14 14:22:00");
|
|
|
+ map.put("timestamp", "1668406920005");
|
|
|
+ map.put("validityTime", "2022-11-24 23:59:59");
|
|
|
+ String json = JSONObject.toJSONString(map, SerializerFeature.MapSortField);
|
|
|
+ System.out.println("数据:" + json);
|
|
|
+ // 计算签名
|
|
|
+ try {
|
|
|
+ String sign = "feFfcprGjdmDDqRmxK5qlWlMncX0mc6LJ5agebOGIx2QiAern+6ZRg/SBHOgvHp/+1ywVRdyKNUKxPneETwKPw==";
|
|
|
+ System.out.println(RSAUtils.rsaSignCheck(sign, json, publickey));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ */
|
|
|
|
|
|
// 获取合同编号
|
|
|
- // contractNo, ok := req["contractNo"]
|
|
|
- // if !ok {
|
|
|
- // global.M2A_LOG.Error("【HandleASignCompleted】 获取合同编号失败", zap.Any("req", req))
|
|
|
- // return
|
|
|
- // }
|
|
|
- // // 获取合同状态
|
|
|
- // status, ok := req["status"]
|
|
|
- // if !ok {
|
|
|
- // global.M2A_LOG.Error("【HandleASignCompleted】 获取获取合同状态失败", zap.Any("req", req))
|
|
|
- // return
|
|
|
- // }
|
|
|
- // if status == "2" {
|
|
|
- // // 已签约
|
|
|
- // // 下载合同
|
|
|
-
|
|
|
- // }
|
|
|
+ contractNo, ok := req["contractNo"]
|
|
|
+ if !ok {
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取合同编号失败", zap.Any("req", req))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 获取合同状态
|
|
|
+ status, ok := req["status"]
|
|
|
+ if !ok {
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取获取合同状态失败", zap.Any("req", req))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if status == "2" {
|
|
|
+ // 已签约
|
|
|
+ // 下载合同
|
|
|
+ r, e := asign.DownloadContract(contractNo)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if r.Code != 100000 {
|
|
|
+ err = errors.New(strconv.Itoa(r.Code))
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 下载合同接口调用失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if r.Data.Data != "" {
|
|
|
+ // 获取网上开户地址(用于客户端下载文件)
|
|
|
+ openconfig := account.Wskhopenaccountconfig{CONFIGID: 6}
|
|
|
+ has, e := openconfig.Get()
|
|
|
+ if e != nil || !has {
|
|
|
+ err = e
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取网上开户地址失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 将Base64写入目标文件
|
|
|
+ uid, _ := uuid.NewV4()
|
|
|
+ fileName := fmt.Sprintf("%v_%v.pdf", r.Data.FileName, uid.String())
|
|
|
+ openconfig.CONFIGVALUE = "./" // FIXME: - 测试代码
|
|
|
+ folderPath := "sign/" + time.Now().Format("20060102")
|
|
|
+ savePath := openconfig.CONFIGVALUE + "/uploadFile/" + folderPath
|
|
|
+ fmt.Println(savePath + "/" + fileName)
|
|
|
+ f, e := os.OpenFile(savePath+"/"+fileName, os.O_RDWR|os.O_CREATE, os.ModePerm)
|
|
|
+ if e != nil {
|
|
|
+ err = e
|
|
|
+ global.M2A_LOG.Error("【HandleASignCompleted】 获取网上开户地址失败", zap.Error(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return
|
|
|
}
|