传参用postman提交参数接口正常的很。.net的同事调用却是乱码:
.net代码如下:
我的接口代码:
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); }
项目:JFinal