/* * * MchServiceImpl * */ package com.hboxs.service.impl; import com.alibaba.fastjson.JSONObject; import com.hboxs.common.Constant; import com.hboxs.common.JoinpayConstant; import com.hboxs.common.utils.HttpClientUtils; import com.hboxs.common.utils.joinpay.utils.AESUtil; import com.hboxs.common.utils.joinpay.utils.RSAUtil; import com.hboxs.dao.MchDao; import com.hboxs.joinpay.entity.Mch; import com.hboxs.service.MchService; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; import org.springframework.stereotype.Service; import org.springframework.util.Base64Utils; import sun.misc.BASE64Encoder; import sun.net.www.content.image.png; import javax.annotation.Resource; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.*; /** * Service - 汇聚支付 - 分销商 * @author dinfeng jimo * @version 1.0 * */ @Service("mchServiceImpl") public class MchServiceImpl extends BaseServiceImpl implements MchService { @Resource(name = "mchDaoImpl") private MchDao mchDao; @Resource(name = "mchDaoImpl") public void setBaseDao(MchDao mchDao) { super.setBaseDao(mchDao); } protected static Logger logger = Logger.getLogger(MchServiceImpl.class); @Override public Mch getUniqueness(Long adminId) { return mchDao.getUniqueness(adminId); } @Override public String createMch(Mch mch) { Long adminId = mch.getAdminId(); if(null == adminId){ return "找不到对应的管理员"; } Integer alt_merchant_type = mch.getAlt_merchant_type(); if(JoinpayConstant.alt_merchant_type1!=alt_merchant_type && JoinpayConstant.alt_merchant_type2!= alt_merchant_type && JoinpayConstant.alt_merchant_type3!= alt_merchant_type){ return "商家类型不正确"; } String url = "https://www.joinpay.com/allocFunds"; JSONObject requestData = new JSONObject(new LinkedHashMap()); String login_name = "test1_" + adminId + "@mianhuatang.com"; // String login_name = mch.getLegal_person(); mch.setLogin_name(login_name); // String alt_mch_name = "test1_" + adminId + "@mianhuatang.com"; String alt_mch_name = mch.getLegal_person(); mch.setAlt_mch_name(alt_mch_name); mch.setAlt_mch_short_name(""); // 格式为16 位随机字符串:16 位随机字符串 String aes_key1 = getRandomString(16); String aes_key2 = getRandomString(16); requestData.put("login_name", login_name); requestData.put("alt_mch_name", alt_mch_name); requestData.put("alt_mch_short_name", ""); requestData.put("alt_merchant_type", mch.getAlt_merchant_type()); requestData.put("busi_contact_name", mch.getBusi_contact_name()); requestData.put("busi_contact_mobile_no", mch.getBusi_contact_mobile_no()); requestData.put("phone_no", mch.getPhone_no()); requestData.put("manage_scope", mch.getManage_scope()); requestData.put("manage_addr", mch.getManage_addr()); requestData.put("legal_person", AESUtil.encrypt(mch.getLegal_person() , aes_key1 , aes_key2 )); requestData.put("id_card_no", AESUtil.encrypt(mch.getId_card_no(), aes_key1 , aes_key2 )); requestData.put("id_card_expiry", mch.getId_card_expiry()); // 个体工商户和企业必填:营业执照编号 / 营业执照有效期 if(JoinpayConstant.alt_merchant_type2== alt_merchant_type || JoinpayConstant.alt_merchant_type3== alt_merchant_type){ requestData.put("license_no", mch.getLicense_no()); requestData.put("license_expiry", mch.getLicense_expiry()); } // 由汇聚自动结算 requestData.put("sett_mode", JoinpayConstant.sett_mode1); // 结算周期类型:自然日 requestData.put("sett_date_type", JoinpayConstant.sett_date_type2); // 结算周期:1 requestData.put("risk_day", 1); if(JoinpayConstant.alt_merchant_type2== alt_merchant_type || JoinpayConstant.alt_merchant_type3== alt_merchant_type){ // 企业用对公账户 requestData.put("bank_account_type", JoinpayConstant.bank_account_type4); }else if(JoinpayConstant.alt_merchant_type1== alt_merchant_type){ // 个人用借记卡 requestData.put("bank_account_type", JoinpayConstant.bank_account_type1); } requestData.put("bank_account_name", AESUtil.encrypt(mch.getBank_account_name(), aes_key1 , aes_key2 )); requestData.put("bank_account_no", AESUtil.encrypt(mch.getBank_account_no(), aes_key1 , aes_key2 )); requestData.put("bank_channel_no", mch.getBank_channel_no()); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altmch.add"); requestJson.put("version", "2.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); requestJson.put("aes_key", RSAUtil.encrypt(aes_key1+":"+aes_key2 , JoinpayConstant.publickey )); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); if(jsonObject.has("resp_code")){ mch.setResp_code(jsonObject.getString("resp_code")); } if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_code")){ mch.setBiz_code(data.getString("biz_code")); } if (data.has("alt_mch_no")){ mch.setAlt_mch_no(data.getString("alt_mch_no")); } if(data.has("order_status")){ mch.setOrder_status(data.getString("order_status")); } } /** * 更新一下分销商户的 各种响应码 & login_name */ update(mch); if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); } } } } catch (IOException e) { e.printStackTrace(); } return Constant.correct_code; } @Override public String updateMch(Mch mch , String legal_person , String id_card_no , Integer alt_merchant_type , String bank_account_name , String bank_account_no , String bank_channel_no) { Long adminId = mch.getAdminId(); if(null == adminId){ return "找不到对应的管理员"; } if(JoinpayConstant.alt_merchant_type1!=alt_merchant_type && JoinpayConstant.alt_merchant_type2!= alt_merchant_type && JoinpayConstant.alt_merchant_type3!= alt_merchant_type){ return "商家类型不正确"; } String url = "https://www.joinpay.com/allocFunds"; JSONObject requestData = new JSONObject(new LinkedHashMap()); // 格式为16 位随机字符串:16 位随机字符串 String aes_key1 = getRandomString(16); String aes_key2 = getRandomString(16); requestData.put("alt_mch_no", mch.getAlt_mch_no()); requestData.put("legal_person", AESUtil.encrypt(legal_person, aes_key1 , aes_key2 )); requestData.put("id_card_no", AESUtil.encrypt(id_card_no, aes_key1 , aes_key2 )); if(JoinpayConstant.alt_merchant_type2== alt_merchant_type || JoinpayConstant.alt_merchant_type3== alt_merchant_type){ // 企业用对公账户 requestData.put("bank_account_type", JoinpayConstant.bank_account_type4); mch.setBank_account_type(JoinpayConstant.bank_account_type4); }else if(JoinpayConstant.alt_merchant_type1== alt_merchant_type){ // 个人用借记卡 requestData.put("bank_account_type", JoinpayConstant.bank_account_type1); mch.setBank_account_type(JoinpayConstant.bank_account_type1); } requestData.put("bank_account_name", AESUtil.encrypt(bank_account_name, aes_key1 , aes_key2 )); requestData.put("bank_account_no", AESUtil.encrypt(bank_account_no, aes_key1 , aes_key2 )); requestData.put("bank_channel_no", bank_channel_no); mch.setLegal_person(legal_person); mch.setId_card_no(id_card_no); mch.setAlt_merchant_type(alt_merchant_type); mch.setBank_account_name(bank_account_name); mch.setBank_account_no(bank_account_no); mch.setBank_channel_no(bank_channel_no); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altmch.modify"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); requestJson.put("aes_key", RSAUtil.encrypt(aes_key1+":"+aes_key2 , JoinpayConstant.publickey )); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); if(jsonObject.has("resp_code")){ mch.setResp_code(jsonObject.getString("resp_code")); } if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_code")){ mch.setBiz_code(data.getString("biz_code")); } if (data.has("alt_mch_no")){ mch.setAlt_mch_no(data.getString("alt_mch_no")); } if(data.has("order_status")){ mch.setOrder_status(data.getString("order_status")); } } if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); } } } } catch (IOException e) { e.printStackTrace(); } return Constant.correct_code; } @Override public String refreshMch(Mch mch) { String login_name = mch.getLogin_name(); if(StringUtils.isEmpty(login_name)){ return "账户不存在"; } String url = "https://www.joinpay.com/allocFunds"; JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_login_name", "test1_" + mch.getAdminId() + "@mianhuatang.com"); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altmch.query"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); if(jsonObject.has("resp_code")){ mch.setResp_code(jsonObject.getString("resp_code")); } if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_code")){ mch.setBiz_code(data.getString("biz_code")); } if (data.has("alt_mch_no")){ mch.setAlt_mch_no(data.getString("alt_mch_no")); } if(data.has("order_status")){ mch.setOrder_status(data.getString("order_status")); } } // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); }else{ return JoinpayConstant.resp_code.get(resp_code); } } }else{ return "请求失败"; } } catch (IOException e) { e.printStackTrace(); } update(mch); return Constant.correct_code; } @Override public String refreshMyAccount(Mch mch) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altAccount.get"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); }else{ return JoinpayConstant.resp_code.get(resp_code); } } }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); // 更新账户的金额 if(data.has("alt_main_balance")){ mch.setAlt_main_balance(new BigDecimal(data.getString("alt_main_balance")).divide(new BigDecimal(100))); } if(data.has("alt_guar_balance")){ mch.setAlt_guar_balance(new BigDecimal(data.getString("alt_guar_balance")).divide(new BigDecimal(100))); } if(data.has("alt_avil_balance")){ mch.setAlt_avil_balance(new BigDecimal(data.getString("alt_avil_balance")).divide(new BigDecimal(100))); } update(mch); } } catch (IOException e) { e.printStackTrace(); } return Constant.correct_code; } // 协议内容获取接口 @Override public String getQuerySignContent(Mch mch) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altMchSign.querySignContent"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); }else{ return JoinpayConstant.resp_code.get(resp_code); } } }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); //update(mch); } } catch (IOException e) { e.printStackTrace(); } return Constant.correct_code; } // 协议内容签约接口 @Override public String altMchSign(Mch mch) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String dateString = formatter.format(currentTime); JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); requestData.put("sign_status" , "P1000"); requestData.put("sign_time" , dateString); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altMchSign.sign"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); String back=null; org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); }else{ return JoinpayConstant.resp_code.get(resp_code); } } }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); String biz_code = data.getString("biz_code"); if(biz_code.equals("B100000")){ String sign_trx_no = data.getString("sign_trx_no"); String sign_status = data.getString("sign_status"); if(sign_status.equals("P1000")){ sign_status="签约成功"; }else { sign_status="签约失败"; } mch.setSign_status(sign_status); mch.setSign_trx_no(sign_trx_no); back = sign_status; } update(mch); } } catch (IOException e) { e.printStackTrace(); } return back; } // 协议签约查询接口 @Override public String querySignRecord(Mch mch) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altMchSign.querySignRecord"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); if(JoinpayConstant.resp_code2.equals(resp_code)){ org.json.JSONObject data = jsonObject.getJSONObject("data"); if(data.has("biz_msg")){ return data.getString("biz_msg"); }else{ return JoinpayConstant.resp_code.get(resp_code); } } }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); String biz_code = data.getString("biz_code"); if(biz_code.equals("B100000")){ String sign_trx_no = data.getString("sign_trx_no"); String sign_status = data.getString("sign_status"); if(sign_status.equals("P1000")){ sign_status="签约成功"; }else { sign_status="签约失败"; } mch.setSign_status(sign_status); mch.setSign_trx_no(sign_trx_no); update(mch); } } } catch (IOException e) { e.printStackTrace(); } return Constant.correct_code; } /** * 传送身份证图片 * @param * @return */ @Override public String sendCard(Mch mch,String cardPositive,String cardNegative) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } // String card_positive = ImageToBase64ByLocal(cardPositive); String card_positive = cardPositive; // String card_negative = ImageToBase64ByLocal(cardNegative); String card_negative = cardNegative; JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); requestData.put("card_positive" , card_positive); requestData.put("card_negative" , card_negative); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altMchPics.uploadPic"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); String back=null; org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); String biz_code = data.getString("biz_code"); if(biz_code.equals("B100000")){ String approve_status = "审核中"; mch.setApprove_status(approve_status); mch.setApprove_note(""); back = approve_status; } if(biz_code.equals("B100002")){ String approve_status = "上传失败"; String approve_note = data.getString("biz_msg"); mch.setApprove_note(approve_note); mch.setApprove_status(approve_status); back = approve_status; } if(biz_code.equals("B101017")){ String approve_status = "上传失败"; String approve_note = data.getString("biz_msg"); mch.setApprove_note(approve_note); mch.setApprove_status(approve_status); back = approve_status; } update(mch); } } catch (IOException e) { e.printStackTrace(); } return back; } /** * 查询身份证照片审核状态 * @param * @return */ @Override public String searchApprove(Mch mch) { String url = "https://www.joinpay.com/allocFunds"; if(StringUtils.isEmpty(mch.getAlt_mch_no())){ return "找不到商家编号"; } JSONObject requestData = new JSONObject(new LinkedHashMap()); requestData.put("alt_mch_no" , mch.getAlt_mch_no()); JSONObject requestJson = new JSONObject(new TreeMap()); requestJson.put("method", "altMchPics.queryPicsInfo"); requestJson.put("version", "1.0"); requestJson.put("data", requestData); // 32位随机字符串 String uuid = UUID.randomUUID().toString().trim().replaceAll("-", ""); requestJson.put("rand_str", uuid); requestJson.put("sign_type", JoinpayConstant.sign_type_MD5); requestJson.put("mch_no", JoinpayConstant.mch_no); String sign = createMD5Sign(requestJson , JoinpayConstant.key); requestJson.put("sign", sign.toUpperCase()); logger.info("请求参数:" + requestJson); String back=null; org.json.JSONObject jsonObject; try { jsonObject = HttpClientUtils.postJson(url, requestJson.toString()); logger.info("响应参数:" + jsonObject); // 判断请求是否正确,受理成功 if(jsonObject.has("resp_code")){ String resp_code = jsonObject.getString("resp_code"); mch.setResp_code(resp_code); }else{ return "请求失败"; } // 处理data if(jsonObject.has("data")){ org.json.JSONObject data = jsonObject.getJSONObject("data"); String biz_code = data.getString("biz_code"); if(biz_code.equals("B100000")){ String approve_status = "审核通过"; String approve_note = data.getString("approve_note"); mch.setApprove_note(approve_note); mch.setApprove_status(approve_status); back = approve_status; } if(biz_code.equals("B110008")){ String approve_status = "审核未通过"; String approve_note = data.getString("biz_msg"); mch.setApprove_note(approve_note); mch.setApprove_status(approve_status); back = approve_status; } if(biz_code.equals("B101018")){ String approve_status = "审核未通过"; String approve_note = data.getString("biz_msg"); mch.setApprove_note(approve_note); mch.setApprove_status(approve_status); back = approve_status; } update(mch); } } catch (IOException e) { e.printStackTrace(); } return back; } /** * 本地图片转换成base64字符串 * * @param imgFile 图片本地路径 * @return */ public static String ImageToBase64ByLocal(String imgFile) {// 将图片文件转化为字节数组字符串,并对其进行Base64编码处理 InputStream in = null; byte[] data = null; // 读取图片字节数组 try { in = new FileInputStream(imgFile); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } // 对字节数组Base64编码 BASE64Encoder encoder = new BASE64Encoder(); String[] strings = imgFile.split("\\."); if(strings.length>1){ String str = strings[strings.length-1]; String title = "data:image/"+str+";base64,"; return title+encoder.encode(data);// 返回Base64编码过的字节数组字符串 }else { return null; } } /** * 签名算法sign , MD5 签名 * @param requestJson * @return */ public static String createMD5Sign(JSONObject requestJson , String key){ StringBuffer sb = new StringBuffer(); Set es = requestJson.entrySet(); Iterator it = es.iterator(); while(it.hasNext()) { Map.Entry entry = (Map.Entry)it.next(); String k = (String)entry.getKey(); Object v = entry.getValue(); if(null != v && !"".equals(v) && !"sign".equals(k) && !"key".equals(k)) { sb.append(k + "=" + v + "&"); } } sb.append("key=" + key); logger.info("签名字符串:"+sb.toString()); String sign = DigestUtils.md5Hex(sb.toString()); return sign; } /** * 获取随机字符串 * @return */ public static String getRandomString(int length){ String str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random=new Random(); StringBuffer sb=new StringBuffer(); for(int i=0;i