瀏覽代碼

修改BUG

zhou.xiaoning 2 年之前
父節點
當前提交
4aabf0dc32
共有 9 個文件被更改,包括 241 次插入23 次删除
  1. 60 0
      config/config.go
  2. 23 15
      config/config.xml
  3. 27 2
      config/readme.md
  4. 4 4
      controllers/guangzuan/tradeService.go
  5. 2 2
      models/common.go
  6. 1 0
      models/esign.go
  7. 1 0
      services/asign/api.go
  8. 122 0
      services/asign/http.go
  9. 1 0
      services/asign/models.go

+ 60 - 0
config/config.go

@@ -72,6 +72,15 @@ type TencentConfig struct {
 	SignKey                 string
 }
 
+type AsignConfig struct {
+	Enabled    int
+	Url        string
+	AppId      string
+	PrivateKey string
+	NotifyUrl  string
+	OpenApiUrl string
+}
+
 type ServiceConfig struct {
 	WebCfg     WebConfig
 	LogCfg     LogConfig
@@ -81,6 +90,7 @@ type ServiceConfig struct {
 	MongoDBCfg MongoDBConfig
 	MySQLCfg   MySQLConfig
 	TencentCfg TencentConfig
+	AsignCfg   AsignConfig
 }
 
 func (c *ServiceConfig) Init(path string) error {
@@ -431,6 +441,56 @@ func (c *ServiceConfig) Init(path string) error {
 		SerCfg.TencentCfg.SignKey = signKey.SelectAttrValue("value", "")
 	}
 
+	// 爱签配置
+	// asignsettings := root.SelectElements("Asign")
+	// for _, setting := range asignsettings {
+	// 	// 启用标志
+	// 	enabled := setting.SelectElement("Enabled")
+	// 	if enabled == nil {
+	// 		return errors.New("read asign enabled failed")
+	// 	}
+	// 	ret, err := strconv.ParseUint(enabled.SelectAttrValue("value", "0"), 10, 32)
+	// 	if err != nil {
+	// 		return errors.New("read asign enabled failed")
+	// 	}
+	// 	SerCfg.AsignCfg.Enabled = int(ret)
+
+	// 	// url
+	// 	url := setting.SelectElement("Url")
+	// 	if url == nil {
+	// 		return errors.New("read asign url failed")
+	// 	}
+	// 	SerCfg.AsignCfg.Url = url.SelectAttrValue("value", "")
+
+	// 	// AppId
+	// 	appId := setting.SelectElement("AppId")
+	// 	if appId == nil {
+	// 		return errors.New("read asign AppId failed")
+	// 	}
+	// 	SerCfg.AsignCfg.AppId = appId.SelectAttrValue("value", "")
+
+	// 	// 私钥
+	// 	privateKey := setting.SelectElement("PrivateKey")
+	// 	if privateKey == nil {
+	// 		return errors.New("read asign PrivateKey failed")
+	// 	}
+	// 	SerCfg.AsignCfg.PrivateKey = privateKey.SelectAttrValue("value", "")
+
+	// 	// 合同签署回调通知URL
+	// 	notifyUrl := setting.SelectElement("NotifyUrl")
+	// 	if notifyUrl == nil {
+	// 		return errors.New("read asign notifyUrl failed")
+	// 	}
+	// 	SerCfg.AsignCfg.NotifyUrl = notifyUrl.SelectAttrValue("value", "")
+
+	// 	// 应用的唯一标识
+	// 	openApiUrl := setting.SelectElement("OpenApiUrl")
+	// 	if openApiUrl == nil {
+	// 		return errors.New("read asgin openApiUrl failed")
+	// 	}
+	// 	SerCfg.AsignCfg.OpenApiUrl = openApiUrl.SelectAttrValue("value", "")
+	// }
+
 	return nil
 }
 

+ 23 - 15
config/config.xml

@@ -13,11 +13,11 @@
     <DbAddress value="192.168.31.88"/>
     <DbName value="orcl"/>
     <DbPort value="1521"/>
-    <DbUser value="mtp2_test204"/>
+    <DbUser value="mtp2_test171"/>
     <DbPwd value="muchinfo"/>
   </DbSetting>
   <RedisSetting>
-    <Address value="192.168.31.204"/>
+    <Address value="192.168.31.171"/>
     <Port value="5007"/>
     <Timeout value="3"/>
     <ConnNum value="1"/>
@@ -25,11 +25,11 @@
     <Pwd value=""/>
   </RedisSetting>
   <MqSetting>
-    <Url value="amqp://guest:guest@192.168.31.204:5020/test"/>
+    <Url value="amqp://guest:guest@192.168.31.171:5020/test"/>
     <Exchange value="entry"/>
   </MqSetting>
   <MongoDBSetting>
-    <HostName value="192.168.31.204"/>
+    <HostName value="192.168.31.171"/>
     <Port value="5025"/>
     <DBName value="HistoryQuote"/>
     <Username value="quote_test01"/>
@@ -38,20 +38,28 @@
   <MySQLSetting>
     <Host value="192.168.30.72"/>
     <Port value="3306"/>
-    <DBName value="historyquote_test204"/>
-    <Username value="quote_test204"/>
+    <DBName value="historyquote_test171"/>
+    <Username value="quote_test171"/>
     <Password value="123456"/>
   </MySQLSetting>
   <Tencent>
-    <Enabled value="1"/>
-    <SecretId value="AKIDPktwvneP2WqxvmWFsMclmfLLKDyrbAXp"/>
-    <SecretKey value="GNH9tX8c6Wls02vhNzUvdLuGMYfeVErM"/>
-    <EndPoint value="essbasic.tencentcloudapi.com"/>
-    <AppId value="yDSLpUUghqyijhUTQQ1W1DzMZVs3S2s8"/>
-    <ProxyOrganizationName value="海南掉期市场管理有限责任公司"/>
+    <Enabled value="0"/>
+    <SecretId value="AKyDwiyUUckpkct4igUy8lsS7SEqR6c7yR"/>
+    <SecretKey value="SKwvG74cbV3OrAiJdjU5k4507vZwNYDbwT"/>
+    <EndPoint value="essbasic.test.ess.tencent.cn"/>
+    <AppId value="yDwiuUUckpogfoa4UxhigrYChFMdSJQV"/>
+    <ProxyOrganizationName value="天津麦顿"/>
     <ProxyOrganizationOpenId value="TJMD"/>
-    <ProxyOperatorOpenId value="TJMD_LEGAL"/>
-    <SignToken value="42F95163F767407C858FB58D519A054A"/>
-    <SignKey value="34FD7C4496794788B569E84729601276"/>
+    <ProxyOperatorOpenId value="TJMD01"/>
+    <SignToken value="D586D270A51448179277A11729F37D3E"/>
+    <SignKey value="8774F484EA294C1E829EA6E2D7F99123"/>
   </Tencent>
+  <Asign>
+    <Enabled value="1"/>
+    <Url value="https://prev.asign.cn/"/>
+    <AppId value="290912417"/>
+    <PrivateKey value="MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAkMD+72J6iAF0ZNV+3t628lsRHfJ80nKZWK5/C7Pg+AZmOIzJlwHsKhRzCvxoxqYHQprhiFzW9l73v9vD9l1JYwIDAQABAkBVijccr01JYdKuY5t9iI8D2NzcnZc1pZMI3NUmzT18Uyg7b9CUvGHlLeg/gdT4QtVd7wIzHYCY4letEcEMh54BAiEAwzNWusj5XiLmty7PI0Hbakx4HtcND1+P0UHLEWqWOuECIQC91zQuL7nStgGzT3HvaeBB5Ouapa39fHRm2nCjHaxwwwIgRR2XdvmUOj23XWMomr5F14SN/7V7fVcD0D8wjNElsmECIDYavV5kb7tj7/wgqkInlKhzC8rZaUsTS0F9BBkY/eptAiAQJ8Saz8YlMIESdHMxANGSog01fECbcZqLFMuNf8SorA=="/>
+    <NotifyUrl value="http://218.17.158.45:15105/api/Account/HandleASignCompleted"/>
+    <OpenApiUrl value="http://192.168.31.202:5015/mtp2-onlineopen"/>
+  </Asign>
 </Configuration>

+ 27 - 2
config/readme.md

@@ -13,7 +13,7 @@ cfg.json 用于配置Web交易端所需要的相关服务地址:
         "mobileAuthUrl": "http://192.168.31.104:5056"                       -- 实名认证地址
     }
 
-腾讯电子签配置说明:
+************************* 腾讯电子签配置说明 *************************
   <Tencent>
     <Enabled value="1"/>
     <SecretId value="AKIDPktwvneP2WqxvmWFsMclmfLLKDyrbAXp"/>
@@ -49,4 +49,29 @@ SignKey 腾讯电子签密回调通知密钥,用于解密,使用公司账号
     <ProxyOperatorOpenId value="TJMD01"/>
     <SignToken value="D586D270A51448179277A11729F37D3E"/>
     <SignKey value="8774F484EA294C1E829EA6E2D7F99123"/>
-</Tencent>
+</Tencent>
+
+************************* 爱签配置说明 *************************
+爱签官网:https://www.asign.cn
+接入助手:https://web.asign.cn/platform/tools/helper
+对接文档:https://web.asign.cn/platform/openDoc/docDetail
+测试环境账号注册:https://preweb.asign.cn/platform/openlogin
+生产环境账号注册:https://web.asign.cn/platform
+演示地址:https://ai.acsign.cn/m/#/demo/index
+
+多元测试环境:
+<Asign>
+  <Enabled value="1"/>
+  <Url value="https://prev.asign.cn/"/>
+  <AppId value="290912417"/>
+  <PrivateKey value="MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAkMD+72J6iAF0ZNV+3t628lsRHfJ80nKZWK5/C7Pg+AZmOIzJlwHsKhRzCvxoxqYHQprhiFzW9l73v9vD9l1JYwIDAQABAkBVijccr01JYdKuY5t9iI8D2NzcnZc1pZMI3NUmzT18Uyg7b9CUvGHlLeg/gdT4QtVd7wIzHYCY4letEcEMh54BAiEAwzNWusj5XiLmty7PI0Hbakx4HtcND1+P0UHLEWqWOuECIQC91zQuL7nStgGzT3HvaeBB5Ouapa39fHRm2nCjHaxwwwIgRR2XdvmUOj23XWMomr5F14SN/7V7fVcD0D8wjNElsmECIDYavV5kb7tj7/wgqkInlKhzC8rZaUsTS0F9BBkY/eptAiAQJ8Saz8YlMIESdHMxANGSog01fECbcZqLFMuNf8SorA=="/>
+  <NotifyUrl value="http://218.17.158.45:15105/api/Account/HandleASignCompleted"/>
+  <OpenApiUrl value="http://192.168.31.202:5015/mtp2-onlineopen"/>
+</Asign>
+
+url: 'https://prev.asign.cn/' # 测试环境 - https://prev.asign.cn/  正式环境 - https://oapi.asign.cn/
+appId: '290912417' # 测试-290912417 正式-944849860
+privateKey: 'MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAkMD+72J6iAF0ZNV+3t628lsRHfJ80nKZWK5/C7Pg+AZmOIzJlwHsKhRzCvxoxqYHQprhiFzW9l73v9vD9l1JYwIDAQABAkBVijccr01JYdKuY5t9iI8D2NzcnZc1pZMI3NUmzT18Uyg7b9CUvGHlLeg/gdT4QtVd7wIzHYCY4letEcEMh54BAiEAwzNWusj5XiLmty7PI0Hbakx4HtcND1+P0UHLEWqWOuECIQC91zQuL7nStgGzT3HvaeBB5Ouapa39fHRm2nCjHaxwwwIgRR2XdvmUOj23XWMomr5F14SN/7V7fVcD0D8wjNElsmECIDYavV5kb7tj7/wgqkInlKhzC8rZaUsTS0F9BBkY/eptAiAQJ8Saz8YlMIESdHMxANGSog01fECbcZqLFMuNf8SorA=='
+notifyUrl: 'http://218.17.158.45:15105/api/Account/HandleASignCompleted' # 合同签署回调通知URL
+openApiUrl: 'http://192.168.31.202:5015/mtp2-onlineopen'
+willFaceRedirectUrl: 'http://218.17.158.45:15105/api/Account/HandleWillFace' # 人脸认证结果回调通知URL,可拼接参数

+ 4 - 4
controllers/guangzuan/tradeService.go

@@ -18,8 +18,8 @@ import (
 // @Security Group
 // @Param    userid   query    int    true  "用户ID"
 // @Param    executestatus query    int false "执行状态 - 1:未生效 2:进行中 3:已结束"
-// @Param    page          query    int false "页码"
-// @Param    pagesize      query    int false "每页条数"
+// @Param    page     query    int    false "页码"
+// @Param    pagesize query    int    false "每页条数"
 // @Success  200           {array}  models.GzcjjcorderM
 // @Failure  500     {object} app.Response
 // @Router   /Guangzuan/QueryGZCJJCOrder [get]
@@ -39,8 +39,8 @@ func QueryGZCJJCOrder(c *gin.Context) {
 // @Security Group
 // @Param    userid        query    int true  "用户ID"
 // @Param    orderid  query    string false "单据ID"
-// @Param    page     query    int    false "页码"
-// @Param    pagesize query    int    false "每页条数"
+// @Param    page          query    int false "页码"
+// @Param    pagesize      query    int false "每页条数"
 // @Success  200      {array}  models.GzcjjcorderdetailM
 // @Failure  500           {object} app.Response
 // @Router   /Guangzuan/QueryGZCJJCOrderDetail [get]

+ 2 - 2
models/common.go

@@ -1471,7 +1471,7 @@ func GetTodayAccountConfigInfo(accountid int) (rsp GetTodayAccountConfigInfoRsp,
 					rsp.RiskRatioType = new(Riskratiotype)
 					*rsp.RiskRatioType = riskatiotype
 				} else {
-					if err == nil {
+					if err != nil {
 						err = errors.New("获取数据失败")
 					}
 				}
@@ -1481,7 +1481,7 @@ func GetTodayAccountConfigInfo(accountid int) (rsp GetTodayAccountConfigInfoRsp,
 					rsp.RiskRatioType = new(Riskratiotype)
 					*rsp.RiskRatioType = riskatiotype
 				} else {
-					if err == nil {
+					if err != nil {
 						err = errors.New("获取数据失败")
 					}
 				}

+ 1 - 0
models/esign.go

@@ -60,6 +60,7 @@ func QueryUsereSignRecords(userId, memberUserId int, recordId, templateConfigId,
 }
 
 func QueryMdUserSwapProtocol(userId int, areaUserId *int64) (datas []Mduserswapprotocol, err error) {
+	datas = make([]Mduserswapprotocol, 0)
 	session := db.GetEngine().Table("MD_USERSWAPPROTOCOL").Where("USERID = ?", userId)
 	if areaUserId != nil {
 		session = session.And("AREAUSERID = ?", areaUserId)

+ 1 - 0
services/asign/api.go

@@ -0,0 +1 @@
+package asign

+ 122 - 0
services/asign/http.go

@@ -0,0 +1,122 @@
+package asign
+
+import (
+	"crypto"
+	"crypto/md5"
+	"crypto/rand"
+	"crypto/rsa"
+	"crypto/sha1"
+	"crypto/x509"
+	"encoding/base64"
+	"encoding/hex"
+	"encoding/pem"
+	"fmt"
+	"sort"
+)
+
+func HttpPost(url string, bizData map[string]interface{}) (rspBody []byte, err error) {
+
+	// 签名
+	// timestamp := int64(time.Now().Unix())
+
+	return
+}
+
+// 签名规范:
+// 1、表单提交方式:form-data
+// 示例:1B2M2Y8AsgTpgAmY7PhCfg==
+// 2、请求头部参数
+// 参数1:sign(签名值,具体算法参考一下的前面算法)
+// 参数2:timestamp(时间戳,13位)
+// 3、请求体参数:
+// 参数1:appId(appId值,每个接入者唯一一个)
+// 参数2:timestamp(时间戳,13位,与上述一致)
+// 参数3:bizData(json字符串,举个例子,比方说要传合同编号如:{"contractNo":"0001"})
+// 4、签名算法:
+// 4.1、将上述3所属的bizData(json字符串),按照阿拉伯字母排序(如:{"ba":1,"ac":2}--->{"ac":2,"ba":1}),
+// 4.2、将4.1排序后的字符串,将【bizData+md5(bizData)+ appId + timestatmp】拼接后利用RSA非对称加密算法(SHA1withRSA),计算出最后的签名sign,对其base64编码,放入head的key(sign)中。
+//
+//	 String  sign ;
+//	 String  rsaSuffix = jsonStr + DigestUtils.md5Hex ( jsonStr ) + appId + timestatmp ;
+//	 byte  []  bytes = RSAUtils.generateSHA1withRSASignature ( rsaSuffix, privateKey ) ;
+//	 try {
+//	     sign = Base64Utils.encode ( bytes ) ;
+//	     sign = sign.replaceAll ( " \r\n" , "" ) ;
+//	 }  catch ( Exception e )  {
+//	     log.error( "sdk异常",  e ) ;
+//	     return  ApiRespBody.create ( ApiResponseInfo. _ERROR ) ;
+//	}
+func getSignature(bizData map[string]interface{}, appId, timestamp, privateKey string) (signature string, err error) {
+	pem10, _ := pem.Decode([]byte(privateKey))
+	privateKey10I, _ := x509.ParsePKCS8PrivateKey(pem10.Bytes)
+	privateKey10 := privateKey10I.(*rsa.PrivateKey)
+
+	// sort by key
+	sortedData := sortMapByKey(bizData)
+
+	// md5(bizData)
+	m := md5.New()
+	m.Write([]byte(sortedData))
+	bdMd5Hx := hex.EncodeToString(m.Sum(nil))
+
+	// 待签内容
+	message := sortedData + bdMd5Hx + appId + timestamp
+	h := sha1.New()
+	h.Write([]byte(message))
+	sum := h.Sum(nil)
+
+	// 使用私钥进行签名
+	sign, err := rsa.SignPKCS1v15(rand.Reader, privateKey10, crypto.SHA1, sum)
+	if err != nil {
+		fmt.Println("Error signing:", err)
+		return
+	}
+
+	// fmt.Println(signature)
+	signature = base64.StdEncoding.EncodeToString(sign)
+
+	return
+}
+
+// sortMapByKey 按key排序map返回string
+func sortMapByKey(data map[string]interface{}) (sortedData string) {
+	keys := make([]string, 0, len(data))
+	for k := range data {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+	for i, k := range keys {
+		if i > 0 {
+			sortedData += ","
+		}
+		switch data[k].(type) {
+		case string:
+			sortedData += fmt.Sprintf(`"%s":"%s"`, k, data[k].(string))
+		case map[string]interface{}:
+			sortedData += fmt.Sprintf(`"%s":%s`, k, sortMapByKey(data[k].(map[string]interface{})))
+		case []interface{}:
+			list := data[k].([]interface{})
+			sortedData += fmt.Sprintf(`"%s":[`, k)
+			for j, item := range list {
+				if j > 0 {
+					sortedData += ","
+				}
+				sortedData += sortMapByKey(item.(map[string]interface{}))
+			}
+			sortedData += "]"
+		default:
+			sortedData += fmt.Sprintf(`"%s":%v`, k, data[k])
+		}
+	}
+
+	return fmt.Sprintf("{%s}", sortedData)
+}
+
+// func main() {
+// 	datas := make(map[string]interface{})
+// 	json.Unmarshal([]byte(`{"account":"12345","name":"张三","map":{"ccc":"adfasd","aaa":34355},"list":[{"ccc":"adfasd","aaa":34355},{"dddd":"8ghg","kkkk":12.55}]}`), &datas)
+// 	getSignature(datas, "290912417", "1701866011940",
+// 		`-----BEGIN PRIVATE KEY-----
+// MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEAkMD+72J6iAF0ZNV+3t628lsRHfJ80nKZWK5/C7Pg+AZmOIzJlwHsKhRzCvxoxqYHQprhiFzW9l73v9vD9l1JYwIDAQABAkBVijccr01JYdKuY5t9iI8D2NzcnZc1pZMI3NUmzT18Uyg7b9CUvGHlLeg/gdT4QtVd7wIzHYCY4letEcEMh54BAiEAwzNWusj5XiLmty7PI0Hbakx4HtcND1+P0UHLEWqWOuECIQC91zQuL7nStgGzT3HvaeBB5Ouapa39fHRm2nCjHaxwwwIgRR2XdvmUOj23XWMomr5F14SN/7V7fVcD0D8wjNElsmECIDYavV5kb7tj7/wgqkInlKhzC8rZaUsTS0F9BBkY/eptAiAQJ8Saz8YlMIESdHMxANGSog01fECbcZqLFMuNf8SorA==
+// -----END PRIVATE KEY-----`)
+// }

+ 1 - 0
services/asign/models.go

@@ -0,0 +1 @@
+package asign