百度,有道,谷歌翻译API

news2024/11/15 17:20:12

API翻译

百度,有道,谷歌API翻译(只针对中英相互翻译),其他语言翻译需要对应from,to的code

百度翻译

package fills.tools.translate;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Set;

import javax.script.Invocable;

import javax.script.ScriptEngine;

import javax.script.ScriptEngineManager;

import org.apache.http.HttpEntity;

import org.apache.http.NameValuePair;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

public class BaiduTranslateTools {

public static void main(String[] args) throws Exception{

     String en = doBdTranslate("测试一下", "zh", "en");

     String zh = doBdTranslate("test", "en", "zh");

     System.out.println(en);

     System.out.println(zh);

}

private static CloseableHttpClient httpClient = HttpClients.createDefault();

/**

 * 封装百度翻译请求参数

 * @param query

 * @param from  zh 

 * @param to  en

 * @return String

 * @throws Exception

 */

public static String doBdTranslate(String query,String from,String to)throws Exception{

     String url = "https://fanyi.baidu.com/v2transapi";

     Map<String,String> params = new HashMap<String,String>();

     params.put("from",from);

     params.put("to",to);

     params.put("transtype","translang");

     params.put("simple_means_flag","3");

     params.put("sign",runByJs(query,"sig",getBdJs()));

     params.put("token","75f7eb4170c6dba7a1d84c76611205c3");

     params.put("domain","common");

     params.put("query",query);

     return bdGetResult(bdTranslate(url, params));

}

/**

 * 封装百度翻译接口 模拟浏览器请求

 * @param url

 * @param map

 * @return String

 * @throws Exception

 */

private static String bdTranslate(String url,Map<String,String> map) throws Exception{

        try {

         HttpPost request = new HttpPost(url);

request.setEntity(new UrlEncodedFormEntity(map2list(map), "UTF-8"));

        request.setHeader("Cookie","BIDUPSID=518EFD25B0E401331F59B9BDC8388898; BAIDUID=DA7060B673236FB3427E0D66755262B9:FG=1; PSTM=1636594736; __yjs_duid=1_57b3cd04392832a6fbd32d39e48784831636600728790; BDORZ=FFFB88E999055A3F8A630C64834BD6D0; BDUSS=phdjFZaTJRZ3lPeW1OaHg0WXFyMFgtNWZ6QXNkczh3cEd-Sn5INjg3dG9nc0poRVFBQUFBJCQAAAAAAAAAAAEAAACHLc4ceXNmd3p6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGj1mmFo9ZpheW; H_PS_PSSID=34446_35104_31254_35049_34584_34518_35245_34578_26350_35146; Hm_lvt_64ecd82404c51e03dc91cb9e8c025574=1637568947; Hm_lpvt_64ecd82404c51e03dc91cb9e8c025574=1637569056; REALTIME_TRANS_SWITCH=1; FANYI_WORD_SWITCH=1; HISTORY_SWITCH=1; SOUND_SPD_SWITCH=1; SOUND_PREFER_SWITCH=1; delPer=0; PSINO=2; BDRCVFR[Fc9oatPmwxn]=mk3SLVN4HKm; BA_HECTOR=8hag058g0gag8g218f1gpp7gb0r");

        request.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");

        request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        request.setHeader("Host","fanyi.baidu.com");

        request.setHeader("Origin","https://fanyi.baidu.com");

        request.setHeader("Referer","https://fanyi.baidu.com/?aldtype=16047");

        request.setHeader("X-Requested-With","XMLHttpRequest");

        CloseableHttpResponse response = httpClient.execute(request);

        HttpEntity entity = response.getEntity();

        String result = EntityUtils.toString(entity, "UTF-8");

        EntityUtils.consume(entity);

        response.getEntity().getContent().close();

        response.close();

        return result;

        } catch (Exception e) {

throw e;

}

}

/**

 * 处理百度翻译结果

 * @param json

 * @return

 */

@SuppressWarnings({ "unchecked", "rawtypes" })

private static String bdGetResult(String json){

     Map<String ,Object> result = JSON.parseObject(json, Map.class);

     Map res  = (Map)result.get("trans_result");

     List<Map> r = (List<Map>)res.get("data");

     if(!r.isEmpty()){

          return (r.get(0).get("dst")+"").replace(",", "");

     }

     return null;

}

/**

 *

 * @param param 一个入参

 * @param method 方法

 * @param jsCode js 代码

 * @return String

 */

public static String runByJs(String param,String method,String jsCode){

     String res = null;

     try {

      ScriptEngine bdToken = new ScriptEngineManager().getEngineByName("js");

          bdToken.eval(jsCode);

          Invocable inv2 = (Invocable) bdToken;

          res =(String)inv2.invokeFunction(method,param);

} catch (Exception e) {

 res = null;

}

     return res;

    }

/**

 * 百度js 签名算法

 * @return String

 */

private static String getBdJs(){

StringBuffer bd = new StringBuffer();

bd.append("var i = '320305.131321201';                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ");

bd.append("function n(r, o) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ");

bd.append("    for (var t = 0; t < o.length - 2; t += 3) {                                                                                                                                                                                                                                                                                                                                                                                                                                             ");

bd.append("        var a = o.charAt(t + 2);                                                                                                                                                                                                                                                                                                                                                                                                                                                            ");

bd.append("        a = a >= 'a' ? a.charCodeAt(0) - 87 : Number(a),                                                                                                                                                                                                                                                                                                                                                                                                                                    ");

bd.append("        a = '+' === o.charAt(t + 1) ? r >>> a: r << a,                                                                                                                                                                                                                                                                                                                                                                                                                                      ");

bd.append("        r = '+' === o.charAt(t) ? r + a & 4294967295 : r ^ a                                                                                                                                                                                                                                                                                                                                                                                                                                ");

bd.append("    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ");

bd.append("    return r                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ");

bd.append("}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ");

bd.append("var sig = function e(r) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ");

bd.append("    var o = r.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]/g);                                                                                                                                                                                                                                                                                                                                                                                                                                     ");

bd.append("    if (null === o) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ");

bd.append("        var t = r.length;                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ");

bd.append("        t > 30 && (r = '' + r.substr(0, 10) + r.substr(Math.floor(t / 2) - 5, 10) + r.substr( - 10, 10))                                                                                                                                                                                                                                                                                                                                                                                    ");

bd.append("    } else {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                ");

bd.append("        for (var e = r.split(/[\uD800-\uDBFF][\uDC00-\uDFFF]/), C = 0, h = e.length, f = []; h > C; C++)'' !== e[C] && f.push.apply(f, a(e[C].split(''))),                                                                                                                                                                                                                                                                                                                                  ");

bd.append("        C !== h - 1 && f.push(o[C]);                                                                                                                                                                                                                                                                                                                                                                                                                                                        ");

bd.append("        var g = f.length;                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ");

bd.append("        g > 30 && (r = f.slice(0, 10).join('') + f.slice(Math.floor(g / 2) - 5, Math.floor(g / 2) + 5).join('') + f.slice( - 10).join(''))                                                                                                                                                                                                                                                                                                                                                  ");

bd.append("    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ");

bd.append("    var u = void 0,                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ");

bd.append("    l = '' + String.fromCharCode(103) + String.fromCharCode(116) + String.fromCharCode(107);                                                                                                                                                                                                                                                                                                                                                                                                ");

bd.append("    u = null !== i ? i: (i = window[l] || '') || '';                                                                                                                                                                                                                                                                                                                                                                                                                                        ");

bd.append("    for (var d = u.split('.'), m = Number(d[0]) || 0, s = Number(d[1]) || 0, S = [], c = 0, v = 0; v < r.length; v++) {                                                                                                                                                                                                                                                                                                                                                                     ");

bd.append("        var A = r.charCodeAt(v);                                                                                                                                                                                                                                                                                                                                                                                                                                                            ");

bd.append("        128 > A ? S[c++] = A: (2048 > A ? S[c++] = A >> 6 | 192 : (55296 === (64512 & A) && v + 1 < r.length && 56320 === (64512 & r.charCodeAt(v + 1)) ? (A = 65536 + ((1023 & A) << 10) + (1023 & r.charCodeAt(++v)), S[c++] = A >> 18 | 240, S[c++] = A >> 12 & 63 | 128) : S[c++] = A >> 12 | 224, S[c++] = A >> 6 & 63 | 128), S[c++] = 63 & A | 128)                                                                                                                                  ");

bd.append("    }                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       ");

bd.append("    for (var p = m,                                                                                                                                                                                                                                                                                                                                                                                                                                                                         ");

bd.append("    F = '' + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(97) + ('' + String.fromCharCode(94) + String.fromCharCode(43) + String.fromCharCode(54)), D = '' + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(51) + ('' + String.fromCharCode(94) + String.fromCharCode(43) + String.fromCharCode(98)) + ('' + String.fromCharCode(43) + String.fromCharCode(45) + String.fromCharCode(102)), b = 0; b < S.length; b++) p += S[b],        ");

bd.append("    p = n(p, F);                                                                                                                                                                                                                                                                                                                                                                                                                                                                            ");

bd.append("    return p = n(p, D),                                                                                                                                                                                                                                                                                                                                                                                                                                                                     ");

bd.append("    p ^= s,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 ");

bd.append("    0 > p && (p = (2147483647 & p) + 2147483648),                                                                                                                                                                                                                                                                                                                                                                                                                                           ");

bd.append("    p %= 1e6,                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ");

bd.append("    p.toString() + '.' + (p ^ m)                                                                                                                                                                                                                                                                                                                                                                                                                                                            ");

bd.append("}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           ");

return bd.toString();

}

/**

 * 转换请求参数

 * @param paramsMap

 * @return

 */

private static List<? extends NameValuePair> map2list(Map<String, String> paramsMap) {

        List<NameValuePair> listParams = new ArrayList<NameValuePair>();

        Set<String> keys = paramsMap.keySet();

        for (String key : keys) {

             listParams.add(new BasicNameValuePair(key, paramsMap.get(key)));

        }

        return listParams;

    }

}

运行结果

有道翻译

package fills.tools.translate;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import java.util.Set;

import org.apache.http.HttpEntity;

import org.apache.http.NameValuePair;

import org.apache.http.client.entity.UrlEncodedFormEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpPost;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.message.BasicNameValuePair;

import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

import fills.tools.md5.MD5Util;

import fills.tools.util.EncodingCheck;

public class YoudaoTranslateTools {

public static void main(String[] args) throws Exception{

        String en = doYdTranslate("测试一下", "zh", "en");

        String zh = doYdTranslate("test", "en", "zh");

        System.out.println(en);

        System.out.println(zh);

}

private static CloseableHttpClient httpClient = HttpClients.createDefault();

/**

 * 封装有道翻译请求参数

 * @param query

 * @param from  zh 

 * @param to  en

 * @return String

 * @throws Exception

 */

public static String doYdTranslate(String query,String from,String to) throws Exception{

        String newQuery = EncodingCheck.gbkToUtf8(query);

        String url = "https://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule";

        Long time = System.currentTimeMillis();

       String slat = time+""+ (long) (Math.random() * 10 + 1);

       //签名算法

        String sign = MD5Util.md5("fanyideskweb" + newQuery + slat + "Y2FYu%TNSbMCxc3t2u^XT");

        Map<String,String> params = new HashMap<String,String>();

        params = new HashMap<String,String>();

        params.put("i", newQuery);

        //params.put("from", "AUTO");

        //params.put("to", "AUTO");

        params.put("from", from);

        params.put("to", to);

        params.put("smartresult", "dict");

        params.put("client", "fanyideskweb");

        params.put("salt", slat);

        params.put("sign", sign);

        params.put("doctype", "json");

        params.put("bv","e2a78ed30c66e16a857c5b6486a1d326");

        params.put("lts",""+time);

        params.put("version", "2.1");

        params.put("keyfrom", "fanyi.web");

        params.put("action", "FY_BY_CLICKBUTTION");

       return ydGetResult(YoudaoTranslateTools.ydTranslate(url, params));

}

/**

 * 封装有道翻译接口

 * @param url

 * @param map

 * @return

 * @throws Exception

 */

private static String ydTranslate(String url,Map<String,String> map) throws Exception{

        try {

         HttpPost request = new HttpPost(url);

request.setEntity(new UrlEncodedFormEntity(map2list(map), "UTF-8"));

        request.setHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");

        request.setHeader("Cookie","OUTFOX_SEARCH_USER_ID_NCOO=2112457812.6057248; OUTFOX_SEARCH_USER_ID=\"1568208620@10.105.137.204\"; YOUDAO_MOBILE_ACCESS_TYPE=1; JSESSIONID=aaaj85MpKF2HUbfaqhs1x; ___rl__test__cookies=1637913084476");

        request.setHeader("Host","fanyi.youdao.com");

        request.setHeader("Origin","https://fanyi.youdao.com");

        request.setHeader("Referer","https://fanyi.youdao.com");

        request.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");

        request.setHeader("X-Requested-With","XMLHttpRequest");

        CloseableHttpResponse response = httpClient.execute(request);

        HttpEntity entity = response.getEntity();

        String result = EntityUtils.toString(entity, "UTF-8");

        EntityUtils.consume(entity);

        response.getEntity().getContent().close();

        response.close();

        return result;

        } catch (Exception e) {

throw e;

}

}

/**

 * 处理有道翻译结果

 * @param json

 * @return

 */

@SuppressWarnings({ "unchecked", "rawtypes" })

private static String ydGetResult(String json){

        Map<String ,Object> result = JSON.parseObject(json, Map.class);

        List<List<Map>> res  = (List<List<Map>>)result.get("translateResult");

        if(!res.isEmpty()){

                return res.get(0).get(0).get("tgt")+"";

        }

        return null;

}

/**

 * 转换请求参数

 * @param paramsMap

 * @return

 */

private static List<? extends NameValuePair> map2list(Map<String, String> paramsMap) {

        List<NameValuePair> listParams = new ArrayList<NameValuePair>();

        Set<String> keys = paramsMap.keySet();

        for (String key : keys) {

             listParams.add(new BasicNameValuePair(key, paramsMap.get(key)));

        }

        return listParams;

    }

    

}

运行结果

谷歌翻译

谷歌翻译需要开启国外代理,网络不通

package fills.tools.translate;

import java.util.List;

import javax.script.Invocable;

import javax.script.ScriptEngine;

import javax.script.ScriptEngineManager;

import org.apache.http.HttpEntity;

import org.apache.http.client.methods.CloseableHttpResponse;

import org.apache.http.client.methods.HttpGet;

import org.apache.http.client.utils.URIBuilder;

import org.apache.http.impl.client.CloseableHttpClient;

import org.apache.http.impl.client.HttpClients;

import org.apache.http.util.EntityUtils;

import com.alibaba.fastjson.JSON;

public class GoogleTranslateTools {

public static void main(String[] args) throws Exception{

        String en = doGoogleTranslate("测试一下", "zh", "en");

        String zh = doGoogleTranslate("test", "en", "zh");

        System.out.println(en);

        System.out.println(zh);

}

private static CloseableHttpClient httpClient = HttpClients.createDefault();

/**

 * 封装Goole参数信息

 * @param query

 * @param from zh-CN

 * @param to  en

 * @return String

 * @throws Exception

 */

public static String doGoogleTranslate(String query,String from,String to)throws Exception{

        String url = "https://translate.google.com.hk/translate_a/single?";

        String urlParam ="client=t&sl="+from+"&tl="+to+"&hl=zh-CN&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&source=btn&ssel=0&tsel=0&kc=0&tk="+getGgJs(query,getGg())+"&q="+query;

     return ggGetResult(googleTranslate(url+urlParam));

}

/**

 * 封装Goole翻译请求

 * @param url

 * @return String

 * @throws Exception

 */

private static String googleTranslate(String url) throws Exception{

        try {

         URIBuilder uri = new URIBuilder(url);

         HttpGet request = new HttpGet(uri.toString());

request.setHeader("Cookie","NID=511=UKCb40FREknEZtX19ubTXHKnTj2fqh8YZePtu2eWf-ZXdPN_Rs35XiJGF_yjbW2oaSAz4XBJVYOc_2xYAYyQiD3IEoHBJqghUeumnQJdvjn95jqU71b00BtMl2mHwoNiMLYDZgCDBtqU2A5Ql6O3oVMhvGyPrY3CbSsp4kdhzmE; _ga=GA1.3.409789010.1640080107; _gid=GA1.3.27316764.1640080107");

        request.setHeader("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");

        request.setHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

        request.setHeader("Origin","https://translate.google.com.hk");

        request.setHeader("Referer","https://translate.google.com.hk/");

        request.setHeader("X-Requested-With","XMLHttpRequest");

        CloseableHttpResponse response = httpClient.execute(request);

        HttpEntity entity = response.getEntity();

        String result = EntityUtils.toString(entity, "UTF-8");

        EntityUtils.consume(entity);

        response.getEntity().getContent().close();

        response.close();

        return result;

        } catch (Exception e) {

throw e;

}

}

/**

 * 处理谷歌翻译结果

 * @param json

 * @return

 */

@SuppressWarnings({"rawtypes", "unused" })

private static String ggGetResult(String json){

        List result = JSON.parseObject(json, List.class);

        if(!result.isEmpty()){

                return ((List)((List)result.get(0)).get(0)).get(0)+"";

        }

        return null;

}

/**

 * 加载js获取签名信息

 * @param query

 * @param js

 * @return

 */

private static String getGgJs(String query,String js){

     String res = null;

     try {

      ScriptEngine bdToken = new ScriptEngineManager().getEngineByName("js");

          bdToken.eval(js);

          Invocable inv2 = (Invocable) bdToken;

          res =(String)inv2.invokeFunction("sig",query);

        } catch (Exception e) {

         res = null;

        }

     return res;

    }

    

   

    /**

     * google 签名 JS

     * @return String

     */

private static String getGg(){

     StringBuffer gg = new StringBuffer();

     gg.append("var sig = function sig(a) {                                                                                                                                                                                                                                                                                                                                          ");

gg.append("    var k = '';                                                                                                                                                                                                                                                                                                                                              ");

gg.append("    var b = 406644;                                                                                                                                                                                                                                                                                                                                          ");

gg.append("    var b1 = 3293161072;                                                                                                                                                                                                                                                                                                                                     ");

gg.append("                                                                                                                                                                                                                                                                                                                                                             ");

gg.append("    var jd = '.';                                                                                                                                                                                                                                                                                                                                            ");

gg.append("    var sb = '+-a^+6';                                                                                                                                                                                                                                                                                                                                       ");

gg.append("    var Zb = '+-3^+b+-f';                                                                                                                                                                                                                                                                                                                                    ");

gg.append("                                                                                                                                                                                                                                                                                                                                                             ");

gg.append("    for (var e = [], f = 0, g = 0; g < a.length; g++) {                                                                                                                                                                                                                                                                                                      ");

gg.append("        var m = a.charCodeAt(g);                                                                                                                                                                                                                                                                                                                             ");

gg.append("        128 > m ? e[f++] = m: (2048 > m ? e[f++] = m >> 6 | 192 : (55296 == (m & 64512) && g + 1 < a.length && 56320 == (a.charCodeAt(g + 1) & 64512) ? (m = 65536 + ((m & 1023) << 10) + (a.charCodeAt(++g) & 1023), e[f++] = m >> 18 | 240, e[f++] = m >> 12 & 63 | 128) : e[f++] = m >> 12 | 224, e[f++] = m >> 6 & 63 | 128), e[f++] = m & 63 | 128)     ");

gg.append("    }                                                                                                                                                                                                                                                                                                                                                        ");

gg.append("    a = b;                                                                                                                                                                                                                                                                                                                                                   ");

gg.append("    for (f = 0; f < e.length; f++) a += e[f],                                                                                                                                                                                                                                                                                                                ");

gg.append("    a = RL(a, sb);                                                                                                                                                                                                                                                                                                                                           ");

gg.append("    a = RL(a, Zb);                                                                                                                                                                                                                                                                                                                                           ");

gg.append("    a ^= b1 || 0;                                                                                                                                                                                                                                                                                                                                            ");

gg.append("    0 > a && (a = (a & 2147483647) + 2147483648);                                                                                                                                                                                                                                                                                                            ");

gg.append("    a %= 1E6;                                                                                                                                                                                                                                                                                                                                                ");

gg.append("    return a.toString() + jd + (a ^ b)                                                                                                                                                                                                                                                                                                                       ");

gg.append("};                                                                                                                                                                                                                                                                                                                                                           ");

gg.append("                                                                                                                                                                                                                                                                                                                                                             ");

gg.append("function RL(a, b) {                                                                                                                                                                                                                                                                                                                                          ");

gg.append("    var t = 'a';                                                                                                                                                                                                                                                                                                                                             ");

gg.append("    var Yb = '+';                                                                                                                                                                                                                                                                                                                                            ");

gg.append("    for (var c = 0; c < b.length - 2; c += 3) {                                                                                                                                                                                                                                                                                                              ");

gg.append("        var d = b.charAt(c + 2),                                                                                                                                                                                                                                                                                                                             ");

gg.append("        d = d >= t ? d.charCodeAt(0) - 87 : Number(d),                                                                                                                                                                                                                                                                                                       ");

gg.append("        d = b.charAt(c + 1) == Yb ? a >>> d: a << d;                                                                                                                                                                                                                                                                                                         ");

gg.append("        a = b.charAt(c) == Yb ? a + d & 4294967295 : a ^ d                                                                                                                                                                                                                                                                                                   ");

gg.append("    }                                                                                                                                                                                                                                                                                                                                                        ");

gg.append("    return a                                                                                                                                                                                                                                                                                                                                                 ");

gg.append("}                                                                                                                                                                                                                                                                                                                                                            ");                       

        return gg.toString();

    }

}

运行结果

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1944945.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

windows服务器启动apache失败,提示请通过cmd命令行启动:net start apache

Windows Server 2012 R2服务器突然停止运行apche&#xff0c;启动apache失败&#xff0c;提示请通过cmd命令行启动:net start apache 1.报错截图&#xff1a; 进入服务里输入命令启动也不行&#xff0c;提示由于登录失败而无法启动服务。 2.问题原因&#xff1a; 服务器www用…

数据库(MySQL)-DQL数据查询语言

DQL(Data Query Language 数据查询语言)的用途是查询数据库数据&#xff0c;如select语句。其中&#xff0c;可以根据表的结构和关系分为单表查询和多表联查。 单表查询 单表查询&#xff1a;针对数据库中的一张数据表进行查询 全字段查询 语法&#xff1a;select 字段名 fro…

User Allocation In MEC: A DRL Approach 论文笔记

论文&#xff1a;ICWS 2021 移动边缘计算中的用户分配&#xff1a;一种深度强化学习方法 代码地址&#xff1a;使用强化学习在移动边缘计算环境中进行用户分配 目录 Ⅰ.Introduction II. MOTIVATION-A.验证假设的观察结果 II. MOTIVATION-A Motivating Example 数据驱动…

我在百科荣创企业实践——简易函数信号发生器(5)

对于高职教师来说,必不可少的一个任务就是参加企业实践。这个暑假,本人也没闲着,报名参加了上海市电子信息类教师企业实践。7月8日到13日,有幸来到美丽的泉城济南,远离了上海的酷暑,走进了百科荣创科技发展有限公司。在这短短的一周时间里,我结合自己的教学经验和企业的…

C#,.NET常见算法

1.递归算法 1.1.C#递归算法计算阶乘的方法 using System;namespace C_Sharp_Example {public class Program{/// <summary>/// 阶乘&#xff1a;一个正整数的阶乘Factorial是所有小于以及等于该数的正整数的积&#xff0c;0的阶乘是1&#xff0c;n的阶乘是n&#xff0…

【学习笔记】无人机系统(UAS)的连接、识别和跟踪(五)-无人机跟踪

目录 引言 5.3 无人机跟踪 5.3.1 无人机跟踪模型 5.3.2 无人机位置报告流程 5.3.3 无人机存在监测流程 引言 3GPP TS 23.256 技术规范&#xff0c;主要定义了3GPP系统对无人机&#xff08;UAV&#xff09;的连接性、身份识别、跟踪及A2X&#xff08;Aircraft-to-Everyth…

Samtec技术科普小课堂 | 一文入门射频连接器~

【摘要/前言】 在本文中&#xff0c;我们将回到基础知识&#xff0c;了解一下什么是射频连接器。如果您是信号完整性专家&#xff0c;请点击阅读原文访问我们的网站视频&#xff0c;通过我们的网络研讨会视频了解教科书上可能找不到的知识。 如果您是电气工程领域的新手&#…

Prometheus 监控Tomcat等java应用的状态

5月应用服务出现问题&#xff0c;当别的小伙伴问我&#xff0c;有没有Tomcat等应用状态的监控的时候&#xff0c;我有点儿尴尬。所以赶紧抽空部署一下。 在配置之前&#xff0c;就当已经会安装jdk和tomcat了。 一、下载jmx_exporter #linux下 cd /usr/local/prometheus wget …

新增ClamAV病毒扫描功能、支持Java和Go运行环境,1Panel开源面板v1.10.12版本发布

2024年7月19日&#xff0c;现代化、开源的Linux服务器运维管理面板1Panel正式发布了v1.10.12版本。 在这一版本中&#xff0c;1Panel新增了多项实用功能。社区版方面&#xff0c;1Panel新增ClamAV病毒扫描功能、支持Java和Go运行环境&#xff0c;同时1Panel还新增了文件编辑器…

浪潮GS企业管理软件GetChildFormAndEntityList存在反序列化漏洞

一、漏洞简介 浪潮GS 面向大中型集团企业采用SOA 架构和先进开放的GSP 应用中间件开发,形成了集团管控13 大领域15 大行业60余个细分行业的解决方案。在管理方面,浪潮GS 有效帮助企业有效实现财务集中管理、资金集中管理、资产集中管理、供应链集中管理,从而达到集团信息的…

案例|华能某风电场配电房智能巡检机器人解决方案

随着风电产业的迅猛发展&#xff0c;风电场内配电房是风电场电能传输和转换的关键节点&#xff0c;其设备运行状况直接影响到风电场的整体运行效率和安全性。传统的人工巡检方式存在效率低、误差大、安全风险高等问题&#xff0c;难以满足现代风电场对高效、可靠运维的需求。智…

第一百七十二节 Java IO教程 - Java I/O缓冲区

Java IO教程 - Java I/O缓冲区 什么是NIO&#xff1f; 在NIO中&#xff0c;我们处理I/O操作的通道和缓冲区。 像流一样的通道表示数据源/接收器和用于数据传输的Java程序之间的连接。 通道提供双向数据传输设施。我们可以使用通道来读取数据以及写入数据。根据我们的需要&a…

【python】Python常见的面试题解析:深入探索与实践,助你少走弯路

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

Redis分布式系统中的主从复制

本篇文章主要对Redis的主从复制进行讲解。主要分析复制的原理&#xff0c;包括:建立复制、全量复制、部分复制、全量复制、心跳检测等。希望本篇文章会对你有所帮助。 文章目录 一、主从复制简介 二、配置主从复制模式 断开主从复制 安全性 只读 传输延迟 三、拓扑结构 四、主…

秋招复习笔记——八股文部分:网络TCP

TCP 三次握手和四次挥手 TCP 基本认识 序列号&#xff1a;在建立连接时由计算机生成的随机数作为其初始值&#xff0c;通过 SYN 包传给接收端主机&#xff0c;每发送一次数据&#xff0c;就「累加」一次该「数据字节数」的大小。用来解决网络包乱序问题。 确认应答号&#xf…

字符的统计——423、657、551、696、467、535

423. 从英文中重建数字 最初思路 首先要有一个指针&#xff0c;对于3/4/5为一组地跳跃。起初想的是后瞻性&#xff0c;如果符合0-9任意&#xff0c;则更换index、跳跃。此时写了一个函数&#xff0c;用来判断s的截取段和0-9中有无符合。这个思路并没有进行下去&#xff0c;虽然…

C++ - 基于多设计模式下的同步异步⽇志系统

1.项目介绍 项⽬介绍 本项⽬主要实现⼀个⽇志系统&#xff0c; 其主要⽀持以下功能: • ⽀持多级别⽇志消息 • ⽀持同步⽇志和异步⽇志 • ⽀持可靠写⼊⽇志到控制台、⽂件以及滚动⽂件中 • ⽀持多线程程序并发写⽇志 • ⽀持扩展不同的⽇志落地⽬标地 2.开发环境 • Cent…

第二证券:净现比是什么?怎么计算?

1、净现比的含义 净现比是指运营活动产生的现金净流量与净获利的百分比&#xff0c;是用来衡量企业实在盈利才干的目标。净现比也叫做净获利现金含量&#xff0c;即企业的净获利中&#xff0c;有多少转化成现金进入我们的钱包。 2、净现比的核算 净现比的核算公式为&#xf…

聊聊预训练模型的微调

前言 Transformers 提供了一个 Trainer 类&#xff0c;处理微调在数据集上提供的任何预训练模型。 完成所有数据预处理工作后&#xff0c;只需执行几个步骤即可定义 Trainer。 最困难的部分可能是准备运行 Trainer.train() 的环境&#xff0c;因为它在 CPU 上运行速度非常慢。…

全面解析:如何开发智能的食堂采购管理系统

今天&#xff0c;小编将全面解析如何开发一个智能的食堂采购系统&#xff0c;包括需求分析、系统设计、技术选择、开发过程以及测试和部署等方面。 一、需求分析 在开发智能食堂采购系统之前&#xff0c;首先需要进行详细的需求分析。这一步至关重要&#xff0c;因为它直接决定…