(已解决)我要开裂了,传参乱码问题!

image.png


传参用postman提交参数接口正常的很。.net的同事调用却是乱码:

image.png

.net代码如下:

image.png

我的接口代码:

public void addUser() throws UnsupportedEncodingException {
    logger.info("addUser 添加账号 传参信息:" );
    //System.out.println("addUser 添加账号 传参信息:" + JSON.toJSON(getParaMap()));
    String username = getPara("username", "");//姓名
    logger.info("username: " + username);
   // logger.info("================");
    logger.info(URLDecoder.decode(getPara("username"),"UTF-8"));
    logger.info(URLDecoder.decode(getPara("username"),"gb2312"));
    logger.info(URLDecoder.decode(getPara("username"),"GBK"));
    logger.info(URLDecoder.decode(getPara("username"),"iso8859_1"));
    logger.info("================");
    // username = URLDecoder.decode(username, "GBK");
    logger.info("iso8859_1: " + new String(getPara("username").getBytes("iso8859_1"),"GBK"));
    logger.info("GBK: " + new String(getPara("username").getBytes("GBK"),"GBK"));
    logger.info("gb2312: " + new String(getPara("username").getBytes("gb2312"),"GBK"));
    logger.info("UTF-8: " + new String(getPara("username").getBytes("UTF-8"),"GBK"));

    logger.info("iso8859_1 2: " + new String(getPara("username").getBytes("iso8859_1"),"UTF-8"));
    logger.info("GBK 2: " + new String(getPara("username").getBytes("GBK"),"UTF-8"));
    logger.info("gb2312 2: " + new String(getPara("username").getBytes("gb2312"),"UTF-8"));
    logger.info("UTF-8 2: " + new String(getPara("username").getBytes("UTF-8"),"UTF-8"));
    /*logger.info("UTF-8: " + URLDecoder.decode(username, "UTF-8"));
    logger.info("gb2312: " + URLDecoder.decode(username, "gb2312"));
    String test = username.replaceAll("%(?![0-9a-fA-F]{2})", "%25");
    logger.info("test: " + URLDecoder.decode(test, "UTF-8"));*/

    String accnum = forSix(getPara("accnum", ""));//账套编号

    String phone = getPara("phone", "");//手机号
    String pwd = getPara("pwd", "");//pwd
    String token = getPara("token", "");//token
    String groupname = getPara("groupname", "0_0");//角色
    logger.info("groupname: " + groupname);
    if (!groupname.contains("_")) {
        groupname = "0_0";
    }
    List<String> listsg = java.util.Arrays.asList(groupname.split("_"));
    Ret ret = Ret.create();
    if (checkTokenDate(token)) {
        //通过
        //判断账号是否存在
        String loginIp = IpKit.getRealIp(getRequest());
        ret = RegService.me.reg(phone, username, "123123", 0, Integer.valueOf(listsg.get(0)), new String[]{accnum}, loginIp, pwd);
        if (ret.isFail() && ret.getBoolean("have")) {
            int accountId = Db.queryInt("select id from account where userName = ? limit 1", phone);
            //添加对应的账号
            Db.update("DELETE FROM `account_company` WHERE `accountId` = ? And `companyId` = ?", accountId, accnum);
            List<Record> lists = Db.find("SELECT a.companyId, a.companycode, a.tshortname FROM `v_latestNT` a LEFT JOIN v_prepareCompany b ON companyId = b.id WHERE isSync = 1 AND companycode = ?", accnum);
            if (lists.size() > 0) {
                AccountCompany accountCompany = new AccountCompany();
                accountCompany.setAccountId(accountId);
                accountCompany.setCompanyId(accnum);
                accountCompany.save();
                ret.set("State", "success");
                ret.set("Msg", "用户:" + username + "  账套;" + accnum + ",账套编码添加成功!");
                ret.set("Code", 0);
            } else {
                ret.set("State", "error");
                ret.set("Msg", accnum + " 账套编码不存在!");
                ret.set("Code", 1111);
            }

        } else if (ret.isFail()) {
            ret.set("State", "error");
            ret.set("Msg", ret.getStr("msg"));
            ret.set("Code", 1111);
        } else if (ret.isOk()) {
            ret.set("State", "success");
            ret.set("Msg", ret.getStr("msg"));
            ret.set("Code", 0);
        } else {
            ret.set("State", "error");
            ret.set("Msg", "未知异常");
            ret.set("Code", 1111);
            renderJson(ret);
        }
    } else {
        ret.set("State", "error");
        ret.set("Msg", "token 不正确");
        ret.set("Code", 1003);
        renderJson(ret);
    }
    renderJson(ret);
}


评论区

zzutligang

2021-02-22 15:56

字符集,字符集,字符集!重要的事情说三遍!

超级大富

2021-02-22 15:59

可以让.net 工程师把编码格式改为GBK 试下,怀疑是后端编译采用的是GBK

fmpoffice

2021-02-22 16:33

@zzutligang 字符集,我要怎么搞?

fmpoffice

2021-02-22 17:02

搞掂了,升级jfianl和jfinal-undertow

zzutligang

2021-02-24 15:09

建议把所有字符集都统一成utf8,微软很气蛋,总是默认gbk或则iso8859-1

热门反馈

扫码入社