Commit 2fedb02f by Java-聂换换

商户进件

parent 40e2dddb
......@@ -29,6 +29,14 @@ public class ComCode {
public static final String EXTRA_RATE = "200"; // 附加手续费(单位:分)
public static final String INTEGRAL_MERCHANT_ID = "100532502191215"; // 商户号
public static final String INTEGRAL_MERCHANT_KEY = "781ed0d6-9657-404c-9f91-79eff2e0b782";//"670993bf-dd22-4464-9d81-69595d36b794"; // 商户key
public static final String INTEGRAL_MERCHANT_SECRET = "0033fc8d-161b-4e97-87de-efed7a34bdea";//"289ada73-27db-49e0-b2ad-3ae1613a665a"; // 商户sescet
public static final String INTEGRAL_QUICK_PAY_URL = "/quick/pay"; // 积分快捷支付
public static final String INTEGRAL_ORDER_QUERY_URL = "/order/query"; // 积分查询订单
//快捷处理
public static final String INTEGRAL_MERCHANT_REG_URL ="/api/quick/pay/handle";
/**
* duolabao相关参数
......
package com.thinkgem.jeesite.modules.pay.juhezhong.dto;
import java.math.BigDecimal;
public class MerchantsEntering extends CommonDto{
private String subMchId;//子商户号
private String subMerchantName; // 商户名称
private String serviceType; // 操作类型 1(参考附录)
private String idType;//证件类型
private String accName;//持卡人姓名
private String accNo;//卡号
private String accProvince;//开通省份
private String accCity;//开通城市
private String mobile;//预留手机号
private String idNo;//证件号码
private BigDecimal settleRate;//结算费率
private BigDecimal extraRate;//T0费率
private Integer accType;//账户类型
private String bankCode;
}
package com.thinkgem.jeesite.modules.pay.juhezhong.service;
import com.alibaba.fastjson.JSONObject;
import com.thinkgem.jeesite.common.constant.ComCode;
import com.thinkgem.jeesite.modules.pay.juhezhong.dto.CommonDto;
import com.thinkgem.jeesite.modules.pay.juhezhong.dto.MerchantDto;
import com.thinkgem.jeesite.modules.pay.juhezhong.dto.MerchantsEntering;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.Bean2Map;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.SignUtils;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.HttpUtil;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Map;
@Transactional
@Service
public class JuHeZhongPayIntegralService {
private Logger logger = LoggerFactory.getLogger(Logger.class);
/**
* 查询订单状态
*
* @param dto
* @return
* @throws Exception
*/
public JSONObject query(CommonDto dto) throws Exception {
dto.setMerchantId(ComCode.MERCHANT_ID);
dto.setMerchantKey(ComCode.INTEGRAL_MERCHANT_KEY);
Map<String, Object> params = Bean2Map.Entity2Map(dto);
String signBefore = SignUtils.signBefore(params);
String sign = SignUtils.sign(signBefore, ComCode.INTEGRAL_MERCHANT_SECRET);
params.put("sign", sign);
String respStr = HttpUtil.post(ComCode.HOST + ComCode.INTEGRAL_ORDER_QUERY_URL, params);
logger.info("respStr:{}", respStr);
return JSONObject.parseObject(respStr);
}
public JSONObject quickPayHandle(JSONObject dto)throws Exception {
dto.put("merchantId",ComCode.INTEGRAL_MERCHANT_ID);
dto.put("timestamp",System.currentTimeMillis());
String signBefore = SignUtils.signBefore(dto);
String sign = SignUtils.sign(signBefore, ComCode.INTEGRAL_MERCHANT_SECRET);
dto.put("sign", sign);
logger.info("signBefore:{},sign:{}", signBefore,sign);
String respStr = HttpUtil.post(ComCode.HOST + ComCode.INTEGRAL_MERCHANT_REG_URL, dto.toJSONString());
System.out.println(respStr);
return JSONObject.parseObject(respStr);
}
public static void main(String[] args) throws Exception {
// JSONObject dto = new JSONObject();
// dto.put("orderId","12323243435545465");
// dto.put("serviceType","4");
// dto.put("","");
// JuHeZhongPayIntegralService juHeZhongPayIntegralService = new JuHeZhongPayIntegralService();
// JSONObject jsonObject = juHeZhongPayIntegralService.quickPayHandle(dto);
// System.out.println(jsonObject.toJSONString());
JuHeZhongPayIntegralService juHeZhongPayIntegralService = new JuHeZhongPayIntegralService();
JSONObject dto = new JSONObject();
dto.put("orderId", MakeOrderNum.makeOrderNum());//标识请求唯一(非订单号)
dto.put("serviceType", 1);//服务类型
dto.put("merchantId", ComCode.INTEGRAL_MERCHANT_ID);//商户号
dto.put("subMerchantName", "niehh");//对公的就按照营业执照的注册名称进行商户名的报备进件,个体户的需要突出省,市,区一级营业范围,如:“XX市+XX区+法人名称+营业范围”--例“北京市朝阳区洪新阳饭店”而且一个身份证不要重复入很多个做银联二维码交易的商户 原则上一个身份证下只有一个做银联二维码交易的户,23:00—7:00,这段时间,银联二维码可以交易,不结算
dto.put("accName", "聂换换");//开户名称
dto.put("accNo", "6217000180000770507");//开户账号
dto.put("accType",1); //1=个人账户 0=企业账户1=个人账户
dto.put("bankName", "建设银行");//开户银行名(支行全称)
dto.put("bankCode", "105100000017");//联行号
dto.put("mobile","13722537737");
dto.put("idNo","130434199212214429");//身份证号
dto.put("settleType","795934");//费率类型 795934
dto.put("address","天津市河西区");//地址
dto.put("merchantKey", ComCode.INTEGRAL_MERCHANT_KEY);//商户key
dto.put("timestamp", System.currentTimeMillis());//时间戳
JSONObject jsonObject = juHeZhongPayIntegralService.quickPayHandle(dto);
String signBefore = SignUtils.signBefore(jsonObject);
String sign = SignUtils.sign(signBefore, ComCode.INTEGRAL_MERCHANT_SECRET);
//B105004538
System.out.println(jsonObject.toJSONString());
}
}
package com.thinkgem.jeesite.modules.pay.juhezhong.utils;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author lsw
* @date 2016年1月3日
* @version 1.0
* @desc 日期工具类
*/
public class DateUtil {
/**
* 将时间格式化成指定的字符串
*
* @param date
* @param ftm
* @return
*/
public static String format2str(Date date, String ftm) {
return new SimpleDateFormat(ftm).format(date);
}
/**
* 装字符串格式化成指定日期时间
* @param value
* @param fmt
* @return
*/
public static Date string2Date(String value,String fmt){
try {
return new SimpleDateFormat(fmt).parse(value);
} catch (ParseException e) {
}
return new Date();
}
}
\ No newline at end of file
......@@ -4,17 +4,24 @@ import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreConnectionPNames;
......@@ -22,8 +29,12 @@ import org.apache.http.params.HttpParams;
import org.apache.http.util.EntityUtils;
import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.net.URLEncoder;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -37,10 +48,12 @@ import java.util.Map;
public class HttpUtil {
private static final org.slf4j.Logger log = LoggerFactory.getLogger(HttpUtil.class);
private static PoolingHttpClientConnectionManager cm = null;
private static PoolingClientConnectionManager conMgr = null;
private static RequestConfig defaultRequestConfig = null;
static {
HttpParams params = new BasicHttpParams();
Integer CONNECTION_TIMEOUT = 2 * 1000; //设置请求超时2秒钟 根据业务调整
......@@ -56,6 +69,25 @@ public class HttpUtil {
conMgr.setMaxTotal(2000);
conMgr.setDefaultMaxPerRoute(conMgr.getMaxTotal());
try {
//采用绕过验证的方式处理https请求
SSLContext sslcontext = createIgnoreVerifySSL();
Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
.register("https", new SSLConnectionSocketFactory(sslcontext))
.register("http", new PlainConnectionSocketFactory())
.build();
cm = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
cm.setMaxTotal(2000);
cm.setDefaultMaxPerRoute(20);
defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(30000)
.setConnectionRequestTimeout(30000)
.setStaleConnectionCheckEnabled(true)
.build();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String get(String url, String param) {
......@@ -159,6 +191,38 @@ public class HttpUtil {
}
}
public static String post(String url, String json) throws Exception {
CloseableHttpClient httpclient = HttpClients.custom().setConnectionManager(cm).build();
HttpPost httpPost = null;
CloseableHttpResponse response = null;
String str = "";
try {
httpPost = new HttpPost(url);
StringEntity postingString = new StringEntity(json,"UTF-8");// json传递
httpPost.setEntity(postingString);
httpPost.setHeader("Content-type", "application/json");
response = httpclient.execute(httpPost);
try {
HttpEntity entity = response.getEntity();
str = EntityUtils.toString(entity,"UTF-8");
log.debug("httpclient调用状态:" + response.getStatusLine());
log.debug("httpclient调用结果{}", str);
// return EntityUtils.toString(response.getEntity());
return str;
} finally {
response.close();
}
} finally {
if (response != null) {
response.close();
}
if (httpPost != null) {
httpPost.releaseConnection();
}
}
}
public static String postRaw(String url, String json) throws Exception {
......@@ -223,4 +287,31 @@ public class HttpUtil {
e.printStackTrace();
}
}
private static SSLContext createIgnoreVerifySSL() throws Exception {
SSLContext sc = SSLContext.getInstance("SSLv3");
// 实现一个X509TrustManager接口,用于绕过验证,不用修改里面的方法
X509TrustManager trustManager = new X509TrustManager() {
@Override
public void checkClientTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
@Override
public void checkServerTrusted(
java.security.cert.X509Certificate[] paramArrayOfX509Certificate,
String paramString) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
};
sc.init(null, new TrustManager[]{trustManager}, null);
return sc;
}
}
package com.thinkgem.jeesite.modules.pay.juhezhong.utils;
import java.util.Date;
/**
* Created by lishi on 2017/11/1.
*/
public class MakeOrderNum {
/**
* 锁对象,可以为任意对象
*/
private static Object lockObj = "lockerOrder";
/**
* 订单号生成计数器
*/
private static long orderNumCount = 0L;
/**
* 每毫秒生成订单号数量最大值
*/
private static int maxPerMSECSize=1000;
/**
* 订单号生成
*/
public static String makeOrderNum() {
String finOrderNum = "";
try {
// 最终生成的订单号
synchronized (lockObj) {
// 取系统当前时间作为订单号变量前半部分,精确到毫秒
long nowLong = Long.parseLong(DateUtil.format2str(new Date(),"yyyyMMddHHmmssSSS"));
// 计数器到最大值归零,可扩展更大,目前1毫秒处理峰值1000个,1秒100万
if (orderNumCount >= maxPerMSECSize) {
orderNumCount = 0L;
}
//组装订单号
String countStr=maxPerMSECSize +orderNumCount+"";
finOrderNum=nowLong+countStr.substring(1);
orderNumCount++;
}
} catch (Exception e) {
e.printStackTrace();
}
return finOrderNum;
}
public static void main(String[] args) {
System.out.println(makeOrderNum());
System.out.println(makeOrderNum());
}
}
......@@ -26,16 +26,21 @@ public class OrderService {
public List<OrderEntity> getOrderList(OrderRequest request){
if(request.getStartDate()!= null && request.getStartDate() != 0){
request.setStartTime(DateUtils.formatDate(new Date(request.getStartDate()),"yyyy-MM-dd") + " 00:00:00");
request.setStartTime(DateUtils.formatDate(new Date(request.getStartDate()*1000),"yyyy-MM-dd") + " 00:00:00");
}
if(request.getEndDate() != null && request.getEndDate() != 0){
request.setEndTime(DateUtils.formatDate(new Date(request.getEndDate()),"yyyy-MM-dd") + " 23:59:59");
request.setEndTime(DateUtils.formatDate(new Date(request.getEndDate()*1000),"yyyy-MM-dd") + " 23:59:59");
}
return orderApiDao.getOrderList(request);
}
public static void main(String[] args){
Date date = new Date(1522723599416L);
System.out.println(new Date(1522723775000l));
System.out.println(System.currentTimeMillis());
}
}
......@@ -79,6 +79,8 @@ public interface UserApiDao {
List<BelongBankEntity> getBelongBank(UserRequest request);
BelongBankEntity getBelongBankEntity(UserRequest request);
Level getLevelByUserLevel(UserRequest request);
}
......@@ -9,8 +9,10 @@ import com.thinkgem.jeesite.common.utils.MD5;
import com.thinkgem.jeesite.modules.commonError.MyException;
import com.thinkgem.jeesite.modules.message.MessageUtils;
import com.thinkgem.jeesite.modules.pay.juhezhong.dto.MerchantDto;
import com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayIntegralService;
import com.thinkgem.jeesite.modules.pay.juhezhong.service.JuHeZhongPayService;
import com.thinkgem.jeesite.modules.pay.entity.RateEntity;
import com.thinkgem.jeesite.modules.pay.juhezhong.utils.MakeOrderNum;
import com.thinkgem.jeesite.modules.user.bean.IdentityCodeRequest;
import com.thinkgem.jeesite.modules.user.bean.UserRequest;
import com.thinkgem.jeesite.modules.user.dao.UserApiDao;
......@@ -41,6 +43,9 @@ public class UserApiService {
@Autowired
private JuHeZhongPayService juHeZhongPayService;
@Autowired
private JuHeZhongPayIntegralService juHeZhongPayIntegralService;
public UserEntity getUserInfo(Request request) {
UserEntity user = userDao.getUserInfo(request);
// 以下两行代码应Android要求,增加空detail和card
......@@ -221,7 +226,8 @@ public class UserApiService {
// 为用户卡注册subMerchantId
String type = "1"; // 默认将卡片添加为对私
String status = "0"; // 新增卡片审核状态均为未审核
String subMerchantId = null;//registJuHeZhongPay(request, type);
// String subMerchantId = null;//registJuHeZhongPay(request, type);
String subMerchantId = quickPayHandleJuhezhong(request,type);
// 更新银行卡详情
CardEntity cardStatusEntity = new CardEntity(request.getSubMerchantCode(), "N");
userDao.updateCardStatus(cardStatusEntity);
......@@ -325,6 +331,46 @@ public class UserApiService {
return jsonObject.getString("subMchId");
}
public String quickPayHandleJuhezhong(UserRequest request, String type) throws MyException, Exception {
UserEntity userEntity = userDao.getUserInfo(request);
BelongBankEntity belongBankEntity = userDao.getBelongBankEntity(request);
if (userEntity == null) {
throw new MyException("用户信息为空");
}
UserDetailEntity userDetailEntity = userDao.getUserDetailByCode(userEntity);
RateEntity rateEntityParam = new RateEntity(userEntity.getLevel(), "quick");
RateEntity rateEntity = userDao.getRateByLevel(rateEntityParam);
if (rateEntity == null) {
throw new MyException("费率等级信息为空");
}
JSONObject dto = new JSONObject();
dto.put("orderId", MakeOrderNum.makeOrderNum());//标识请求唯一(非订单号)
dto.put("serviceType", 1);//服务类型
dto.put("merchantId", ComCode.INTEGRAL_MERCHANT_ID);//商户号
dto.put("subMerchantName",request.getRealName() );//对公的就按照营业执照的注册名称进行商户名的报备进件,个体户的需要突出省,市,区一级营业范围,如:“XX市+XX区+法人名称+营业范围”--例“北京市朝阳区洪新阳饭店”而且一个身份证不要重复入很多个做银联二维码交易的商户 原则上一个身份证下只有一个做银联二维码交易的户,23:00—7:00,这段时间,银联二维码可以交易,不结算
dto.put("accName", request.getRealName());//开户名称
dto.put("accNo", request.getCardNo());//开户账号
dto.put("accType",1); //1=个人账户 0=企业账户1=个人账户
dto.put("bankName", belongBankEntity.getBankName());//开户银行名(支行全称)
dto.put("bankCode", request.getBelongBank());//联行号
dto.put("mobile",request.getMobile());
dto.put("idNo",request.getIdCard());//身份证号
dto.put("settleType","795934");//费率类型 795934
dto.put("address",request.getCardPlace());//地址
dto.put("merchantKey", ComCode.INTEGRAL_MERCHANT_KEY);//商户key
dto.put("timestamp", System.currentTimeMillis());//时间戳
JSONObject jsonObject = juHeZhongPayIntegralService.quickPayHandle(dto);
if (!"0000".equals(jsonObject.getString("code"))) {
throw new MyException(jsonObject.getString("msg"));
}
return jsonObject.getString("subMchId");
}
/**
* 修改JuHeZhong支付用户费率
*
......
......@@ -368,10 +368,10 @@
debit_card,
create_by,
update_by,
update_date = CURRENT_TIMESTAMP
update_date
)
VALUES
(#{code}, #{userCode}, #{realName}, #{idCard}, #{idCardPlace}, #{idCardFront}, #{idCardBack}, #{idCardHold}, #{debitCard}, #{createdUser}, #{modifiedUser})
(#{code}, #{userCode}, #{realName}, #{idCard}, #{idCardPlace}, #{idCardFront}, #{idCardBack}, #{idCardHold}, #{debitCard}, #{createdUser}, #{modifiedUser},now())
</insert>
<update id="updateUserDetail">
......@@ -642,6 +642,28 @@
WHERE
del_flag = '0'
</select>
<select id="getBelongBankEntity" resultType="com.thinkgem.jeesite.modules.user.entity.BelongBankEntity">
SELECT
yb.id,
yb.code,
yb.bank_code AS bankCode,
yb.bank_name AS bankName,
yb.bank_short AS bankShort,
yb.create_date AS created,
yb.create_by AS createdUser,
yb.update_date AS modified,
yb.update_by AS modifiedUser,
yb.del_flag AS delFlag
FROM
youka_bank yb
WHERE
del_flag = '0'
AND yb.bank_code = #{belongBank}
</select>
<select id="getRateListByLevel" resultType="com.thinkgem.jeesite.modules.pay.entity.RateEntity">
SELECT
yr.user_level AS userLevel,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment