ncc token

This commit is contained in:
lvleigang 2025-06-12 15:20:43 +08:00
parent 61f604bad4
commit cbec72c450
3 changed files with 77 additions and 1 deletions

View File

@ -32,7 +32,7 @@ spring:
# type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://ufidahz.com.cn:9014/businesscenter?serverTimezone=UTC&useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=30000&socketTimeout=30000&autoReconnectForPools=true
username: root
password: 62e4295b615a30dbf3b8ee96f41c820b
password: bd993088e8a7c3dc5f44441617f9b4bf
driver-class-name: com.mysql.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
# url: jdbc:dm://hzya.ufyct.com:9040/businesscenter?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8
# url: jdbc:dm://hzya.ufyct.com:9040?schema=businesscenter&zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&compatibleMode=oracle

View File

@ -0,0 +1,11 @@
package com.hzya.frame.ncc.v202005.service;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
public interface INccTokenService {
SysExtensionApiEntity getNccToken(SysExtensionApiEntity entity);
}

View File

@ -0,0 +1,65 @@
package com.hzya.frame.ncc.v202005.service.impl;
import com.hzya.frame.ncc.v202005.service.INccTokenService;
import com.hzya.frame.sysnew.application.entity.SysExtensionApiEntity;
import com.hzya.frame.util.bipV3.Encryption;
import com.hzya.frame.util.bipV3.SHA256Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.net.URLEncoder;
import java.util.*;
@Service(value="nccTokenService")
public class NccTokenServiceImpl implements INccTokenService {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Override
public SysExtensionApiEntity getNccToken(SysExtensionApiEntity entity) {
try {
Map<String, String> headers = entity.getHeaders();
String client_id = headers.get("client_id");
Map<String, String> paramMap = new HashMap<String, String>();
// 密码模式认证
paramMap.put("grant_type", "client_credentials");
// 第三方应用id
paramMap.put("client_id", client_id);
// 第三方应用secret]
String client_secret = headers.get("client_secret");
// 账套编码
String busi_center = headers.get("busi_center");
//用户编码
String usercode = headers.get("usercode");
//数据库编码
String dsname = headers.get("dsname");
String pubKey = headers.get("pubKey");
// 第三方应用secret 公钥加密]
paramMap.put("client_secret", URLEncoder.encode(Encryption.pubEncrypt(pubKey, client_secret), "utf-8"));
// 账套编码
paramMap.put("biz_center", busi_center);
// // TODO 传递数据源和ncc登录用户
paramMap.put("dsname", dsname);
paramMap.put("usercode", usercode);
// 签名
String sign = SHA256Util.getSHA256(client_id + client_secret + pubKey,pubKey);
paramMap.put("signature", sign);
StringBuffer querys = new StringBuffer();
querys.append("biz_center="+busi_center);
querys.append("&grant_type="+"client_credentials");
querys.append("&signature="+sign);
querys.append("&dsname="+dsname);
querys.append("&client_secret="+ URLEncoder.encode(Encryption.pubEncrypt(pubKey, client_secret), "utf-8"));
querys.append("&usercode="+usercode);
querys.append("&client_id="+client_id);
entity.setQuerys(querys.toString());
headers.put("content-type","application/x-www-form-urlencoded");
} catch (Exception e) {
e.printStackTrace();
}
return entity;
}
}