/**
* 测试的返回JSon方法,正式的不会用
* @author MrHandler
* @param reqCode
* @param joinStr
* @return
*/
public static String getBasicJsonStrTest(int reqCode,String joinStr){
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\","+joinStr);
jsonStr.append("}}");
return jsonStr.toString();
}
/**
* 返回基本的JSon格式的信息
* 示例
{
"outParam": {
"reqCode": "551291",
"reqBak": "特约绑定必须先绑定设备",
"respTime": "2014-12-17 13:52:53"
}
}
* @param reqCode 返回码
* @return
*/
public static String getBasicJsonStr(int reqCode,String bak){
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
if(bak != null && !"".equals(bak)){
jsonStr.append("\"reqBak\":"+"\""+bak+"\",");
}else{
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
}
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\"");
jsonStr.append("}}");
return jsonStr.toString();
}
/**
* 生成JSon
* 示例
{
"outParam": {
"reqCode": "551291",
"reqBak": "特约绑定必须先绑定设备",
"respTime": "2014-12-17 13:52:53",
"life": {
"x": "1",
"y": "2",
"lifeList": [
{
"goodsId": "id1",
"goodsTitle": "标题1",
"goodsImg": "图片1",
"goodsCount": "1"
},
{
"goodsId": "id2",
"goodsTitle": "标题2",
"goodsImg": "图片2",
"goodsCount": "2"
}
]
}
}
}
* @param reqCode 返回码
* @param fields 返回字段
* @param lists 返回集合
* @param clz 对象
* @supFields 集合要新增的字段 可以为空
* @supFieldsVal 对应集合要新增的字段值 可以为空
* @return
* @throws Exception
*/
public static String getJsonStr(int reqCode,Object[] fields,List<?> lists,Class<?> clz,Object[] supFields,Object[] supFieldsVal) throws Exception{
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\",");
jsonStr.append("\"life\":{");
//对象信息
if(supFields != null && supFields.length> 0){
for (int i = 0; i < supFields.length; i++) {
if(i == supFields.length - 1){
if(lists != null && lists.size() > 0){
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\"");
}
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}
}
}
if(lists != null && lists.size() > 0){
jsonStr.append("\"lifeList\":[");
for (int i=0;i<lists.size();i++) {
jsonStr.append("{");
Object val = lists.get(i);
for (int j = 0; j < fields.length; j++) {//字段
String methodStr = fields[j].toString();
Method m = clz.getDeclaredMethod("get"+methodStr.substring(0,1).toUpperCase() + methodStr.substring(1));
Object rel = m.invoke(val);//对象调用值
if(rel == null){//针对获取的值进行处理
rel = "";
}
if(j == fields.length -1){
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\"");
}else{
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\",");
}
}
if(i == lists.size()-1){
jsonStr.append("}");
}else{
jsonStr.append("},");
}
}
jsonStr.append("]");
}
jsonStr.append("}}}");
return jsonStr.toString();
}
/**
* @param reqCode 返回码
* @param ObjectJson 对象JSON
* @return
* @throws Exception
*/
public static String getJsonStr(int reqCode,Object object) throws Exception{
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\",");
if(object!= null){
jsonStr.append("\"life\":"+toJSONString(object));
}
jsonStr.append("}}");
return jsonStr.toString();
}
/**
* 对象里面包含集合
* @author MrHandler
* @param reqCode 返回码
* @param listFields 返回的字段
* @param lists 数据
* @param listClzs 实体类Class
* @supFields 集合要新增的字段 可以为空
* @supFieldsVal 对应集合要新增的字段值 可以为空
* @return
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String getJsonStrByObjectToList(int reqCode,List<Object[]> listFields,List<?> lists,List<Class<?>> listClzs,
Object[] supFields,Object[] supFieldsVal) throws Exception{
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\",");
jsonStr.append("\"life\":{");
//对象信息
if(supFields != null && supFields.length> 0){
for (int i = 0; i < supFields.length; i++) {
if(i == supFields.length - 1){
if(lists != null && lists.size() > 0){
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\"");
}
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}
}
}
if(lists != null && lists.size() > 0){
jsonStr.append("\"lifeList\":[");
for (int i=0;i<lists.size();i++) {
jsonStr.append("{");
Object val = lists.get(i);
Object[] fields = listFields.get(0);//主字段
Class clz = listClzs.get(0); //主对象
for (int j = 0; j < fields.length; j++) {//字段
String methodStr = fields[j].toString();
Method m = clz.getDeclaredMethod("get"+methodStr.substring(0,1).toUpperCase() + methodStr.substring(1));
Object rel = m.invoke(val);//对象调用值
if(rel == null){//针对获取的值进行处理
rel = "";
}
if(rel instanceof List<?>){//对象里面包含集合
int f =0;
Iterator iterator = ((List) rel).listIterator();
jsonStr.append("\""+methodStr+"\":[");
while (iterator.hasNext()) {
jsonStr.append("{");
Object val2=iterator.next();//对象
for (int k = 1; k < listClzs.size(); k++) {
Class subClz = listClzs.get(k);
if(val2.getClass().equals(subClz)){//需要反射的子对象
//遍历对象里面的集合
/* String className = subClz.getName();
className = className.substring(0,1).toLowerCase()+className.substring(1)+"List";*/
Object[] subFields = listFields.get(k);
for (int h = 0;h < subFields.length; h++) {
String methodStr2 = subFields[h].toString();
Method m2 = subClz.getDeclaredMethod("get"+methodStr2.substring(0,1).toUpperCase() + methodStr2.substring(1));
Object rel2 = m2.invoke(val2);//对象调用值
if(rel2==null){
rel2 = "";
}
if(h == subFields.length -1){
jsonStr.append("\""+methodStr2+"\":"+"\""+rel2+"\"");
}else{
jsonStr.append("\""+methodStr2+"\":"+"\""+rel2+"\",");
}
}
}
}
//要判断是否是最后一个字段
if( f==((List) rel).size()-1){
//要判断是否是最后一个字段
jsonStr.append("}");//这是否有多个信息
}else{
//要判断是否是最后一个字段
jsonStr.append("},");//这是否有多个信息
}
f++;
}
jsonStr.append("]");//这是否有多个信息
}else{
if(j == fields.length -1){
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\"");
}else{
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\",");
}
}
}
if(i == lists.size()-1){
jsonStr.append("}");
}else{
jsonStr.append("},");
}
}
jsonStr.append("]");
}
jsonStr.append("}}}");
return jsonStr.toString();
}
/**
* 针对所有的公共的生成JSon格式
* @author MrHandler
* @param reqCode 返回码
* @param mapFields 返回字段
* @param mapLists 返回的集合
* @param mapClzs 返回的映射类
* @param supFields 集合要新增的字段 可以为空
* @param supFieldsVal 对应集合要新增的字段值 可以为空
* @return
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String getJsonStrByMap(int reqCode,Map<String, Object[]> mapFields,Map<String, List> mapLists,Map<String,Class> mapClzs,Object[] supFields,Object[] supFieldsVal) throws Exception{
StringBuffer jsonStr = new StringBuffer();
jsonStr.append("{\"outParam\":{");
jsonStr.append("\"reqCode\":"+"\""+reqCode+"\",");
jsonStr.append("\"reqBak\":"+"\""+CodeSettingsSkil.getErrorCodeDesc(String.valueOf(reqCode))+"\",");
jsonStr.append("\"respTime\":"+"\""+WebServiceValidate.getCurrentStr()+"\",");
jsonStr.append("\"life\":{");
//对象信息
if(supFields != null && supFields.length> 0){
for (int i = 0; i < supFields.length; i++) {
if(i == supFields.length - 1){
if(mapLists != null && mapLists.size() > 0){
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\"");
}
}else{
jsonStr.append("\""+supFields[i]+"\":"+"\""+supFieldsVal[i]+"\",");
}
}
}
if(mapLists != null && mapLists.size() > 0){
int count=0;
for(Object mn: mapLists.keySet()){
String jsonElement =mn.toString();
jsonStr.append("\""+jsonElement+"\":[");
List lists = mapLists.get(mn);
for (int i=0;i<lists.size();i++) {
jsonStr.append("{");
Object val = lists.get(i);
Object[] fields = mapFields.get(jsonElement);
Class clz = mapClzs.get(jsonElement);
for (int j = 0; j < fields.length; j++) {//字段
String methodStr = fields[j].toString();
Method m = clz.getDeclaredMethod("get"+methodStr.substring(0,1).toUpperCase() + methodStr.substring(1));
Object rel = m.invoke(val);//对象调用值
if(rel == null){//针对获取的值进行处理
rel = "";
}
if(j == fields.length -1){
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\"");
}else{
jsonStr.append("\""+methodStr+"\":"+"\""+rel+"\",");
}
}
if(i == lists.size()-1){
jsonStr.append("}");
}else{
jsonStr.append("},");
}
}
count++;
if(count == mapLists.size()){
jsonStr.append("]");
}else{
jsonStr.append("],");
}
}
}
jsonStr.append("}}}");
return jsonStr.toString();
}
public static String getEncoding(String str) {
String encode = "GB2312";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { //判断是不是GB2312
String s = encode;
return s; //是的话,返回“GB2312“,以下代码同理
}
} catch (Exception exception) {
}
encode = "ISO-8859-1";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { //判断是不是ISO-8859-1
String s1 = encode;
return s1;
}
} catch (Exception exception1) {
}
encode = "UTF-8";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { //判断是不是UTF-8
String s2 = encode;
return s2;
}
} catch (Exception exception2) {
}
encode = "GBK";
try {
if (str.equals(new String(str.getBytes(encode), encode))) { //判断是不是GBK
String s3 = encode;
return s3;
}
} catch (Exception exception3) {
}
return ""; //如果都不是,说明输入的内容不属于常见的编码格式。
}
/**
*
* @param param 请求参数
* @param reqCode 请求码
* @param arr 需要验证的参数
* @param encType 验签方式 md5 1001 rsa 1002
* @return
* @throws JSONException
* @throws UnsupportedEncodingException
*/
@SuppressWarnings("unused")
public static Map<String,String> reqJsonStr(String reqCode[],String arr[],String encType,HttpServletRequest request) throws JSONException, UnsupportedEncodingException{
MallPublicMethod method = new MallPublicMethod();
String met = request.getMethod();
if("GET".equals(met)){
return returnParam(new String[]{"result", "msg"}, new String[]{"1003", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551000)});
}
request.setCharacterEncoding("UTF-8");
String inParam =request.getParameter("encryptionParam");
//String str1 =TransferDecUtil.byteArrayToHexString(inParam.getBytes());
String sign = request.getParameter("sign");
if(inParam ==null || "".equals(inParam) || sign==null || "".equals(sign)){
return returnParam(new String[]{"result", "msg"}, new String[]{"1003", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551002)});
}
if(arr != null && arr.length>0){
StringBuffer str = new StringBuffer();
for (int i = 0; i < arr.length; i++) {
str.append(arr[i]);
}
}
try{
JSONObject jsonObject = new JSONObject(inParam);
//inParam=inParam.replace("\\n", "\\\\n");
String code = jsonObject.get("reqCode").toString();
String memberNo = jsonObject.get("memberNo").toString();
String reqTime = jsonObject.get("reqTime").toString();
String osName = jsonObject.get("osName").toString();
String version = jsonObject.get("version").toString();
// String sign = jsonObject.get("sign").toString();
// 判断客户端请求方式
String reqMethod = request.getMethod().toLowerCase();
// 验证请求参数是否为空
int checkReqParam = checkReqParam(code, inParam, sign, reqCode, osName,memberNo, reqMethod);
if (1001!=checkReqParam) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(checkReqParam),memberNo,osName});
}
//memberNo = convertMemberNo(memberNo);
String memPhone ="";
String memArr[] =convertMemberNoNew(memberNo);
memberNo=memArr[2].toString();
if("1002".equals(memArr[0].toString())){
memPhone =memArr[1].toString();
}
// if(isType!=1001){
if(true){
//如果是加密的要先解密
// 解密出来的请求数据
String encryptionData = null;
if ("1001".equals(encType)) {
// MD5方式 加密
encryptionData = method.serverMd5Verify(inParam,memberNo, sign);
} else if ("1002".equals(encType)) { // Rsa方式加密
encryptionData = method.serverDecAndSign(inParam,memberNo, osName, sign);
}
if ("1002".equals(encryptionData)) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551037),memberNo,osName});
// 验签失败
} else if ("1003".equals(encryptionData)) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551035),memberNo,osName});
// 解密失败
} else if ("1004".equals(encryptionData)) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551036),memberNo,osName});
}else if ("1005".equals(encryptionData)) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551046),memberNo,osName});
}
// 验证会员账号
int checkMemberNo = MallPublicMethod.checkMemberNoJson(memberNo);
if (1001 !=checkMemberNo) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(checkMemberNo),memberNo,osName});
}
// 验证版本号
String checkVersion = MallPublicMethod.checkVersionJson(osName, version);
if (!"1001".equals(checkVersion)) {
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(checkVersion),memberNo,osName});
}
}
JSONObject reqParam=null;
//判断入参是否一致
if(arr != null && arr.length>0 ){
inParam=inParam.replace("\\n", "\\\\n");
jsonObject=null;
jsonObject = new JSONObject(inParam);
reqParam = jsonObject.getJSONObject("reqParam");
// String str1 =TransferDecUtil.byteArrayToHexString(reqParam.toString().getBytes());
for (int i = 0; i < arr.length; i++) {
String val=reqParam.get(arr[i]).toString();
if(val==null){
return returnParam(new String[]{"result", "msg","memberNo","osName"}, new String[]{"1002", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551011),memberNo,osName});
}
}
}
String[] keyArray = new String[30];
String[] valArray = new String[30];
keyArray[0] = "result";
valArray[0] = "1001";
keyArray[1] = "msg";
valArray[1] = "";
keyArray[2] = "version";
valArray[2] = version;
keyArray[3] = "memberNo";
valArray[3] = memberNo;
keyArray[4] = "osName";
valArray[4] = osName;
keyArray[5] = "sign";
valArray[5] = sign;
keyArray[6] = "reqCode";
valArray[6] = code;
keyArray[7] = "loginType";
valArray[7] = memArr[0].toString();
keyArray[8] = "memPhone";
valArray[8] = memPhone;
if(arr != null && arr.length>0){
int i = 9;
for (String string : arr) {
keyArray[i] = string;
valArray[i] = reqParam.get(string).toString();
i++;
}
}
return returnParam(keyArray, valArray);
}catch (Exception e) {
e.printStackTrace();
return returnParam(new String[]{"result", "msg"}, new String[]{"1003", String.valueOf(CodeSettings.MALL_INTERFACE_RESPONSECODE551567)});
}
}
public static Map<String, String> returnParam(String[] key, String[] values){
Map<String, String> map = new HashMap<String, String>();
for (int i = 0; i < values.length; i++) {
map.put(key[i], values[i]);
}
return map;
}
/**
* 验证请求参数是否为空
* @param reqCode
* @param encParam
* @param sign
* @param reqCodeLocal
* @param osName
* @param memberNo
* @return
*/
public static int checkReqParam(String reqCode , String encParam , String sign ,
String reqCodeLocal[] , String osName , String memberNo, String reqMethod){
if(reqCode == null || "".equals(reqCode)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551011 ;
}
if(encParam == null || "".equals(encParam)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551011;
}
if(sign == null || "".equals(sign)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551011 ;
}
int i = 0;
for (String string : reqCodeLocal) {
if(reqCode.equals(string)){
i++;
}
}
if(i == 0){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551012;
}
if(osName == null || "".equals(osName)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551012;
}
if(memberNo == null || "".equals(memberNo)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551012;
}
if(!"1001".equals(osName) && !"1002".equals(osName) && !"1003".equals(osName) && !"1004".equals(osName)){
return CodeSettings.MALL_INTERFACE_RESPONSECODE551012;
}
if (!"post".equals(reqMethod)) {
return CodeSettings.MALL_INTERFACE_RESPONSECODE551039;
}
return 1001;
}
private static NodeList initStart(String protocolXML, String tagName) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); //实例化一个文档构建器工厂
DocumentBuilder builder = factory.newDocumentBuilder(); //通过文档构建器工厂获取一个文档构建器
Document doc = builder.parse(new InputSource(new StringReader(protocolXML))); //通过文档通过文档构建器构建一个文档实例
Element root = doc.getDocumentElement();
NodeList n = root.getElementsByTagName(tagName); //获取所有名字为 tagName 的节点
return n;
}
/**
* 公共的节点处理信息
* @param n
* @param i
* @return
*/
private static String[] publicNode(NodeList n, int i) {
Node book = n.item(i);
NodeList nl2 = book.getChildNodes();//此处值得注意,在DOM解析时会将所有回车都视为 n 节点的子节点。
String[] obj = new String[nl2.getLength()];
for (int j = 0; j < nl2.getLength(); j++) {
Node n2 = nl2.item(j);
NodeList nms = n2.getChildNodes();
String val = nms.item(0).getTextContent();
obj[j] = val;
}
return obj;
}
/**
* 读取商品保障信息
* @author MrHandler
* @param xml
* @return
*/
public static List<Guarantee> readGuaranteeXML(String xml) {
List<Guarantee> lists;
try {
lists = new ArrayList<Guarantee>();
NodeList n = initStart(xml, "guarantee");
if (n == null) {
return null;
}
for (int i = 0; i < n.getLength(); i++) {
String[] obj = publicNode(n, i);
lists.add(new Guarantee(Integer.parseInt(obj[0]), obj[1], obj[2]));
}
}catch (Exception e) {
e.printStackTrace();
return null;
}
return lists;
}
/**
* 获取商品详情对象
* @author MrHandler
* @param xmlMsg
* @return
*/
public static Object[] getGoodsDeatil(String xmlMsg){
Object[] returnObject = new Object[2];
Goods g = new Goods();
int goodsId1 = xmlMsg.indexOf("<goodsId>");
int goodsId2 = xmlMsg.indexOf("</goodsId>");
String goodsId = xmlMsg.substring(goodsId1+"<goodsId>".length(), goodsId2);
g.setGoodsId(goodsId);
int oldStateStr1 = xmlMsg.indexOf("<oldStateStr>");
int oldStateStr2 = xmlMsg.indexOf("</oldStateStr>");
String oldStateStr = xmlMsg.substring(oldStateStr1+"<oldStateStr>".length(), oldStateStr2);
g.setOldStateStr(oldStateStr);
int goodsTitle1 = xmlMsg.indexOf("<goodsTitle>");
int goodsTitle2 = xmlMsg.indexOf("</goodsTitle>");
String goodsTitle = xmlMsg.substring(goodsTitle1+"<goodsTitle>".length(), goodsTitle2);
g.setGoodsTitle(goodsTitle);
int goodsName1 = xmlMsg.indexOf("<goodsName>");
int goodsName2 = xmlMsg.indexOf("</goodsName>");
String goodsName = xmlMsg.substring(goodsName1+"<goodsName>".length(), goodsName2);
g.setGoodsName(goodsName);
int prefecture1 = xmlMsg.indexOf("<prefecture>");
int prefecture2 = xmlMsg.indexOf("</prefecture>");
String prefecture = xmlMsg.substring(prefecture1+"<prefecture>".length(), prefecture2);
g.setPrefecture(prefecture);
int goodsImg1 = xmlMsg.indexOf("<goodsImg>");
int goodsImg2 = xmlMsg.indexOf("</goodsImg>");
String goodsImg = xmlMsg.substring(goodsImg1+"<goodsImg>".length(), goodsImg2);
g.setGoodsImg(goodsImg);
int typeHot1 = xmlMsg.indexOf("<typeHot>");
int typeHot2 = xmlMsg.indexOf("</typeHot>");
String typeHot = xmlMsg.substring(typeHot1+"<typeHot>".length(), typeHot2);
g.setTypeHot(typeHot);
int goodsCount1 = xmlMsg.indexOf("<goodsCount>");
int goodsCount2 = xmlMsg.indexOf("</goodsCount>");
String goodsCount = xmlMsg.substring(goodsCount1+"<goodsCount>".length(), goodsCount2);
g.setGoodsCount(goodsCount);
int stroeCount1 = xmlMsg.indexOf("<stroeCount>");
int stroeCount2 = xmlMsg.indexOf("</stroeCount>");
String stroeCount = xmlMsg.substring(stroeCount1+"<stroeCount>".length(), stroeCount2);
g.setStroeCount(stroeCount);
int collectCount1 = xmlMsg.indexOf("<collectCount>");
int collectCount2 = xmlMsg.indexOf("</collectCount>");
String collectCount = xmlMsg.substring(collectCount1+"<collectCount>".length(), collectCount2);
g.setCollectCount(collectCount);
int goodsBrandName1 = xmlMsg.indexOf("<goodsBrandName>");
int goodsBrandName2 = xmlMsg.indexOf("</goodsBrandName>");
String goodsBrandName = xmlMsg.substring(goodsBrandName1+"<goodsBrandName>".length(), goodsBrandName2);
g.setGoodsBrandName(goodsBrandName);
int goodsRemark1 = xmlMsg.indexOf("<goodsRemark>");
int goodsRemark2 = xmlMsg.indexOf("</goodsRemark>");
String goodsRemark = xmlMsg.substring(goodsRemark1+"<goodsRemark>".length(), goodsRemark2);
g.setGoodsRemark(goodsRemark);
int isSell1 = xmlMsg.indexOf("<isSell>");
int isSell2 = xmlMsg.indexOf("</isSell>");
String isSell = xmlMsg.substring(isSell1+"<isSell>".length(), isSell2);
g.setIsSell(isSell);
int sellerMemberNo1 = xmlMsg.indexOf("<sellerMemberNo>");
int sellerMemberNo2 = xmlMsg.indexOf("</sellerMemberNo>");
String sellerMemberNo = xmlMsg.substring(sellerMemberNo1+"<sellerMemberNo>".length(), sellerMemberNo2);
g.setSellerMemberNo(sellerMemberNo);
int shopName1 = xmlMsg.indexOf("<shopName>");
int shopName2 = xmlMsg.indexOf("</shopName>");
String shopName = xmlMsg.substring(shopName1+"<shopName>".length(), shopName2);
g.setShopName(shopName);
int logo1 = xmlMsg.indexOf("<logo>");
int logo2 = xmlMsg.indexOf("</logo>");
String logo = xmlMsg.substring(logo1+"<logo>".length(), logo2);
g.setLogo(logo);
int isUploadAttachment1 = xmlMsg.indexOf("<isUploadAttachment>");
int isUploadAttachment2 = xmlMsg.indexOf("</isUploadAttachment>");
String isUploadAttachment = xmlMsg.substring(isUploadAttachment1+"<isUploadAttachment>".length(), isUploadAttachment2);
g.setIsUploadAttachment(isUploadAttachment);
int isGifts1 = xmlMsg.indexOf("<isGifts>");
int isGifts2 = xmlMsg.indexOf("</isGifts>");
String isGifts = xmlMsg.substring(isGifts1+"<isGifts>".length(), isGifts2);
g.setIsGifts(isGifts);
int giftState1 = xmlMsg.indexOf("<giftState>");
int giftState2 = xmlMsg.indexOf("</giftState>");
String giftState = xmlMsg.substring(giftState1+"<giftState>".length(), giftState2);
g.setGiftState(giftState);
int storeCity1 = xmlMsg.indexOf("<storeCity>");
int storeCity2 = xmlMsg.indexOf("</storeCity>");
String storeCity = xmlMsg.substring(storeCity1+"<storeCity>".length(), storeCity2);
g.setStoreCity(storeCity);
int storeProvince1 = xmlMsg.indexOf("<storeProvince>");
int storeProvince2 = xmlMsg.indexOf("</storeProvince>");
String storeProvince = xmlMsg.substring(storeProvince1+"<storeProvince>".length(), storeProvince2);
g.setStoreProvince(storeProvince);
int isPrestore1 = xmlMsg.indexOf("<isPrestore>");
int isPrestore2 = xmlMsg.indexOf("</isPrestore>");
String isPrestore = xmlMsg.substring(isPrestore1+"<isPrestore>".length(), isPrestore2);
g.setIsPrestore(isPrestore);
int hasBill1 = xmlMsg.indexOf("<hasBill>");
if(hasBill1 !=-1){
int hasBill2 = xmlMsg.indexOf("</hasBill>");
String hasBill = xmlMsg.substring(hasBill1+"<hasBill>".length(), hasBill2);
g.setHasBill(hasBill);
}
int expressType1 = xmlMsg.indexOf("<expressType>");
if(expressType1 != -1){
int expressType2 = xmlMsg.indexOf("</expressType>");
String expressType = xmlMsg.substring(expressType1+"<expressType>".length(), expressType2);
g.setExpressType(expressType);
int freight1 = xmlMsg.indexOf("<freight>");
int freight2 = xmlMsg.indexOf("</freight>");
String freight = xmlMsg.substring(freight1+"<freight>".length(), freight2);
g.setFreight(freight);
}
int memberprice1 = xmlMsg.indexOf("<memberprice>");
int memberprice2 = xmlMsg.indexOf("</memberprice>");
String memberprice = xmlMsg.substring(memberprice1+"<memberprice>".length(), memberprice2);
g.setMemberPrice(memberprice);
int specialPrice1 = xmlMsg.indexOf("<specialPrice>");
int specialPrice2 = xmlMsg.indexOf("</specialPrice>");
String specialPrice = xmlMsg.substring(specialPrice1+"<specialPrice>".length(), specialPrice2);
g.setSpecialPrice(specialPrice);
returnObject[0] = g; //商品详情对象
int guarantee1 = xmlMsg.indexOf("<guarantee>");
int guarantee2 = xmlMsg.lastIndexOf("</guarantee>");
String guarantees = xmlMsg.substring(guarantee1, guarantee2+"</guarantee>".length());
guarantees = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>"+guarantees+"</root>";
List<Guarantee> lists = readGuaranteeXML(guarantees);
returnObject[1] = lists; //商品保障
return returnObject;
}
/**
* 转换会员账号
* @param memberNo
* @return
*/
public static String convertMemberNo(String memberNo){
if(ConvertUtil.isNumeric(memberNo)){//如果是纯数字会员
MemberInfoDao dao = new MemberInfoDao();
dao.setDataBaseType(FieldsDB.THREEWEIDU_PEPOS_BUSINESS);
try {
Object[] memberObj = dao.custFieldFind("MEMBERINFO_WEBSERVICEGETPHONE_SELECT", new Object[]{memberNo}, 2);
if(memberObj != null){
return memberObj[1].toString();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return memberNo;
}
public static String[] convertMemberNoNew(String memberNo) {
String arr[]= new String[3];
//如果是纯数字会员
arr[0]="1001"; //是否是手机号码1001 否 1002是
if(ConvertUtil.isNumeric(memberNo)){
arr[0]="1002";
arr[1]=memberNo;
}
String mem= convertMemberNo(memberNo);
arr[2]=mem;
return arr;
}
/**
*
* fastjson 转换
* @param object
* @return
*/
public static String toJSONString(Object object){
return JSON.toJSONString(object);
}