EAS调用苍穹获取AppToken和login接口示例

栏目:eas cloud知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

EAS调用苍穹获取AppToken和login接口示例

应该是很常用的工具类了,talk is cheap,show me the code


import java.util.HashMap;

import java.util.Map;

import com.alibaba.fastjson.JSON;

import com.alibaba.fastjson.JSONObject;

import com.kingdee.bos.BOSException;

import com.kingdee.bos.qing.web.util.HttpUtil;


/**

 * @desc 苍穹登录openapi帮助类

 *

 */

public class CosmicLoginUtil {


// 在苍穹配置的第三方appid

private final static String APP_ID = "EAS";

// 在苍穹配置的第三方密码

private final static String APP_SECURET = "1234567812345678";

// 苍穹租户id

private final static String TENANT_ID = "cosmic-simple";

// 登陆用户(手机号)

private final static String USER = "186xxxxxxxx";

// 苍穹服务器IP地址

private final static String SERVER_IP = "localhost";

// 获取apptoken的url

private final static String GET_APP_TOKEN_URL = "http://"+SERVER_IP+":8080/ierp/api/getAppToken.do";

// 登录的url

private final static String LOGIN_URL = "http://"+SERVER_IP+":8080/ierp/api/login.do";


/**

* @desc 调用苍穹的登录openapi,先获取app_token,再登录获取access_token

* @date 2021-8-22

* @return

* @throws Exception

*/

public static String login() throws Exception {

JSONObject requestData = new JSONObject();

requestData.put("appId", APP_ID);

requestData.put("appSecuret", APP_SECURET);

requestData.put("tenantid", TENANT_ID);

// requestData.put("accountId", "759401979301596160");

requestData.put("language","zh_CN");

String json = HttpUtil.postByJson(GET_APP_TOKEN_URL, null, requestData.toJSONString());

System.out.println(json);


JSONObject resultObj = (JSONObject)JSON.parse(json);

JSONObject data = resultObj.getJSONObject("data");

String apptoken = data.getString("app_token");

String tenantid = TENANT_ID;

String user = USER;

// String accountId = "759401979301596160";

String usertype = "Mobile";

JSONObject loginParam = new JSONObject();

loginParam.put("apptoken", apptoken);

loginParam.put("tenantid", tenantid);

loginParam.put("user", user);

// loginParam.put("accountId", accountId);

loginParam.put("usertype", usertype);

String result = HttpUtil.postByJson(LOGIN_URL, null, loginParam.toJSONString());

System.out.println(result);

return result;

}



【emoji】学习

EAS调用苍穹获取AppToken和login接口示例

应该是很常用的工具类了,talk is cheap,show me the codeimport java.util.HashMap;import java.util.Map;import com.alibaba.fas...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息