package com.zy.erp.ghln;
|
|
import com.alibaba.fastjson.JSON;
|
import com.zy.common.utils.HttpHandler;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
|
import java.io.IOException;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @author pang.jiabao
|
* @description
|
* @createDate 2024/7/10 19:46
|
*/
|
public class GhlnErp {
|
|
public static final String servelUrl = "http://192.168.16.7/K3Cloud";
|
|
private static Logger logger = LoggerFactory.getLogger(GhlnErp.class);
|
|
private static String dbid ; //测试环境TEST3为6353684490aa2b 正式环境为 655f026e8f0a03 TEST1测试环境为63985a1d80ae72
|
|
private static String userName="Administrator"; //测试环境和正式环境都是一样的
|
|
private static String passWord="a123456."; //测试环境和正式环境都是一样的
|
private static int lang=2052;
|
|
static {
|
boolean addressEnabled = false; //获取正式环境数据为true 测试环境就为false
|
if(addressEnabled){
|
dbid="655f026e8f0a03";
|
}else{
|
dbid="63985a1d80ae72";
|
}
|
}
|
|
|
// @Scheduled(fixedRate=200000)
|
public static String login() throws IOException {
|
logger.info("dbid"+dbid);
|
// id号 用户名 和 密码
|
// String loginParam = buildLogin("6269114ac9aeb1", "demo", "a123456.", 2052); 高科测试 6295eb8010ec7f 正式环境账套ID 62de03297091ce
|
String loginParam = buildLogin(dbid, userName, passWord, lang);
|
System.out.println(loginParam);
|
String url = "/Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc";
|
String response= new HttpHandler.Builder()
|
.setUri(servelUrl)
|
.setPath(url)
|
.setJson(loginParam)
|
.build()
|
.doPost();
|
// HttpUtil.httpPost(url, loginParam);
|
String login_cookie="";
|
// if(response.getStatusCode()== HttpStatus.OK) {
|
// Set<String> keys=response.getHeaders().keySet();
|
// for(String key:keys){
|
// if (key.equalsIgnoreCase("Set-Cookie")) {
|
// List<String> cookies = response.getHeaders().get(key);
|
// for(String cookie:cookies){
|
// if(cookie.startsWith("kdservice-sessionid")){
|
// login_cookie=cookie;
|
// RedisUtils.setCacheObject("loginedcookies", login_cookie,10, TimeUnit.MINUTES);
|
//
|
// System.out.println("登录K3成功啦:"+login_cookie);
|
// break;
|
// }
|
// }
|
// }
|
// }
|
// System.out.println( response.getBody());
|
// }
|
return login_cookie;
|
}
|
|
public static void main(String[] args) throws IOException {
|
String login = GhlnErp.login();
|
System.out.println(login);
|
}
|
|
public static String buildLogin(String dbid, String userName, String password, int lang){
|
Map<String,Object> param = new HashMap<>(4);
|
param.put("acctID",dbid);
|
param.put("username",userName);
|
param.put("password",password);
|
param.put("lcid",lang);
|
return JSON.toJSONString(param);
|
}
|
|
// 获取半成品母卷查询接口:
|
// public static ArrayList<ObtainInforMasterRollMaterVo> GetJxFMaterialIdByFMaterialName(){
|
// Long beginTime = new Date().getTime();
|
// ArrayList<ObtainInforMasterRollMaterVo> masterlist= new ArrayList<>();
|
// try{
|
// String url = servelUrl+"/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc";
|
// String formId="BD_MATERIAL";
|
// String cookie=""
|
//// RedisUtils.getCacheObject("loginedcookies");
|
// if( cookie == null){
|
// cookie = login();
|
// }
|
// String residuelength="{\n" +
|
// " \"FormId\": \"BD_MATERIAL\",\n" +
|
// " \"FieldKeys\": \"FNumber,FName,FSpecification,FUseOrgId.fnumber,FDocumentStatus,FBaseUnitId.fnumber\",\n" +
|
// " \"FilterString\": \"FUseOrgId.fnumber='10004' and fnumber like '02%'\",\n" +
|
// " \"OrderString\": \"\",\n" +
|
// " \"TopRowCount\": 0,\n" +
|
// " \"StartRow\": 0,\n" +
|
// " \"Limit\": 2000,\n" +
|
// " \"SubSystemId\": \"\"\n" +
|
// "}";
|
// String queryinfo = "";
|
//// buildMaterial(residuelength,formId) ;
|
// Map<String, Object> header = new HashMap<>();
|
// header.put("Cookie",cookie);
|
// String results =
|
// HttpUtil.httpPost(url, header, queryinfo);
|
// String[] tempstr=null;
|
// if(!"[]".equals(results)) {
|
// String[] returnstr=results.split("],");
|
// if (returnstr.length > 0) {
|
// for(int i=0; i<returnstr.length;i++){
|
// ObtainInforMasterRollMaterVo obtaininfor=new ObtainInforMasterRollMaterVo();
|
// tempstr = returnstr[i].split(",");
|
// if (i == 0) {
|
// obtaininfor.setMaterialNo(tempstr[0].substring(2, tempstr[0].length())); //物料编码
|
// } else {
|
// obtaininfor.setMaterialNo(tempstr[0].substring(1, tempstr[0].length())); //物料编码
|
// }
|
// obtaininfor.setFmaterialName(tempstr[1]); // 物料名称
|
// obtaininfor.setFSpecification(tempstr[2]); // 规格
|
// obtaininfor.setFUseOrgId(tempstr[3]); // 使用组织
|
// obtaininfor.setFDocumentStatus(tempstr[4]); // 数据状态
|
// if (returnstr.length == 1) {
|
// obtaininfor.setFBaseUnitId(tempstr[5].substring(0, tempstr[5].length() - 2)); // 基本单位
|
// } else if (returnstr.length > 1) {
|
// if (i == returnstr.length - 1) {
|
// obtaininfor.setFBaseUnitId(tempstr[5].substring(0, tempstr[5].length() - 2));
|
//
|
// } else {
|
// obtaininfor.setFBaseUnitId(tempstr[5].substring(0, tempstr[5].length()));
|
// }
|
// }
|
// StringUtils.removeReg(obtaininfor);
|
// masterlist.add(obtaininfor);
|
// }
|
// }
|
// }
|
// }catch (Exception e){
|
// logger.error("调用物料查询接口获取母卷物料信息报错--JX");
|
// logger.error(e.getMessage());
|
// throw new RuntimeException("调用物料查询接口获取母卷物料信息报错--JX");
|
// }
|
// Long opetime =new Date().getTime()-beginTime;
|
// logger.info("调用物料查询接口获取母卷物料信息--jx 调用接口耗时 "+opetime);
|
// return masterlist;
|
// }
|
//
|
// public static String GetJxFMaterialIdByFMaterialName(String materialno){
|
// Long beginTime = new Date().getTime();
|
// String matername="";
|
// try{
|
// String url = servelUrl+"/Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc";
|
// String formId="BD_MATERIAL";
|
// String cookie=RedisUtils.getCacheObject("loginedcookies");
|
// if( cookie == null){
|
// cookie = login();
|
// }
|
// String residuelength="{\n" +
|
// " \"FormId\": \"BD_MATERIAL\",\n" +
|
// " \"FieldKeys\": \"FName\",\n" +
|
// " \"FilterString\": \"FUseOrgId.fnumber='10004' and fnumber='"+materialno+"'\",\n" +
|
// " \"OrderString\": \"\",\n" +
|
// " \"TopRowCount\": 0,\n" +
|
// " \"StartRow\": 0,\n" +
|
// " \"Limit\": 2000,\n" +
|
// " \"SubSystemId\": \"\"\n" +
|
// "}";
|
// String queryinfo = buildMaterial(residuelength,formId) ;
|
// Map<String, Object> header = new HashMap<>();
|
// header.put("Cookie",cookie);
|
// String results = HttpUtil.httpPost(url, header, queryinfo);
|
// String[] tempstr=null;
|
// if(!"[]".equals(results)) {
|
// String[] returnstr=results.split("],");
|
// if (returnstr.length > 0) {
|
// for(int i=0; i<returnstr.length;i++){
|
// ObtainInforMasterRollMaterVo obtaininfor=new ObtainInforMasterRollMaterVo();
|
// tempstr = returnstr[i].split(",");
|
// if (i == 0) {
|
// matername=tempstr[0].substring(2, tempstr[0].length()-2); //物料名称
|
// }
|
// break;
|
// StringUtils.removeReg(matername);
|
// }
|
// }
|
// }
|
// }catch (Exception e){
|
// logger.error("调用物料查询接口获取母卷物料信息报错--JX");
|
// logger.error(e.getMessage());
|
// throw new RuntimeException("调用物料查询接口获取母卷物料信息报错--JX");
|
// }
|
// Long opetime =new Date().getTime()-beginTime;
|
// logger.info("调用物料查询接口获取母卷物料信息--jx 调用接口耗时 "+opetime);
|
// return matername;
|
// }
|
|
}
|