Java tutorial
package com.hx.sync.utils; import java.util.HashMap; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hx.sync.vo.TmOwner; import com.hx.sync.vo.TmVehicle; import com.hx.sync.vo.TmVeicleInfoVo; public class MemberUtils { private static final Log logger = LogFactory.getLog("MemberUtils"); static Config config = new Config(); static boolean flag = true; static String url = config.getValue("member.center.url"); /** * mobile???? */ public static JSONObject getMeberList(String mobile, String userGuid) { Config config = new Config(); if (flag) { //?? JSONObject data = new JSONObject(); if (mobile != null && !mobile.equals("")) { data.put("mobile", mobile); } if (userGuid != null && !userGuid.equals("")) { data.put("user_guid", userGuid); } //? Map<String, String> map = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = (JSONObject) HttpClientUtil.postForm(url + "/Account/V1/Users/getOwnerInfo", map); if (json != null && json.get("data") != null && json.containsKey("data") && json.containsKey("code") && json.getInteger("code") == 200) { return json.getJSONObject("data"); } } return null; } /** * * true?false */ public static JSONObject saveMember(TmOwner to, boolean status) { //?? JSONObject data = new JSONObject(); //? Map<String, String> map = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); to.setOwnerNo(to.getOwnerNo()); to.setEntityCode(to.getEntityCode()); data.put("data", JSONObject.toJSONString(to)); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = HttpClientUtil.postForm(url + "/Account/V1/Users/index", map); logger.debug("post return data:" + json); /* if(json!=null && json.containsKey("code") && (json.getInteger("code")==200 ||json.getInteger("code")==402 ) && json.containsKey("data") && json.getJSONObject("data")!=null){ JSONObject returnData=json.getJSONObject("data"); String memberNo=returnData.getString("user_guid"); if(memberNo!=null && !memberNo.equals("")){ return memberNo; } } */ return json; } /** *??,oldMobile??newMobile?? */ public static Boolean updateMemberMobile(String userGuid, String contactorMobile) { if (flag) { //?? JSONObject data = new JSONObject(); //? Map<String, String> map = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); data.put("user_guid", userGuid); data.put("contactor_mobile", contactorMobile); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = (JSONObject) HttpClientUtil.postForm(url + "/Account/V1/Users/editPhone", map); logger.debug("----------update member editPhone" + json); if (json != null && json.getInteger("code") != null && json.getInteger("code") == 200) { logger.debug("updateMemberMobile:" + json.toJSONString()); return true; } } return false; } /** * ?????? * @param map * @param needResponse * @return * @author wangzy * @date 2016-3-15 * */ public static boolean updateUserTradeInfo(JSONObject map, boolean needResponse) { if (map != null && flag) { //? Map<String, String> publicMap = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); publicMap.put("data", map.toJSONString()); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(map.toJSONString(), millis); publicMap.put("identity_code", identityCode); publicMap.put("time", millis); publicMap.put("data", (map.toJSONString())); publicMap.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = HttpClientUtil.postForm(url + "/Account/V1/Prepaid/userTrade", publicMap, needResponse); if (Utility.isNotEmpty(json) && json.containsKey("code") && json.getInteger("code") == 200) { logger.debug("updateUserTradeInfo:" + json.toJSONString()); return true; } } return false; } /** * ?? * @param mobile * @param verifyCode * @param enetityCode * @return * @author wangzy * @date 2016-3-19 * */ public static JSONObject getMemberCouponInfo(String mobile, String verifyCode, String enetityCode) { JSONObject object = null; if (Utility.isNotEmpty(mobile) && Utility.isNotEmpty(verifyCode) && flag) { JSONObject param = new JSONObject(); param.put("mobile", mobile); param.put("cp_verify_code", verifyCode); param.put("from_entity", enetityCode); //? Map<String, String> publicMap = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); publicMap.put("data", param.toJSONString()); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(param.toJSONString(), millis); publicMap.put("identity_code", identityCode); publicMap.put("time", millis); publicMap.put("data", (param.toJSONString())); publicMap.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = (JSONObject) HttpClientUtil.postForm(url + "/Account/V1/Coupon/get_shop_coupon", publicMap, true); if (Utility.isNotEmpty(json) && json.containsKey("code") && json.getInteger("code") == 200 && json.containsKey("data") && json.getJSONArray("data") != null) { JSONArray jsonArr = json.getJSONArray("data"); if (Utility.isNotEmpty(jsonArr) && jsonArr.size() > 0) { for (int i = 0, len = jsonArr.size(); i < len; i++) { JSONObject obj = jsonArr.getJSONObject(i); String description = (String) obj.get("description"); object = JSONObject.parseObject(description); object.put("userGuid", obj.getString("user_guid")); object.put("cpVerifyCode", obj.getString("cp_verify_code")); } } } } return object; } /** * ? * @param map * @param needResponse * @return * @author wangzy * @date 2016-3-19 * */ public static boolean updateCouponStatus(JSONObject map, boolean needResponse) { if (map != null && flag) { //? Map<String, String> publicMap = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); publicMap.put("data", map.toJSONString()); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(map.toJSONString(), millis); publicMap.put("identity_code", identityCode); publicMap.put("time", millis); publicMap.put("data", (map.toJSONString())); publicMap.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = HttpClientUtil.postForm(url + "/Account/V1/Coupon/update_coupon", publicMap, needResponse); if (Utility.isNotEmpty(json) && json.containsKey("code") && json.getInteger("code") == 200 && json.containsKey("data") && json.get("data") != null) { logger.debug("updateCouponStatus:" + json.toJSONString()); return true; } } return false; } /** * ?? * @param tm * @return */ public static boolean updateMemberVehicle(TmVehicle tm) { if (flag) { //?? /*JSONObject data = new JSONObject(); //? Map<String, String> map=new HashMap<String, String>(); String millis=String.valueOf(System.currentTimeMillis()/1000)+Utility.getRandomNum(8); data.put("data", JSONObject.toJSONString(tm)); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json=HttpClientUtil.postForm(url+"Account/V1/Vehicle/index", map); logger.info("post return data:" + json); if(json!=null && json.containsKey("code") && (json.getInteger("code")==200 ||json.getInteger("code")==402 )){ return true; }*/ Map<String, Object> str = new HashMap<String, Object>(); str.put("entityCode", tm.getEntityCode()); str.put("vin", tm.getVin()); return true; } return false; } /** * ?? * @param tv * @return */ public static boolean editMemberVehicleInfo(TmVeicleInfoVo tv) { if (flag) { /*//?? JSONObject data = new JSONObject(); //? Map<String, String> map=new HashMap<String, String>(); String millis=String.valueOf(System.currentTimeMillis()/1000)+Utility.getRandomNum(8); data.put("data", JSONObject.toJSONString(tv)); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("data", JSONObject.toJSONString(tv).toString()); map.put("identity_code", identityCode); map.put("time", millis); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json=HttpClientUtil.postForm(url+"Account/V1/Vehicle/editVehicle", map); logger.info("post return data:" + json); if(json!=null && json.containsKey("code") && (json.getInteger("code")==200 ||json.getInteger("code")==402 )){ return true; }*/ } return false; } /** * ?? * @param mobile * @param guid * @param vin * @param license * @return */ public static JSONObject getMemberVehicleInfo(String mobile, String guid, String vin, String license) { JSONObject obj = new JSONObject(); if (flag) { JSONObject data = new JSONObject(); if (Utility.isNotEmpty(mobile)) { data.put("mobile", mobile); } if (Utility.isNotEmpty(guid)) { data.put("user_guid", guid); } if (Utility.isNotEmpty(vin)) { data.put("vin", vin); } if (Utility.isNotEmpty(license)) { data.put("license", license); } //? Map<String, String> map = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = (JSONObject) HttpClientUtil.postForm(url + "/Account/V1/Vehicle/getVehicle", map); if (json != null && json.get("data") != null && json.containsKey("data") && json.containsKey("code") && json.getInteger("code") == 200) { JSON array = (JSON) json.get("data"); if (array instanceof JSONObject) { obj = (JSONObject) array; } } } return obj; } /** * ?? */ public static JSONObject sendVehicleTMemberCenter(TmVehicle tm) { JSONObject data = new JSONObject(); //? Map<String, String> map = new HashMap<String, String>(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); data.put("data", JSONObject.toJSONString(tm)); //MD5 SecretUtil secretUtil = new SecretUtil(); String identityCode = secretUtil.md5Ticket(data.toJSONString(), millis); map.put("identity_code", identityCode); map.put("time", millis); map.put("data", data.toJSONString()); map.put("systemId", Constants.SYSTEM_ID_MEMBER_CENTER); JSONObject json = HttpClientUtil.postForm(url + "/Account/V1/Vehicle/index", map); logger.debug("post return data:" + json); return json; /* if(json!=null && json.containsKey("code") && (json.getInteger("code")==200 ||json.getInteger("code")==402 )){ return json; }else{ return null; } */ } /** * erp? * @param url * @param adapterNo * @param data * @return */ public static JSONObject accessERPInterface(String url, String adapterNo, String data) { Map<String, String> params = new HashMap<String, String>(); SecretUtil secretUtil = new SecretUtil(); String millis = String.valueOf(System.currentTimeMillis() / 1000) + Utility.getRandomNum(8); String identityCode = secretUtil.md5Ticket(data.toString(), millis); params.put("identityCode", identityCode); params.put("adapterNo", adapterNo); params.put("data", data); params.put("systemId", Constants.SYSTEM_ID_GROUP_ERP); params.put("time", millis); JSONObject resultJson = HttpClientUtil.postForm(url, params, true); return resultJson; } public static void main(String[] args) { JSONObject obj = getMemberVehicleInfo("13554344623", "14-63753d53-5934-11e6-bf5c-fcaa14d9feb4", "VXFOJDN41598KFSDS", "A10086"); System.out.println(obj); } }