金蝶BOS平台查看单据转换关系

进入BOS开发平台->点击文件->点击单据转换
在这里插入图片描述

查看转换对应规则

筛选单据->点击需要查看的数据->查看转换规则
在这里插入图片描述

使用Java调用金蝶接口

编写调用接口类:InvokeHelper

package com.epichust.unimax.utils;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.json.JSONArray;
import org.json.JSONObject;

public class InvokeHelper {

	public static String POST_K3CloudURL = "http://xxx.xxx.x.xx/k3cloud/"; //金蝶部署地址

	// Cookie ֵ
	private static String CookieVal = null;

	//接口映射关系
	private static Map map = new HashMap();
	static {
		map.put("Save",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Save.common.kdsvc");
		map.put("View",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.View.common.kdsvc");
		map.put("Submit",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Submit.common.kdsvc");
		map.put("Audit",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Audit.common.kdsvc");
		map.put("UnAudit",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.UnAudit.common.kdsvc");
		map.put("StatusConvert",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.StatusConvert.common.kdsvc");
		map.put("Push",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Push.common.kdsvc");
		map.put("Delete",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.Delete.common.kdsvc");
		map.put("ExecuteBillQuery",
				"Kingdee.BOS.WebApi.ServicesStub.DynamicFormService.ExecuteBillQuery.common.kdsvc");
	}

	// HttpURLConnection 创建连接
	private static HttpURLConnection initUrlConn(String url, JSONArray paras)
			throws Exception {
		URL postUrl = new URL(POST_K3CloudURL.concat(url));
		HttpURLConnection connection = (HttpURLConnection) postUrl
				.openConnection();
		if (CookieVal != null) {
			connection.setRequestProperty("Cookie", CookieVal);
		}
		if (!connection.getDoOutput()) {
			connection.setDoOutput(true);
		}
		connection.setRequestMethod("POST");
		connection.setUseCaches(false);
		connection.setInstanceFollowRedirects(true);
		connection.setRequestProperty("Content-Type", "application/json; charset=uft-8");
		DataOutputStream out = new DataOutputStream(
				connection.getOutputStream());

		UUID uuid = UUID.randomUUID();
		int hashCode = uuid.toString().hashCode();

		JSONObject jObj = new JSONObject();

		jObj.put("format", 1);
		jObj.put("useragent", "ApiClient");
		jObj.put("rid", hashCode);
		jObj.put("parameters", chinaToUnicode(paras.toString()));
		jObj.put("timestamp", new Date().toString());
		jObj.put("v", "1.0");

		out.writeBytes(jObj.toString());
		out.flush();
		out.close();

		return connection;
	}

	// Login
	public static boolean Login(String dbId)
			throws Exception {

		boolean bResult = false;

		String sUrl = "Kingdee.BOS.WebApi.ServicesStub.AuthService.ValidateUser.common.kdsvc";

		JSONArray jParas = new JSONArray();
		jParas.put(dbId);
		jParas.put(HxjxComConstant.USER_NAME);
		jParas.put(HxjxComConstant.PASS_WORD);
		jParas.put(HxjxComConstant.LANG);

		HttpURLConnection connection = initUrlConn(sUrl, jParas);

		String key = null;
		for (int i = 1; (key = connection.getHeaderFieldKey(i)) != null; i++) {
			if (key.equalsIgnoreCase("Set-Cookie")) {
				String tempCookieVal = connection.getHeaderField(i);
				if (tempCookieVal.startsWith("kdservice-sessionid")) {
					CookieVal = tempCookieVal;
					break;
				}
			}
		}

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				connection.getInputStream(),"utf-8"));
		String line;
		while ((line = reader.readLine()) != null) {
			String sResult = new String(line.getBytes(), "utf-8");
			System.out.println(sResult);
			bResult = line.contains("\"LoginResultType\":1");
		}
		reader.close();

		connection.disconnect();

		return bResult;
	}

	// Save
	public static String Save(String formId, String content) throws Exception {
		return Invoke("Save", formId, content);
	}

	// View
	public static String View(String formId, String content) throws Exception {
		return Invoke("View", formId, content);
	}

	// Submit
	public static String Submit(String formId, String content) throws Exception {
		return Invoke("Submit", formId, content);
	}

	// Audit
	public static String Audit(String formId, String content) throws Exception {
		return Invoke("Audit", formId, content);
	}

	// UnAudit
	public static String UnAudit(String formId, String content) throws Exception {
		return Invoke("UnAudit", formId, content);
	}

	// StatusConvert
	public static String StatusConvert(String formId, String content)
			throws Exception {
		return Invoke("StatusConvert", formId, content);
	}

	// Push
	public static String Push(String formId, String content)
			throws Exception {
		return Invoke("Push", formId, content);
	}

	public static String Delete(String formId, String content)
			throws Exception {
		return Invoke("Delete", formId, content);
	}

	public static String ExecuteBillQuery(String formId, String content)
			throws Exception {
		return Invoke("ExecuteBillQuery", content);
	}

	private static String Invoke(String deal, String formId, String content)
			throws Exception {

		String sUrl = map.get(deal).toString();
		JSONArray jParas = new JSONArray();
		jParas.put(formId);
		jParas.put(content);

		HttpURLConnection connectionInvoke = initUrlConn(sUrl, jParas);

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				connectionInvoke.getInputStream(),"utf-8"));

		String line;
		StringBuilder result = new StringBuilder();
		while ((line = reader.readLine()) != null) {
			String sResult = new String(line.getBytes(), "utf-8");
			result.append(sResult);
		}
		reader.close();
		connectionInvoke.disconnect();

		return  result.toString();
	}

	private static String Invoke(String deal, String content)
			throws Exception {

		String sUrl = map.get(deal).toString();
		JSONArray jParas = new JSONArray();
//		jParas.put(formId);
		jParas.put(content);

		HttpURLConnection connectionInvoke = initUrlConn(sUrl, jParas);

		BufferedReader reader = new BufferedReader(new InputStreamReader(
				connectionInvoke.getInputStream(),"utf-8"));

		String line;
		StringBuilder result = new StringBuilder();
		while ((line = reader.readLine()) != null) {
			String sResult = new String(line.getBytes(), "utf-8");
			result.append(sResult);
		}
		reader.close();
		connectionInvoke.disconnect();

		return  result.toString();
	}

	/**
	 * 
	 * @param str
	 * @return
	 */
	public static String chinaToUnicode(String str) {
		String result = "";
		for (int i = 0; i < str.length(); i++) {
			int chr1 = (char) str.charAt(i);
			if (chr1 >= 19968 && chr1 <= 171941) {
				result += "\\u" + Integer.toHexString(chr1);
			} else {
				result += str.charAt(i);
			}
		}
		return result;
	}
}

调用接口

/**
     * 请求生产订单信息
     * @param orderCode
     * @param env
     * @return
     */
    public static Map<String, Object> querySSDDInfo(String orderCode, String env){
        //根据配置的环境调用ERP
        String dbId = "";
        if ("PRO".equals(env)){
            InvokeHelper.POST_K3CloudURL = HxjxComConstant.PRO_URL;
            dbId = HxjxComConstant.PRO_DB_ID;
        }else {
            InvokeHelper.POST_K3CloudURL = HxjxComConstant.UAT_URL;
            dbId = HxjxComConstant.UAT_DB_ID;
        }
        //开始调用接口
        try {
            if (InvokeHelper.Login(dbId)) {
                String sFormId = "PRD_MO";
                String sContent = createQuerySSDD(orderCode);
                MestarLogger.error("开始请求查看生产订单,调用环境:"+InvokeHelper.POST_K3CloudURL+";传入参数为:"+sContent);
                String result = InvokeHelper.View(sFormId, sContent);
                MestarLogger.error("请求查看生产订单结束,返回结果:"+result);
                Map<String, Object> resultMap = handleSSDDInfoResult(result);
                return resultMap;
            }
        } catch (Exception e) {
            return null;
        }
        return null;
    }
Logo

火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。

更多推荐