• 测试


    测试

    java web 

    package com.tukrin.ocean;
    
    import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.util.HashMap;
    import java.util.Map;
    
    import com.alibaba.fastjson.JSONObject;
    
    /**
     * 欧神人脸平台工具类
     * @author aisi
     *
     */
    public class OceanUtil {
        public static final String OCEAN_TOKEN_URL = "http://192.168.1.221:10006/ocean/auth/token";
        
        /**
         * 获得token
         * @param appId
         * @param appSecret
         * @return String
         */
        public static String getOceanToken(String appId, String appSecret){
            if(appId == null && appSecret == null){
                appId = "a54fce347adf4ca88f740c0eb230ec31";
                appSecret = "$2a$10$dJDxml5rWVC4EanD7TbsgOfqTwcr/tcq5DAGR6KIBrwqo4GuPUHte";
            }
            HttpURLConnection connection = null;
            BufferedReader reader = null;
            String token = null;
            
            try {
                URL url = new URL(OCEAN_TOKEN_URL);
                connection = (HttpURLConnection) url.openConnection();
                connection.setRequestMethod("POST");
                connection.setDoOutput(true);
                connection.setRequestProperty("Content-Type",  "application/json");  
                connection.setConnectTimeout(8000);
                connection.setReadTimeout(6000);
                
                //请求参数
                Map<String, Object> map = new HashMap<String, Object>();
                map.put("appId", appId);
                map.put("appSecret", appSecret);
                
                DataOutputStream out = new DataOutputStream(connection.getOutputStream());
                out.writeBytes(JSONObject.toJSONString(map));
                
                //读取返回数据
                InputStream in = connection.getInputStream();
                reader = new BufferedReader(new InputStreamReader(in));
                StringBuilder sb = new StringBuilder();
                String line = null;
                while((line = reader.readLine()) != null){
                    sb.append(new String(line.getBytes(), "UTF-8"));
                }
                
                //获取token
                JSONObject jsonObject1 = JSONObject.parseObject(sb.toString());
                JSONObject jsonObject2 = (JSONObject) jsonObject1.get("data");
                token = (String) jsonObject2.get("token");
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            return token;
        }
    }

  • 相关阅读:
    在SAP云平台上部署和运行Docker应用
    SAP ABAP maintanence view的数据校验机制
    SAP CRM user参数CRM_UI_PROFILE是在哪行ABAP代码里读取的
    sublime text的dockerfile语法高亮插件
    SAP Business Application Studio和SAP云平台Destination
    SAP UI5应用访问OData metadata的url和Destination
    SAP CRM note的自动拷贝
    合并二维数组
    redis命令手册
    redis性能测试工具的使用
  • 原文地址:https://www.cnblogs.com/aisi-liu/p/10825623.html
Copyright © 2020-2023  润新知