feeConfigDtos = payFeeConfigV1InnerServiceSMOImpl.queryPayFeeConfigs(feeConfigDto);
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgNativeQrcodePaymentFactoryAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgNativeQrcodePaymentFactoryAdapt.java
deleted file mode 100644
index 2fc213d580..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgNativeQrcodePaymentFactoryAdapt.java
+++ /dev/null
@@ -1,285 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.acct.payment.IPaymentFactoryAdapt;
-import com.java110.acct.payment.adapt.bbgpay.lib.GmUtil;
-import com.java110.acct.payment.adapt.bbgpay.lib.JsonUtil;
-import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.factory.CommunitySettingFactory;
-import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.factory.WechatFactory;
-import com.java110.core.log.LoggerFactory;
-import com.java110.dto.app.AppDto;
-import com.java110.dto.owner.OwnerAppUserDto;
-import com.java110.dto.payment.NotifyPaymentOrderDto;
-import com.java110.dto.payment.PaymentOrderDto;
-import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
-import com.java110.dto.wechat.OnlinePayDto;
-import com.java110.dto.wechat.SmallWeChatDto;
-import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
-import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
-import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
-import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
-import com.java110.po.wechat.OnlinePayPo;
-import com.java110.utils.cache.MappingCache;
-import com.java110.utils.cache.UrlCache;
-import com.java110.utils.constant.MappingConstant;
-import com.java110.utils.constant.WechatConstant;
-import com.java110.utils.util.BeanConvertUtil;
-import com.java110.utils.util.PayUtil;
-import com.java110.utils.util.StringUtil;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.*;
-
-/**
- * 北部湾银行支付厂家
- *
- * // 以下数据先查询是否存在 存在则修改 不存在添加
- * INSERT INTO `TT`.`c_mapping` (`domain`, `name`, `key`, `value`, `remark`, `create_time`, `status_cd`)
- * VALUES ('WECHAT', 'native支付厂家', 'NATIVE_QRCODE_PAYMENT_ADAPT', 'bbgNativeQrcodePaymentFactoryAdapt', '', '2023-02-18 18:47:14', '0');
-
- */
-@Service("bbgNativeQrcodePaymentFactoryAdapt")
-public class BbgNativeQrcodePaymentFactoryAdapt implements IPaymentFactoryAdapt {
-
- private static final Logger logger = LoggerFactory.getLogger(BbgNativeQrcodePaymentFactoryAdapt.class);
-
-
- //微信支付
- public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
- // 微信服务商支付开关
- public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
-
- //开关ON打开
- public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
-
-
- private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
-
- private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
-
- public static final String TRADE_TYPE_NATIVE = "NATIVE";
- public static final String TRADE_TYPE_JSAPI = "JSAPI";
- public static final String TRADE_TYPE_MWEB = "MWEB";
- public static final String TRADE_TYPE_APP = "APP";
-
- private static String VERSION = "1.0";
-
- private static String SIGN_TYPE = "RSA2";// 加密算法:SM4、RSA2
-
- private static String gzhPayUrl = "https://mbank.bankofbbg.com/www/corepaycer/getQrcodeLink";
-
- @Autowired
- private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
-
-
- @Autowired
- private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
-
-
- @Autowired
- private IOnlinePayV1InnerServiceSMO onlinePayV1InnerServiceSMOImpl;
-
- @Autowired
- private RestTemplate outRestTemplate;
- @Autowired
- private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
-
- @Override
- public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
-
- SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
- String paymentPoolId = reqJson.getString("paymentPoolId");
-
- String appId = context.getReqHeaders().get("app-id");
- String userId = context.getReqHeaders().get("user-id");
- String tradeType = reqJson.getString("tradeType");
- String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/nativeWechat/992020011134400001/" + paymentPoolId;
-
-
- logger.debug("【小程序支付】 统一下单开始, 订单编号=" + paymentOrderDto.getOrderId());
- SortedMap resultMap = new TreeMap();
- //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
- double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN, "HC_ENV"), paymentOrderDto.getMoney());
- //添加或更新支付记录(参数跟进自己业务需求添加)
-
- Map resMap = null;
- resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
- paymentOrderDto.getOrderId(),
- payAmount,
- smallWeChatDto,
- paymentPoolId,
- notifyUrl
- );
-
-
- return resMap;
- }
-
-
- private Map java110UnifieldOrder(String feeName, String orderNum,
- double payAmount,
- SmallWeChatDto smallWeChatDto,
- String paymentPoolId,
- String notifyUrl) throws Exception {
-
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(paymentPoolId);
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
-
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- String productNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "productNo_SM4");
- String publicKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "publicKey_SM4");
-
- if (feeName.length() > 127) {
- feeName = feeName.substring(0, 126);
- }
-
- Map params = new HashMap<>();
- params.put("version", VERSION);// 版本号 1.0
- params.put("mcht_no", mchtNo_SM4);// 收款商户编号
- params.put("product_no", productNo_SM4);// 产品编号
- params.put("qr_type", "DYNAMIC");// 业务类型
- params.put("txn_type", "0");// 交易类型 0-实时;1-担保
- params.put("tran_no", orderNum);// 商户流水
- params.put("amt", payAmount);// 交易金额
- params.put("ware_name", feeName);// 商品名称
- params.put("ware_describe", "");// 商户数据包
- params.put("trx_trm_no", "");// 交易终端编号
- params.put("trans_source", "09");// 08:商户线下扫码09:商户线上收银10:一案一户缴款11:维修资金缴款12:房屋预售缴款
- params.put("asyn_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));// 通知地址
-
- String decryParams = EncryptDecryptFactory.execute(paymentPoolValueDtos, gzhPayUrl, params);
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- if (!"SUCCESS".equals(paramOut.getString("status"))
- || !"SUCCESS".equals(paramOut.getString("deal_status"))) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
-
- if (!"0000".equals(paramOut.getString("return_code"))
- && !"0001".equals(paramOut.getString("return_code"))
- ) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
- SortedMap resultMap = new TreeMap();
- resultMap.put("prepayId", paramOut.getString("tran_no"));
- resultMap.put("codeUrl", paramOut.getString("qr_link"));
- resultMap.put("code", "0");
- resultMap.put("msg", "下单成功");
- doSaveOnlinePay(smallWeChatDto, "无", orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付",paymentPoolValueDtos.get(0).getPpId());
-
- return resultMap;
- }
-
-
- @Override
- public PaymentOrderDto java110NotifyPayment(NotifyPaymentOrderDto notifyPaymentOrderDto) {
-
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(notifyPaymentOrderDto.getPaymentPoolId());
- paymentPoolValueDto.setCommunityId(notifyPaymentOrderDto.getCommunityId());
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
- String privateKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "privateKey_SM4");
-
- String resXml = "";
- String param = notifyPaymentOrderDto.getParam();
- PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
- // 开始解密
- Map responseParams = JsonUtil.jsonToMap(param);
- if (!responseParams.containsKey("enc_data")) {
- System.err.println("通知失败");
- throw new IllegalArgumentException("通知失败");
- }
- String decryptStr = (String) responseParams.get("enc_data");
- String messageKey = (String) responseParams.get("message_key");
- String secretKey = GmUtil.decryptSm2(messageKey, privateKey_SM4);
- if (secretKey == null) {
- System.err.println("解密失败");
- throw new IllegalArgumentException("解密失败");
- }
- String decryParams = GmUtil.decryptSm4(decryptStr, secretKey);
-
- System.out.println("支付结果返回值(解密后):" + decryParams);
-
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- String outTradeNo = paramOut.get("tran_no").toString();
- paymentOrderDto.setOrderId(outTradeNo);
- paymentOrderDto.setTransactionId(paramOut.get("txn_no").toString());
-
- doUpdateOnlinePay(outTradeNo, OnlinePayDto.STATE_COMPILE, "支付成功");
-
- JSONObject resJson = new JSONObject();
- resJson.put("return_code", "SUCCESS");
- resJson.put("return message", "成功");
-
- paymentOrderDto.setResponseEntity(new ResponseEntity(resJson.toJSONString(), HttpStatus.OK));
- return paymentOrderDto;
- }
-
- private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
-
- SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setObjId(paramIn.getString("communityId"));
- smallWeChatDto.setAppId(paramIn.getString("appId"));
- smallWeChatDto.setPage(1);
- smallWeChatDto.setRow(1);
- List smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
-
- if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
- smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
- smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
- smallWeChatDto.setMchId(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "mchId"));
- smallWeChatDto.setPayPassword(MappingCache.getValue(MappingConstant.WECHAT_STORE_DOMAIN, "key"));
- smallWeChatDto.setObjId(paramIn.getString("communityId"));
-
- return smallWeChatDto;
- }
-
- return BeanConvertUtil.covertBean(smallWeChatDtos.get(0), SmallWeChatDto.class);
- }
-
-
- private void doUpdateOnlinePay(String orderId, String state, String message) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setState(state);
- onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);
- }
-
- private void doSaveOnlinePay(SmallWeChatDto smallWeChatDto, String openId, String orderId, String feeName,
- double money, String state, String message,
- String ppId) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setAppId(smallWeChatDto.getAppId());
- onlinePayPo.setMchId(smallWeChatDto.getMchId());
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOpenId(openId);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setPayId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
- onlinePayPo.setPayName(feeName);
- onlinePayPo.setRefundFee("0");
- onlinePayPo.setState(state);
- onlinePayPo.setTotalFee(money + "");
- onlinePayPo.setTransactionId(orderId);
- onlinePayPo.setPaymentPoolId(ppId);
- onlinePayV1InnerServiceSMOImpl.saveOnlinePay(onlinePayPo);
- }
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java
deleted file mode 100644
index 1ab1b30bc6..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgPaymentFactoryAdapt.java
+++ /dev/null
@@ -1,331 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.acct.payment.IPaymentFactoryAdapt;
-import com.java110.acct.payment.adapt.bbgpay.lib.*;
-import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.factory.CommunitySettingFactory;
-import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.factory.WechatFactory;
-import com.java110.core.log.LoggerFactory;
-import com.java110.dto.app.AppDto;
-import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
-import com.java110.dto.wechat.OnlinePayDto;
-import com.java110.dto.owner.OwnerAppUserDto;
-import com.java110.dto.payment.NotifyPaymentOrderDto;
-import com.java110.dto.payment.PaymentOrderDto;
-import com.java110.dto.wechat.SmallWeChatDto;
-import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
-import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
-import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
-import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
-import com.java110.po.wechat.OnlinePayPo;
-import com.java110.utils.cache.MappingCache;
-import com.java110.utils.cache.UrlCache;
-import com.java110.utils.constant.MappingConstant;
-import com.java110.utils.constant.WechatConstant;
-import com.java110.utils.util.BeanConvertUtil;
-import com.java110.utils.util.PayUtil;
-import com.java110.utils.util.StringUtil;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.*;
-
-/**
- * 北部湾银行支付厂家
- *
- * 微信官方原生 支付实现类
- * 1.0 sql 配置说明:
- *
- * INSERT INTO `TT`.`t_dict` ( `status_cd`, `name`, `description`, `create_time`, `table_name`, `table_columns`)
- * VALUES ( '9070', '北部湾银行支付', '北部湾银行支付', '2022-08-16 15:51:55', 'community_setting_key', 'setting_type');
- *
- * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
- * VALUES ('82', '9070', 'mchtNo_SM4', 'mchtNo_SM4', 'mchtNo_SM4', '2021-10-10 21:25:46', '0');
- * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
- * VALUES ('88', '9070', 'productNo_SM4', 'productNo_SM4', 'productNo_SM4', '2021-10-10 21:25:46', '0');
- * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
- * VALUES ('83', '9070', 'publicKey_SM4', 'publicKey_SM4', '值请填写 公钥 ', '2021-10-10 21:25:46', '0');
- * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`)
- * VALUES ('84', '9070', 'privateKey_SM4', 'privateKey_SM4', '值请填写 私钥 ', '2021-10-10 21:25:46', '0');
- * // 以下数据先查询是否存在 存在则修改 不存在添加
- * INSERT INTO `TT`.`c_mapping` (`domain`, `name`, `key`, `value`, `remark`, `create_time`, `status_cd`)
- * VALUES ('WECHAT', '被扫支付厂家', 'PAY_QR_ADAPT', 'qrCodeBbgPaymentAdapt', '', '2023-02-18 18:47:14', '0');
- *
- * INSERT INTO `TT`.`c_mapping` (`domain`, `name`, `key`, `value`, `remark`, `create_time`, `status_cd`)
- * VALUES ('WECHAT', '线上支付厂家', 'PAYMENT_ADAPT', 'bbgPaymentFactoryAdapt', '', '2023-02-18 18:47:14', '0');
- */
-@Service("bbgPaymentFactoryAdapt")
-public class BbgPaymentFactoryAdapt implements IPaymentFactoryAdapt {
-
- private static final Logger logger = LoggerFactory.getLogger(BbgPaymentFactoryAdapt.class);
-
-
- //微信支付
- public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
- // 微信服务商支付开关
- public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
-
- //开关ON打开
- public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
-
-
- private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
-
- private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
-
- public static final String TRADE_TYPE_NATIVE = "NATIVE";
- public static final String TRADE_TYPE_JSAPI = "JSAPI";
- public static final String TRADE_TYPE_MWEB = "MWEB";
- public static final String TRADE_TYPE_APP = "APP";
-
- private static String VERSION = "1.0";
-
- private static String SIGN_TYPE = "RSA2";// 加密算法:SM4、RSA2
-
- private static String gzhPayUrl = "https://mbank.bankofbbg.com/www/corepaycer/WxGzhPay";
-
- @Autowired
- private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
-
-
- @Autowired
- private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
-
-
- @Autowired
- private IOnlinePayV1InnerServiceSMO onlinePayV1InnerServiceSMOImpl;
-
- @Autowired
- private RestTemplate outRestTemplate;
-
- @Autowired
- private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
-
-
- @Override
- public Map java110Payment(PaymentOrderDto paymentOrderDto, JSONObject reqJson, ICmdDataFlowContext context) throws Exception {
-
- SmallWeChatDto smallWeChatDto = getSmallWechat(reqJson);
- String paymentPoolId = reqJson.getString("paymentPoolId");
-
-
- String appId = context.getReqHeaders().get("app-id");
- String userId = context.getReqHeaders().get("user-id");
- String tradeType = reqJson.getString("tradeType");
- String notifyUrl = UrlCache.getOwnerUrl() + "/app/payment/notify/wechat/992020011134400001/" + paymentPoolId;
-
- String openId = reqJson.getString("openId");
-
-
- if (StringUtil.isEmpty(openId)) {
- String appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
- if (AppDto.WECHAT_OWNER_APP_ID.equals(appId)) {
- appType = OwnerAppUserDto.APP_TYPE_WECHAT;
- } else if (AppDto.WECHAT_MINA_OWNER_APP_ID.equals(appId)) {
- appType = OwnerAppUserDto.APP_TYPE_WECHAT_MINA;
- } else {
- appType = OwnerAppUserDto.APP_TYPE_APP;
- }
-
- OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
- ownerAppUserDto.setUserId(userId);
- ownerAppUserDto.setAppType(appType);
- List ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
-
- if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
- throw new IllegalArgumentException("未找到开放账号信息");
- }
- openId = ownerAppUserDtos.get(0).getOpenId();
- }
-
-
- logger.debug("【小程序支付】 统一下单开始, 订单编号=" + paymentOrderDto.getOrderId());
- SortedMap resultMap = new TreeMap();
- //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
- double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN, "HC_ENV"), paymentOrderDto.getMoney());
- //添加或更新支付记录(参数跟进自己业务需求添加)
-
- Map resMap = null;
- resMap = this.java110UnifieldOrder(paymentOrderDto.getName(),
- paymentOrderDto.getOrderId(),
- tradeType,
- payAmount,
- openId,
- smallWeChatDto,
- paymentPoolId,
- notifyUrl
- );
-
-
- return resMap;
- }
-
-
- private Map java110UnifieldOrder(String feeName, String orderNum,
- String tradeType, double payAmount, String openid,
- SmallWeChatDto smallWeChatDto,
- String paymentPoolId,
- String notifyUrl) throws Exception {
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(paymentPoolId);
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
-
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- String productNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "productNo_SM4");
- String publicKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "publicKey_SM4");
-
-
- if (feeName.length() > 127) {
- feeName = feeName.substring(0, 126);
- }
-
- Map params = new HashMap<>();
- params.put("version", VERSION);// 版本号 1.0
- params.put("mcht_no", mchtNo_SM4);// 收款商户编号
- params.put("product_no", productNo_SM4);// 产品编号
- params.put("biz_type", "WX_GZH");// 业务类型
- params.put("tran_no", orderNum);// 商户流水
- params.put("code", "");// 授权码
- params.put("openid", openid);// 用户标识id
- params.put("appid", smallWeChatDto.getAppId());// 公众号appid
- params.put("amt", payAmount);// 交易金额
- params.put("ware_name", feeName);// 商品名称
- params.put("ware_describe", "");// 商户数据包
- params.put("asyn_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));// 通知地址
- String decryParams = EncryptDecryptFactory.execute(paymentPoolValueDtos, gzhPayUrl, params);
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- if (!"SUCCESS".equals(paramOut.getString("status"))
- || !"SUCCESS".equals(paramOut.getString("deal_status"))) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
-
- if (!"0000".equals(paramOut.getString("return_code"))
- && !"0001".equals(paramOut.getString("return_code"))
- ) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
- SortedMap resultMap = new TreeMap();
- resultMap.put("appId", paramOut.getString("appId"));
- resultMap.put("timeStamp", paramOut.getString("timeStamp"));
- resultMap.put("nonceStr", paramOut.getString("nonceStr"));
- resultMap.put("package", paramOut.getString("package"));
- resultMap.put("signType", paramOut.getString("signType"));
- resultMap.put("sign", paramOut.getString("paySign"));
- resultMap.put("code", "0");
- resultMap.put("msg", "下单成功");
- doSaveOnlinePay(smallWeChatDto, openid, orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付",paymentPoolValueDtos.get(0).getPpId());
-
- return resultMap;
- }
-
-
- @Override
- public PaymentOrderDto java110NotifyPayment(NotifyPaymentOrderDto notifyPaymentOrderDto) {
-
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(notifyPaymentOrderDto.getPaymentPoolId());
- paymentPoolValueDto.setCommunityId(notifyPaymentOrderDto.getCommunityId());
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
- String privateKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "privateKey_SM4");
-
-
- String resXml = "";
- String param = notifyPaymentOrderDto.getParam();
- PaymentOrderDto paymentOrderDto = new PaymentOrderDto();
- // 开始解密
- Map responseParams = JsonUtil.jsonToMap(param);
- if (!responseParams.containsKey("enc_data")) {
- System.err.println("通知失败");
- throw new IllegalArgumentException("通知失败");
- }
- String decryptStr = (String) responseParams.get("enc_data");
- String messageKey = (String) responseParams.get("message_key");
- String secretKey = GmUtil.decryptSm2(messageKey, privateKey_SM4);
- if (secretKey == null) {
- System.err.println("解密失败");
- throw new IllegalArgumentException("解密失败");
- }
- String decryParams = GmUtil.decryptSm4(decryptStr, secretKey);
-
- System.out.println("支付结果返回值(解密后):" + decryParams);
-
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- String outTradeNo = paramOut.get("tran_no").toString();
- paymentOrderDto.setOrderId(outTradeNo);
- paymentOrderDto.setTransactionId(paramOut.get("txn_no").toString());
-
- doUpdateOnlinePay(outTradeNo, OnlinePayDto.STATE_COMPILE, "支付成功");
-
- JSONObject resJson = new JSONObject();
- resJson.put("return_code", "SUCCESS");
- resJson.put("return message", "成功");
-
- paymentOrderDto.setResponseEntity(new ResponseEntity(resJson.toJSONString(), HttpStatus.OK));
- return paymentOrderDto;
- }
-
- private SmallWeChatDto getSmallWechat(JSONObject paramIn) {
-
- SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setObjId(paramIn.getString("communityId"));
- smallWeChatDto.setAppId(paramIn.getString("appId"));
- smallWeChatDto.setPage(1);
- smallWeChatDto.setRow(1);
- List smallWeChatDtos = smallWechatV1InnerServiceSMOImpl.querySmallWechats(smallWeChatDto);
-
- if (smallWeChatDtos == null || smallWeChatDtos.size() < 1) {
- smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
- smallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
- smallWeChatDto.setObjId(paramIn.getString("communityId"));
-
- return smallWeChatDto;
- }
-
- return BeanConvertUtil.covertBean(smallWeChatDtos.get(0), SmallWeChatDto.class);
- }
-
-
- private void doUpdateOnlinePay(String orderId, String state, String message) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setState(state);
- onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);
- }
-
- private void doSaveOnlinePay(SmallWeChatDto smallWeChatDto, String openId, String orderId, String feeName,
- double money, String state, String message,
- String ppId) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setAppId(smallWeChatDto.getAppId());
- onlinePayPo.setMchId(smallWeChatDto.getMchId());
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOpenId(openId);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setPayId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
- onlinePayPo.setPayName(feeName);
- onlinePayPo.setRefundFee("0");
- onlinePayPo.setState(state);
- onlinePayPo.setTotalFee(money + "");
- onlinePayPo.setTransactionId(orderId);
- onlinePayPo.setPaymentPoolId(ppId);
- onlinePayV1InnerServiceSMOImpl.saveOnlinePay(onlinePayPo);
- }
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgRefundMoneyAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgRefundMoneyAdapt.java
deleted file mode 100644
index 4195f0e6d4..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/BbgRefundMoneyAdapt.java
+++ /dev/null
@@ -1,118 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.java110.acct.payment.IRefundMoneyAdapt;
-import com.java110.core.client.FtpUploadTemplate;
-import com.java110.core.client.OssUploadTemplate;
-import com.java110.core.factory.CommunitySettingFactory;
-import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.factory.PlutusFactory;
-import com.java110.core.log.LoggerFactory;
-import com.java110.dto.paymentPool.PaymentPoolDto;
-import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
-import com.java110.dto.wechat.OnlinePayDto;
-import com.java110.intf.acct.IOnlinePayRefundV1InnerServiceSMO;
-import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
-import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
-import com.java110.intf.fee.IReturnPayFeeInnerServiceSMO;
-import com.java110.intf.order.IOrderInnerServiceSMO;
-import com.java110.intf.store.ISmallWechatV1InnerServiceSMO;
-import com.java110.utils.util.PayUtil;
-import com.java110.vo.ResultVo;
-import org.bouncycastle.util.encoders.Base64;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-@Service("bbgRefundMoney")
-public class BbgRefundMoneyAdapt implements IRefundMoneyAdapt {
-
-
- private static String VERSION = "1.0";
-
- private static String SIGN_TYPE = "RSA2";// 加密算法:SM4、RSA2
-
- private static String refundUrl = "https://mbank.bankofbbg.com/www/corepaycer/Refund";// 退款地址
-
- @Autowired
- private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
-
- @Autowired
- private IReturnPayFeeInnerServiceSMO returnPayFeeInnerServiceSMOImpl;
-
- @Autowired
- private IOrderInnerServiceSMO orderInnerServiceSMOImpl;
-
- @Autowired
- private IOnlinePayV1InnerServiceSMO onlinePayV1InnerServiceSMOImpl;
-
- @Autowired
- private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl;
-
- @Autowired
- private RestTemplate outRestTemplate;
-
-
- private static Logger logger = LoggerFactory.getLogger(BbgRefundMoneyAdapt.class);
-
- @Autowired
- private FtpUploadTemplate ftpUploadTemplate;
-
- @Autowired
- private OssUploadTemplate ossUploadTemplate;
-
- @Autowired
- private IOnlinePayRefundV1InnerServiceSMO onlinePayRefundV1InnerServiceSMOImpl;
-
- @Override
- public ResultVo refund(OnlinePayDto onlinePayDto, PaymentPoolDto paymentPoolDto) throws Exception {
-
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(paymentPoolDto.getPpId());
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
-
-
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- String tranNo = GenerateCodeFactory.getGeneratorId("11");
-
-
- Map params = new HashMap<>();
- params.put("version", VERSION);// 版本号 1.0
- params.put("mcht_no", mchtNo_SM4);// 收款商户编号
- params.put("tran_no", tranNo);// 商户流水
- params.put("org_tran_no", onlinePayDto.getOrderId());// 原平台流水
- params.put("device_ip", "172.0.0.1");// 设备发起交易IP
- params.put("amt", onlinePayDto.getRefundFee());// 交易金额
- params.put("ware_name", onlinePayDto.getPayName());// 摘要备注
-
- // 对准备加签参数排序
- String decryParams = EncryptDecryptFactory.execute(paymentPoolValueDtos, refundUrl, params);
-
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- if ( !"SUCCESS".equals(paramOut.getString("status")) || !"SUCCESS".equals(paramOut.getString("deal_status"))) {
- return new ResultVo(ResultVo.CODE_ERROR, "退款失败" + paramOut.getString("return_message"));
- }
- if ( !"0000".equals(paramOut.getString("return_code")) && !"0001".equals(paramOut.getString("return_code"))) {
- return new ResultVo(ResultVo.CODE_ERROR, "退款失败" + paramOut.getString("return_message"));
- }
- if("0001".equals(paramOut.getString("return_code"))){
- return new ResultVo(ResultVo.CODE_OK, paramOut.getString("return_message"));
-
- }
- return new ResultVo(ResultVo.CODE_OK, "退款完成");
-
-
- }
-
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/EncryptDecryptFactory.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/EncryptDecryptFactory.java
deleted file mode 100644
index 1babfd803b..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/EncryptDecryptFactory.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay;
-
-import com.java110.acct.payment.adapt.bbgpay.lib.GmUtil;
-import com.java110.acct.payment.adapt.bbgpay.lib.HttpRequestUtil;
-import com.java110.acct.payment.adapt.bbgpay.lib.JsonUtil;
-import com.java110.core.factory.CommunitySettingFactory;
-import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class EncryptDecryptFactory {
-
-
- public static String execute(List paymentPoolValueDtos, String url, Map params){
- String decrypt = "";
- try {
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- String publicKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "publicKey_SM4");
- // 格式为json
- String json = JsonUtil.mapToJson(params);
- System.out.println("加密前:" + json);
- // 报文加密
- String secretKey = GmUtil.generateSm4Key();
- String encrypt = GmUtil.encryptSm4(json, secretKey);
- System.out.println("加密后:" + encrypt);
-
- Map signParams = new HashMap<>();
- signParams.put("mcht_no", mchtNo_SM4);// 收款商户编号
- signParams.put("sign_type", "SM4");
- signParams.put("message_key", GmUtil.encryptSm2(secretKey, publicKey_SM4));// 密钥加密
- signParams.put("enc_data", encrypt);// 加密后请求参数
-
- String requestParams = JsonUtil.mapToJson(signParams);
- System.out.println("最终请求参数:" + requestParams);
- System.err.println("");
- String returnResult = HttpRequestUtil.httpPost(url, requestParams);
- System.out.println("支付结果返回值(原文):" + returnResult);
- if (returnResult == null) {
- System.err.println("通道响应异常");
- throw new IllegalArgumentException("通道响应异常");
-
- }
- // 开始解密
- Map responseParams = JsonUtil.jsonToMap(returnResult);
- if (!responseParams.containsKey("enc_data")) {
- System.err.println("交易失败-->" + responseParams.get("return_code") + ":" + responseParams.get("return_message"));
- throw new IllegalArgumentException("交易失败-->" + responseParams.get("return_code") + ":" + responseParams.get("return_message"));
- }
- String decryptStr = (String) responseParams.get("enc_data");
-
- decrypt = GmUtil.decryptSm4(decryptStr, secretKey);
- if (decrypt == null) {
- System.err.println("解密失败");
- throw new IllegalArgumentException("解密失败");
- }
- System.out.println("支付结果返回值(解密后):" + decrypt);
- }catch (Exception e){
- e.printStackTrace();
- throw new IllegalArgumentException(e.getMessage());
- }
- return decrypt;
- }
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/QrCodeBbgPaymentAdapt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/QrCodeBbgPaymentAdapt.java
deleted file mode 100644
index 2f0e953c77..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/QrCodeBbgPaymentAdapt.java
+++ /dev/null
@@ -1,217 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay;
-
-import com.alibaba.fastjson.JSONObject;
-import com.java110.acct.smo.IQrCodePaymentSMO;
-import com.java110.core.client.RestTemplate;
-import com.java110.core.factory.GenerateCodeFactory;
-import com.java110.core.log.LoggerFactory;
-import com.java110.dto.paymentPoolValue.PaymentPoolValueDto;
-import com.java110.dto.wechat.OnlinePayDto;
-import com.java110.dto.wechat.SmallWeChatDto;
-import com.java110.intf.acct.IOnlinePayV1InnerServiceSMO;
-import com.java110.intf.acct.IPaymentPoolValueV1InnerServiceSMO;
-import com.java110.intf.store.ISmallWeChatInnerServiceSMO;
-import com.java110.po.wechat.OnlinePayPo;
-import com.java110.utils.cache.MappingCache;
-import com.java110.utils.constant.MappingConstant;
-import com.java110.utils.constant.WechatConstant;
-import com.java110.utils.util.PayUtil;
-import com.java110.vo.ResultVo;
-import org.slf4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.util.*;
-
-/**
- * 微信支付
- */
-@Service
-public class QrCodeBbgPaymentAdapt implements IQrCodePaymentSMO {
- private static Logger logger = LoggerFactory.getLogger(QrCodeBbgPaymentAdapt.class);
-
- //微信支付
- public static final String DOMAIN_WECHAT_PAY = "WECHAT_PAY";
- // 微信服务商支付开关
- public static final String WECHAT_SERVICE_PAY_SWITCH = "WECHAT_SERVICE_PAY_SWITCH";
-
- //开关ON打开
- public static final String WECHAT_SERVICE_PAY_SWITCH_ON = "ON";
-
-
- private static final String WECHAT_SERVICE_APP_ID = "SERVICE_APP_ID";
-
- private static final String WECHAT_SERVICE_MCH_ID = "SERVICE_MCH_ID";
-
- private static String VERSION = "1.0";
-
- private static String SIGN_TYPE = "RSA2";// 加密算法:SM4、RSA2
-
- private static String gzhPayUrl = "https://mbank.bankofbbg.com/www/corepaycer/ScanCodePay";
-
- private static String queryUrl = "https://mbank.bankofbbg.com/www/corepaycer/QueryTxnInfo";// 交易查询地址
-
- @Autowired
- private ISmallWeChatInnerServiceSMO smallWeChatInnerServiceSMOImpl;
-
- @Autowired
- private RestTemplate outRestTemplate;
-
- @Autowired
- private IPaymentPoolValueV1InnerServiceSMO paymentPoolValueV1InnerServiceSMOImpl;
-
- @Autowired
- private IOnlinePayV1InnerServiceSMO onlinePayV1InnerServiceSMOImpl;
-
- @Override
- public ResultVo pay(String communityId, String orderNum, double money, String authCode, String feeName, String paymentPoolId) throws Exception {
- logger.info("【小程序支付】 统一下单开始, 订单编号=" + orderNum);
- SortedMap resultMap = new TreeMap();
- //生成支付金额,开发环境处理支付金额数到0.01、0.02、0.03元
- double payAmount = PayUtil.getPayAmountByEnv(MappingCache.getValue(MappingConstant.ENV_DOMAIN, "HC_ENV"), money);
- //添加或更新支付记录(参数跟进自己业务需求添加)
-
- Map resMap = null;
- logger.debug("resMap=" + resMap);
- String systemName = MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, WechatConstant.PAY_GOOD_NAME);
- SmallWeChatDto shopSmallWeChatDto = null;
- SmallWeChatDto smallWeChatDto = new SmallWeChatDto();
- smallWeChatDto.setObjId(communityId);
- List smallWeChatDtos = smallWeChatInnerServiceSMOImpl.querySmallWeChats(smallWeChatDto);
- if (smallWeChatDtos == null && smallWeChatDtos.size() < 1) {
- shopSmallWeChatDto = new SmallWeChatDto();
- shopSmallWeChatDto.setObjId(communityId);
- shopSmallWeChatDto.setAppId(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appId"));
- shopSmallWeChatDto.setAppSecret(MappingCache.getValue(WechatConstant.WECHAT_DOMAIN, "appSecret"));
- } else {
- shopSmallWeChatDto = smallWeChatDtos.get(0);
- }
-
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(paymentPoolId);
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
-
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- String productNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "productNo_SM4");
- String publicKey_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "publicKey_SM4");
-
-
- Map params = new HashMap<>();
- params.put("version", VERSION);// 版本号 1.0
- params.put("mcht_no", mchtNo_SM4);// 收款商户编号
- params.put("product_no", productNo_SM4);// 产品编号
- params.put("tran_no", orderNum);// 商户流水
- params.put("auth_code", authCode);// 码类型
- params.put("amt", payAmount);// 交易金额
- params.put("ware_name", feeName);// 商品名称
- params.put("device_ip", "172.0.0.1");// 商户数据包
- params.put("recog_no", "123123");// 交易终端编号
- doSaveOnlinePay(shopSmallWeChatDto, "-1", orderNum, feeName, payAmount, OnlinePayDto.STATE_WAIT, "待支付",paymentPoolValueDtos.get(0).getPpId());
-
- String decryParams = EncryptDecryptFactory.execute(paymentPoolValueDtos, gzhPayUrl, params);
-
- JSONObject paramOut = JSONObject.parseObject(decryParams);
- if (!"0000".equals(paramOut.getString("return_code"))
- || !"SUCCESS".equals(paramOut.getString("status"))
- ) {
- return new ResultVo(ResultVo.CODE_ERROR, "支付失败" + paramOut.getString("return_message"));
-
- }
-
- if ("FAIL".equals(paramOut.getString("deal_status"))) {
- return new ResultVo(ResultVo.CODE_ERROR, "业务失败");
- }
-
- if ("SUCCESS".equals(paramOut.getString("deal_status"))) {
- doUpdateOnlinePay(orderNum, OnlinePayDto.STATE_COMPILE, "支付成功");
-
- return new ResultVo(ResultVo.CODE_OK, "成功");
- } else {
- return new ResultVo(ResultVo.CODE_ERROR, "等待用户支付中");
- }
- }
-
- public ResultVo checkPayFinish(String communityId, String orderNum, String paymentPoolId) {
- Map result = null;
- PaymentPoolValueDto paymentPoolValueDto = new PaymentPoolValueDto();
- paymentPoolValueDto.setPpId(paymentPoolId);
- paymentPoolValueDto.setCommunityId(communityId);
- List paymentPoolValueDtos = paymentPoolValueV1InnerServiceSMOImpl.queryPaymentPoolValues(paymentPoolValueDto);
-
-
- if (paymentPoolValueDtos == null || paymentPoolValueDtos.isEmpty()) {
- throw new IllegalArgumentException("配置错误,未配置参数");
- }
- String mchtNo_SM4 = PaymentPoolValueDto.getValue(paymentPoolValueDtos, "mchtNo_SM4");
- Map params = new HashMap<>();
- params.put("version", VERSION);// 版本号 1.0
- params.put("mcht_no", mchtNo_SM4);// 收款商户编号
- params.put("tran_no", orderNum);// 商户流水
- params.put("txn_no", "");// 支付流水
-
- // 对准备加签参数排序
- String decryParams = EncryptDecryptFactory.execute(paymentPoolValueDtos, queryUrl, params);
-
- /**
- * {"amt":"0.01","deal_status":"PROCESSING","jump_url":"","mcht_name":"广西蓉慧科技有限公司","mcht_no":"MCT2023060100029734",
- * "real_amt":"0.01","return_code":"5019","return_message":"用户正在输入密码,请等待","status":"SUCCESS",
- * "tran_no":"962023092519710062","txn_date":"20230925",
- * "txn_no":"P11082023092523543816778858","txn_time":"235438","ware_name":"云星花园-1栋1单元101室-住宅物业费"}
- */
- JSONObject paramOut = JSONObject.parseObject(decryParams);
-
- if ("PROCESSING".equals(paramOut.getString("deal_status")) && "5019".equals(paramOut.getString("return_code"))) {
- return new ResultVo(ResultVo.CODE_WAIT_PAY, "等待支付完成");
- }
-
- if (!"SUCCESS".equals(paramOut.getString("status"))
- || !"SUCCESS".equals(paramOut.getString("deal_status"))) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
-
-
- if (!"0000".equals(paramOut.getString("return_code"))
- && !"0001".equals(paramOut.getString("return_code"))
- ) {
- throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message"));
- }
-
- if ("0000".equals(paramOut.getString("return_code"))) {
- doUpdateOnlinePay(orderNum, OnlinePayDto.STATE_COMPILE, "支付成功");
- return new ResultVo(ResultVo.CODE_OK, "成功");
- } else {
- return new ResultVo(ResultVo.CODE_WAIT_PAY, "等待支付完成");
- }
- }
-
- private void doSaveOnlinePay(SmallWeChatDto smallWeChatDto, String openId, String orderId, String feeName,
- double money, String state, String message,
- String ppId) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setAppId(smallWeChatDto.getAppId());
- onlinePayPo.setMchId(smallWeChatDto.getMchId());
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOpenId(openId);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setPayId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_orderId));
- onlinePayPo.setPayName(feeName);
- onlinePayPo.setRefundFee("0");
- onlinePayPo.setState(state);
- onlinePayPo.setTotalFee(money + "");
- onlinePayPo.setTransactionId(orderId);
- onlinePayPo.setPaymentPoolId(ppId);
- onlinePayV1InnerServiceSMOImpl.saveOnlinePay(onlinePayPo);
- }
-
- private void doUpdateOnlinePay(String orderId, String state, String message) {
- OnlinePayPo onlinePayPo = new OnlinePayPo();
- onlinePayPo.setMessage(message.length() > 1000 ? message.substring(0, 1000) : message);
- onlinePayPo.setOrderId(orderId);
- onlinePayPo.setState(state);
- onlinePayV1InnerServiceSMOImpl.updateOnlinePay(onlinePayPo);
- }
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/AesEncrypt.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/AesEncrypt.java
deleted file mode 100644
index 788f7c254e..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/AesEncrypt.java
+++ /dev/null
@@ -1,175 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-import java.security.Security;
-import java.security.spec.AlgorithmParameterSpec;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-
-import com.alibaba.fastjson.JSONObject;
-
-/**
- * aes 加解密相关工具类
- *
- * @author bbw
- *
- */
-public class AesEncrypt {
- public final static String ivParameter = "0000000000000000";
- private static final String CHARSET_NAME_UTF8 = "UTF-8";
-
- static {
- Security.addProvider(new BouncyCastleProvider());
- Security.setProperty("crypto.policy", "unlimited");
- }
-
- public static String encrypt(String sSrc, String encodingFormat, String sKey) throws Exception {
- Security.addProvider(new BouncyCastleProvider());
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- byte[] raw = sKey.getBytes();
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
- cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
- byte[] encrypted = cipher.doFinal(sSrc.getBytes(encodingFormat));
- return Base64Util.encode(encrypted);
- }
-
- public static byte[] encryptByte(String sSrc, String encodingFormat, String sKey) throws Exception {
- Security.addProvider(new BouncyCastleProvider());
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- byte[] raw = sKey.getBytes();
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
- cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
- byte[] encrypted = cipher.doFinal(sSrc.getBytes(encodingFormat));
- return encrypted;
- }
-
- public static byte[] encryptByte(String sSrc, String encodingFormat, byte[] raw) throws Exception {
- Security.addProvider(new BouncyCastleProvider());
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
- cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
- byte[] encrypted = cipher.doFinal(sSrc.getBytes(encodingFormat));
- return encrypted;
- }
-
- public static String decrypt(String sSrc, String encodingFormat, String sKey) throws Exception {
- Security.addProvider(new BouncyCastleProvider());
- try {
- byte[] raw = sKey.getBytes("ASCII");
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
- cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
- byte[] encrypted1 = Base64Util.decode(sSrc);
- byte[] original = cipher.doFinal(encrypted1);
- String originalString = new String(original, encodingFormat);
- return originalString;
- } catch (Exception ex) {
- return null;
- }
- }
-
- public static byte[] decryptByte(byte[] bt, String sKey) throws Exception {
- Security.addProvider(new BouncyCastleProvider());
- try {
- byte[] raw = sKey.getBytes();
- SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- IvParameterSpec iv = new IvParameterSpec(ivParameter.getBytes());
- cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);
- byte[] original = cipher.doFinal(bt);
- return original;
- } catch (Exception ex) {
- return null;
- }
- }
-
- public static String parseByte2HexStr(byte buf[]) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < buf.length; i++) {
- String hex = Integer.toHexString(buf[i] & 0xFF);
- if (hex.length() == 1) {
- hex = '0' + hex;
- }
- sb.append(hex.toUpperCase());
- }
- return sb.toString();
- }
-
- public static byte[] parseHexStr2Byte(String hexStr) {
- if (hexStr.length() < 1)
- return null;
- byte[] result = new byte[hexStr.length() / 2];
- for (int i = 0; i < hexStr.length() / 2; i++) {
- int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
- int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
- result[i] = (byte) (high * 16 + low);
- }
- return result;
- }
-
- // 法院一案一户加密
- public static String ocoaEncrypt(String content, String aesKey, String aesIV) throws Exception {
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- SecretKeySpec keySpec = new SecretKeySpec(aesKey.getBytes(CHARSET_NAME_UTF8), "AES");
- AlgorithmParameterSpec paramSpec = new IvParameterSpec(aesIV.getBytes());
- cipher.init(Cipher.ENCRYPT_MODE, keySpec, paramSpec);
- byte[] result = cipher.doFinal(content.getBytes(CHARSET_NAME_UTF8));
- return URLEncoder.encode(Base64Util.encode(result), "UTF-8");
- }
-
- // 法院一案一户解密
- public static String ocoaDecrypt(String content, String aesKey, String aesIV) throws Exception {
- try {
- Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
- SecretKeySpec keySpec = new SecretKeySpec(aesKey.getBytes(CHARSET_NAME_UTF8), "AES");
- AlgorithmParameterSpec paramSpec = new IvParameterSpec(aesIV.getBytes());
- cipher.init(Cipher.DECRYPT_MODE, keySpec, paramSpec);
- return new String(cipher.doFinal(Base64Util.decode(URLDecoder.decode(content, "UTF-8"))), CHARSET_NAME_UTF8);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return "";
- }
-
- /**
- * 异或运算
- *
- */
- public static String strEncAndDec(String src) {
- // 字符串转成字符数组
- char[] c = src.toCharArray();
- // 循环给字符数组加密
- for (int i = 0; i < c.length; i++) {
- c[i] = (char) (c[i] ^ 1);
- }
- return new String(c);
- }
-
- public static void main(String[] args) throws Exception {
- JSONObject jsonObject = new JSONObject();
- jsonObject.put("ZH", "0003999");
- jsonObject.put("AH", "");
- String content = JSONObject.toJSONString(jsonObject);
- String s1 = ocoaEncrypt(content, "2021YHSYSHYAKXTK", "2021YHSYSHYAKXTV");
- System.out.println("密文:" + s1);
- String result = ocoaDecrypt(s1, "2021YHSYSHYAKXTK", "2021YHSYSHYAKXTV");
- System.out.println("解密:" + result);
- System.out.println(14584308/16415104f);
-
- String authCode = "990000003458LBU3133170411108125";
- System.out.println("付款码:" + authCode);
- String mchtNo = authCode.substring(12);
- System.out.println("第13位开始截取:" + mchtNo);
- System.out.println("企业商户号:" + strEncAndDec(mchtNo));
- }
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/Base64Util.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/Base64Util.java
deleted file mode 100644
index c8253b6370..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/Base64Util.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import org.apache.commons.codec.binary.Base64;
-
-/**
- *
- * BASE64编码解码工具包
- */
-public class Base64Util {
-
- /**
- *
- * BASE64字符串解码为二进制数据
- *
- *
- * @param base64
- * @return
- * @throws Exception
- */
- public static byte[] decode(String base64) throws Exception {
- return Base64.decodeBase64(base64.getBytes());
- }
-
- /**
- *
- * 二进制数据编码为BASE64字符串
- *
- *
- * @param bytes
- * @return
- * @throws Exception
- */
- public static String encode(byte[] bytes) throws Exception {
- return new String(Base64.encodeBase64(bytes));
- }
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/CAUtil.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/CAUtil.java
deleted file mode 100644
index 6b7dda6233..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/CAUtil.java
+++ /dev/null
@@ -1,184 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringWriter;
-import java.security.KeyFactory;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.Signature;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.spec.X509EncodedKeySpec;
-import java.util.Enumeration;
-
-import org.apache.commons.codec.binary.Base64;
-
-/**
- * 验证证书公共类
- *
- */
-public class CAUtil {
- private static final String DEFAULT_CHARSET = "UTF-8";
- private static final String KEY_ALGORITHM = "RSA";
- private static final String SIGNATURE_ALGORITHM = "SHA256withRSA";
-
- /**
- * 判断字符串是否为null或空 true为空
- */
- public static boolean isNullOrEmpty(String str) {
- return (str == null || str.length() == 0);
- }
-
- // 获取私钥
- public static PrivateKey getPrivateKey(InputStream is, String privateKeyPwd) throws Exception {
- KeyStore ks;
- try {
- ks = KeyStore.getInstance("PKCS12");
- char[] nPassword = null;
- if (isNullOrEmpty(privateKeyPwd)) {
- privateKeyPwd = null;
- } else {
- nPassword = privateKeyPwd.toCharArray();
- }
- ks.load(is, nPassword);
- is.close();
- Enumeration> enumas = ks.aliases();
- String keyAlias = null;
- if (enumas.hasMoreElements()) {
- keyAlias = (String) enumas.nextElement();
- }
- PrivateKey prikey = (PrivateKey) ks.getKey(keyAlias, nPassword);
- return prikey;
- } catch (KeyStoreException e) {
- throw new Exception("获取KeyStore失败");
- } catch (FileNotFoundException e) {
- throw new Exception("无效的私钥地址");
- } catch (NoSuchAlgorithmException e) {
- throw new Exception("读取私钥失败");
- } catch (CertificateException e) {
- throw new Exception("加载证书失败");
- } catch (IOException e) {
- throw new Exception("读取证书失败");
- } catch (UnrecoverableKeyException e) {
- throw new Exception("获取私钥失败");
- }
- }
-
- // 获取公钥
- public static PublicKey getPublicKey(String publicKeyAddr) throws Exception {
- try {
- CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
- FileInputStream bais = new FileInputStream(publicKeyAddr);
- X509Certificate Cert = (X509Certificate) certificatefactory.generateCertificate(bais);
- bais.close();
- PublicKey pk = Cert.getPublicKey();
- return pk;
- } catch (CertificateException e) {
- throw new Exception("获取公钥失败");
- }
- }
-
- /**
- * RSA签名
- *
- * @param localPrivKey
- * 私钥
- * @param plaintext
- * 需要签名的信息
- * @return byte[]
- * @throws Exception
- */
- public static byte[] signRSA(byte[] plainBytes, boolean useBase64Code, PrivateKey privKey) throws Exception {
- Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
- signature.initSign(privKey);
- signature.update(plainBytes);
- // 如果是Base64编码的话,需要对签名后的数组以Base64编码
- if (useBase64Code) {
- return Base64.encodeBase64(signature.sign());
- } else {
- return signature.sign();
- }
- }
-
- /**
- * 验签操作
- *
- * @param peerPubKey
- * 公钥
- * @param plainBytes
- * 需要验签的信息
- * @param signBytes
- * 签名信息
- * @return boolean
- */
- public static boolean verifyRSA(byte[] plainBytes, byte[] signBytes, boolean useBase64Code, PublicKey pubKey) throws Exception {
- boolean isValid = false;
- Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
- signature.initVerify(pubKey);
- signature.update(plainBytes);
- // 如果是Base64编码的话,需要对验签的数组以Base64解码
- if (useBase64Code) {
- isValid = signature.verify(Base64.decodeBase64(signBytes));
- } else {
- isValid = signature.verify(signBytes);
- }
- return isValid;
- }
-
- /**
- * SHA256withRSA签名(RSA2)
- *
- */
- public static String rsa256Sign(String content, String charset, String privateKey) throws Exception {
- if (isNullOrEmpty(charset)) {
- charset = DEFAULT_CHARSET;
- }
- if (isNullOrEmpty(privateKey)) {
- return null;
- }
- KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
- byte[] encodedKey = StreamUtil.readText(new ByteArrayInputStream(privateKey.getBytes())).getBytes();
- encodedKey = Base64.decodeBase64(encodedKey);
- PrivateKey priKey = keyFactory.generatePrivate(new PKCS8EncodedKeySpec(encodedKey));
- Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
- signature.initSign(priKey);
- if (isNullOrEmpty(charset)) {
- signature.update(content.getBytes());
- } else {
- signature.update(content.getBytes(charset));
- }
- byte[] signed = signature.sign();
- return new String(Base64.encodeBase64(signed));
- }
-
- /**
- * SHA256withRSA验签(RSA2)
- *
- */
- public static boolean rsa256Verify(byte[] content, String sign, String publicKey) throws Exception {
- if (isNullOrEmpty(publicKey)) {
- return false;
- }
- KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);
- StringWriter writer = new StringWriter();
- StreamUtil.io(new InputStreamReader(new ByteArrayInputStream(publicKey.getBytes())), writer);
- byte[] encodedKey = writer.toString().getBytes();
- encodedKey = Base64.decodeBase64(encodedKey);
- PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
- Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
- signature.initVerify(pubKey);
- signature.update(content);
- return signature.verify(Base64.decodeBase64(sign.getBytes()));
- }
-}
\ No newline at end of file
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/GmUtil.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/GmUtil.java
deleted file mode 100644
index c85b4f2c68..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/GmUtil.java
+++ /dev/null
@@ -1,311 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import javax.crypto.Cipher;
-import javax.crypto.KeyGenerator;
-import javax.crypto.spec.SecretKeySpec;
-
-import java.math.BigInteger;
-import java.security.Key;
-import java.security.KeyFactory;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.security.SecureRandom;
-import java.security.Security;
-import java.security.Signature;
-import java.security.spec.PKCS8EncodedKeySpec;
-import java.security.spec.X509EncodedKeySpec;
-
-import org.bouncycastle.asn1.gm.GMNamedCurves;
-import org.bouncycastle.asn1.gm.GMObjectIdentifiers;
-import org.bouncycastle.asn1.x9.X9ECParameters;
-import org.bouncycastle.crypto.engines.SM2Engine;
-import org.bouncycastle.crypto.params.ECDomainParameters;
-import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
-import org.bouncycastle.crypto.params.ECPublicKeyParameters;
-import org.bouncycastle.crypto.params.ParametersWithRandom;
-import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey;
-import org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPublicKey;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.bouncycastle.jce.spec.ECParameterSpec;
-import org.bouncycastle.jce.spec.ECPrivateKeySpec;
-import org.bouncycastle.jce.spec.ECPublicKeySpec;
-import org.bouncycastle.util.encoders.Hex;
-
-/**
- * 国密加密算法
- */
-public class GmUtil {
- private static final String DEFAULT_CHARSET = "UTF-8";
- public static final String ALGORITHM_NAME = "SM4";
- // 加密算法/分组加密模式/分组填充方式
- // PKCS5Padding-以8个字节为一组进行分组加密
- // 定义分组加密模式使用:PKCS5Padding
- public static final String ALGORITHM_NAME_ECB_PADDING = "SM4/ECB/PKCS7Padding";
- // 128-32位16进制;256-64位16进制
- public static final int DEFAULT_KEY_SIZE = 128;
- // 椭圆曲线ECParameters ASN.1 结构
- private static X9ECParameters x9ECParameters = GMNamedCurves.getByName("sm2p256v1");
- // 椭圆曲线公钥或私钥的基本域参数。
- private static ECParameterSpec ecDomainParameters = new ECParameterSpec(x9ECParameters.getCurve(), x9ECParameters.getG(), x9ECParameters.getN());
-
- static {
- Security.addProvider(new BouncyCastleProvider());
- }
-
- /**
- * 将Base64转码的公钥串,转化为公钥对象
- *
- */
- public static PublicKey createPublicKey(String publicKey) {
- PublicKey publickey = null;
- try {
- X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(Base64Util.decode(publicKey));
- KeyFactory keyFactory = KeyFactory.getInstance("EC", new BouncyCastleProvider());
- publickey = keyFactory.generatePublic(publicKeySpec);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return publickey;
- }
-
- /**
- * 将Base64转码的私钥串,转化为私钥对象
- *
- */
- public static PrivateKey createPrivateKey(String privateKey) {
- PrivateKey publickey = null;
- try {
- PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(Base64Util.decode(privateKey));
- KeyFactory keyFactory = KeyFactory.getInstance("EC", new BouncyCastleProvider());
- publickey = keyFactory.generatePrivate(pkcs8EncodedKeySpec);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return publickey;
- }
-
- /**
- * 根据publicKey对原始数据data,使用SM2加密
- */
- public static byte[] encrypt(byte[] data, PublicKey publicKey) {
- ECPublicKeyParameters localECPublicKeyParameters = null;
-
- if (publicKey instanceof BCECPublicKey) {
- BCECPublicKey localECPublicKey = (BCECPublicKey) publicKey;
- ECParameterSpec localECParameterSpec = localECPublicKey.getParameters();
- ECDomainParameters localECDomainParameters = new ECDomainParameters(localECParameterSpec.getCurve(), localECParameterSpec.getG(), localECParameterSpec.getN());
- localECPublicKeyParameters = new ECPublicKeyParameters(localECPublicKey.getQ(), localECDomainParameters);
- }
- SM2Engine localSM2Engine = new SM2Engine();
- localSM2Engine.init(true, new ParametersWithRandom(localECPublicKeyParameters, new SecureRandom()));
- byte[] arrayOfByte2;
- try {
- arrayOfByte2 = localSM2Engine.processBlock(data, 0, data.length);
- return arrayOfByte2;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 根据privateKey对加密数据encodedata,使用SM2解密
- */
- public static byte[] decrypt(byte[] encodedata, PrivateKey privateKey) {
- SM2Engine localSM2Engine = new SM2Engine();
- BCECPrivateKey sm2PriK = (BCECPrivateKey) privateKey;
- ECParameterSpec localECParameterSpec = sm2PriK.getParameters();
- ECDomainParameters localECDomainParameters = new ECDomainParameters(localECParameterSpec.getCurve(), localECParameterSpec.getG(), localECParameterSpec.getN());
- ECPrivateKeyParameters localECPrivateKeyParameters = new ECPrivateKeyParameters(sm2PriK.getD(), localECDomainParameters);
- localSM2Engine.init(false, localECPrivateKeyParameters);
- try {
- byte[] arrayOfByte3 = localSM2Engine.processBlock(encodedata, 0, encodedata.length);
- return arrayOfByte3;
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /**
- * 私钥签名
- */
- public static byte[] signByPrivateKey(byte[] data, PrivateKey privateKey) throws Exception {
- Signature sig = Signature.getInstance(GMObjectIdentifiers.sm2sign_with_sm3.toString(), BouncyCastleProvider.PROVIDER_NAME);
- sig.initSign(privateKey);
- sig.update(data);
- return sig.sign();
- }
-
- /**
- * 公钥验签
- */
- public static boolean verifyByPublicKey(byte[] data, PublicKey publicKey, byte[] signature) throws Exception {
- Signature sig = Signature.getInstance(GMObjectIdentifiers.sm2sign_with_sm3.toString(), BouncyCastleProvider.PROVIDER_NAME);
- sig.initVerify(publicKey);
- sig.update(data);
- return sig.verify(signature);
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * @Description 公钥字符串转换为 BCECPublicKey 公钥对象
- * @param pubKeyHex
- * 64字节十六进制公钥字符串(如果公钥字符串为65字节首个字节为0x04:表示该公钥为非压缩格式,操作时需要删除)
- * @return BCECPublicKey SM2公钥对象
- */
- private static BCECPublicKey getECPublicKeyByPublicKeyHex(String pubKeyHex) {
- // 截取64字节有效的SM2公钥(如果公钥首个字节为0x04)
- if (pubKeyHex.length() > 128) {
- pubKeyHex = pubKeyHex.substring(pubKeyHex.length() - 128);
- }
- // 将公钥拆分为x,y分量(各32字节)
- String stringX = pubKeyHex.substring(0, 64);
- String stringY = pubKeyHex.substring(stringX.length());
- // 将公钥x、y分量转换为BigInteger类型
- BigInteger x = new BigInteger(stringX, 16);
- BigInteger y = new BigInteger(stringY, 16);
- // 通过公钥x、y分量创建椭圆曲线公钥规范
- ECPublicKeySpec ecPublicKeySpec = new ECPublicKeySpec(x9ECParameters.getCurve().createPoint(x, y), ecDomainParameters);
- // 通过椭圆曲线公钥规范,创建出椭圆曲线公钥对象(可用于SM2加密及验签)
- return new BCECPublicKey("EC", ecPublicKeySpec, BouncyCastleProvider.CONFIGURATION);
- }
-
- /**
- * @Description 私钥字符串转换为 BCECPrivateKey 私钥对象
- * @param privateKeyHex
- * 32字节十六进制私钥字符串
- * @return BCECPrivateKey SM2私钥对象
- */
- private static BCECPrivateKey getBCECPrivateKeyByPrivateKeyHex(String privateKeyHex) {
- // 将十六进制私钥字符串转换为BigInteger对象
- BigInteger d = new BigInteger(privateKeyHex, 16);
- // 通过私钥和私钥域参数集创建椭圆曲线私钥规范
- ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(d, ecDomainParameters);
- // 通过椭圆曲线私钥规范,创建出椭圆曲线私钥对象(可用于SM2解密和签名)
- return new BCECPrivateKey("EC", ecPrivateKeySpec, BouncyCastleProvider.CONFIGURATION);
- }
-
- /**
- * @Description 公钥加密
- */
- public static String encryptSm2(String data, String publicKeyHex) {
- BCECPublicKey publicKey = getECPublicKeyByPublicKeyHex(publicKeyHex);
- // 加密模式
- SM2Engine.Mode mode = SM2Engine.Mode.C1C3C2;
- // 通过公钥对象获取公钥的基本域参数。
- ECParameterSpec ecParameterSpec = publicKey.getParameters();
- ECDomainParameters ecDomainParameters = new ECDomainParameters(ecParameterSpec.getCurve(), ecParameterSpec.getG(), ecParameterSpec.getN());
- // 通过公钥值和公钥基本参数创建公钥参数对象
- ECPublicKeyParameters ecPublicKeyParameters = new ECPublicKeyParameters(publicKey.getQ(), ecDomainParameters);
- // 根据加密模式实例化SM2公钥加密引擎
- SM2Engine sm2Engine = new SM2Engine(mode);
- // 初始化加密引擎
- sm2Engine.init(true, new ParametersWithRandom(ecPublicKeyParameters, new SecureRandom()));
- byte[] arrayOfBytes = null;
- try {
- // 将明文字符串转换为指定编码的字节串
- byte[] in = Hex.decode(data);
- // 通过加密引擎对字节数串行加密
- arrayOfBytes = sm2Engine.processBlock(in, 0, in.length);
- } catch (Exception e) {
- e.printStackTrace();
- }
- // 将加密后的字节串转换为十六进制字符串
- return Hex.toHexString(arrayOfBytes).toUpperCase();
- }
-
- /**
- * @Description 私钥解密
- */
- public static String decryptSm2(String cipherData, String privateKeyHex) {
- BCECPrivateKey privateKey = getBCECPrivateKeyByPrivateKeyHex(privateKeyHex);
- // 解密模式
- SM2Engine.Mode mode = SM2Engine.Mode.C1C3C2;
- // 将十六进制字符串密文转换为字节数组(需要与加密一致,加密是:加密后的字节数组转换为了十六进制字符串)
- byte[] cipherDataByte = Hex.decode(cipherData);
- // 通过私钥对象获取私钥的基本域参数。
- ECParameterSpec ecParameterSpec = privateKey.getParameters();
- ECDomainParameters ecDomainParameters = new ECDomainParameters(ecParameterSpec.getCurve(), ecParameterSpec.getG(), ecParameterSpec.getN());
- // 通过私钥值和私钥钥基本参数创建私钥参数对象
- ECPrivateKeyParameters ecPrivateKeyParameters = new ECPrivateKeyParameters(privateKey.getD(), ecDomainParameters);
- // 通过解密模式创建解密引擎并初始化
- SM2Engine sm2Engine = new SM2Engine(mode);
- sm2Engine.init(false, ecPrivateKeyParameters);
- String result = null;
- try {
- // 通过解密引擎对密文字节串进行解密
- byte[] arrayOfBytes = sm2Engine.processBlock(cipherDataByte, 0, cipherDataByte.length);
- result = new String(arrayOfBytes, "utf-8");
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /**
- * 自动生成sm4密钥
- *
- */
- public static String generateSm4Key() throws Exception {
- KeyGenerator kg = KeyGenerator.getInstance(ALGORITHM_NAME, BouncyCastleProvider.PROVIDER_NAME);
- kg.init(DEFAULT_KEY_SIZE, new SecureRandom());
- byte[] sm4Key = kg.generateKey().getEncoded();
- return new String(Hex.encode(sm4Key)).toUpperCase();
- }
-
- /**
- * 生成ECB暗号
- *
- */
- private static Cipher generateSm4Cipher(String algorithmName, int mode, byte[] key) throws Exception {
- Cipher cipher = Cipher.getInstance(algorithmName, BouncyCastleProvider.PROVIDER_NAME);
- Key sm4Key = new SecretKeySpec(key, ALGORITHM_NAME);
- cipher.init(mode, sm4Key);
- return cipher;
- }
-
- /**
- * sm4加密
- *
- */
- public static String encryptSm4(String data, String hexKey) {
- try {
- // 16进制字符串-->byte[]
- byte[] keyData = Hex.decode(hexKey);
- // String-->byte[]
- byte[] srcData = data.getBytes(DEFAULT_CHARSET);
- // 加密后的数组
- Cipher cipher = generateSm4Cipher(ALGORITHM_NAME_ECB_PADDING, Cipher.ENCRYPT_MODE, keyData);
- byte[] cipherArray = cipher.doFinal(srcData);
- // byte[]-->hexString
- return Hex.toHexString(cipherArray).toUpperCase();
- } catch (Exception e) {
- return null;
- }
- }
-
- /**
- * sm4解密
- *
- */
- public static String decryptSm4(String cipherText, String hexKey) {
- // 用于接收解密后的字符串
- String decryptStr = null;
- // hexString-->byte[]
- byte[] keyData = Hex.decode(hexKey);
- // hexString-->byte[]
- byte[] cipherData = Hex.decode(cipherText);
- try {
- // 解密
- Cipher cipher = generateSm4Cipher(ALGORITHM_NAME_ECB_PADDING, Cipher.DECRYPT_MODE, keyData);
- byte[] srcData = cipher.doFinal(cipherData);
- decryptStr = new String(srcData, DEFAULT_CHARSET);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return decryptStr;
- }
-
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/HttpRequestUtil.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/HttpRequestUtil.java
deleted file mode 100644
index ce4ce009a5..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/HttpRequestUtil.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URLDecoder;
-
-import org.apache.http.HttpHost;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.config.RequestConfig;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.impl.client.HttpClients;
-import org.apache.http.util.EntityUtils;
-
-/**
- * http请求工具类
- *
- * @author lizhongfu
- *
- */
-public class HttpRequestUtil {
- private final static int connectTimeOut = 30000;// 连接超时时间
- private final static int readTimeOut = 30000;// 读超时时间
-
- /**
- * httpPost
- *
- * @param url 路径
- * @param jsonParam 参数
- * @return
- */
- public static String httpPost(String url, String jsonParam) throws Exception {
- return httpPost(url, jsonParam, false);
- }
-
- /**
- * post请求
- *
- * @return
- */
- public static String httpPost(String url, String jsonParam, boolean bUseProxy) throws Exception {
- // post请求返回结果
- CloseableHttpClient client = HttpClients.createDefault();
- HttpPost method = new HttpPost(url);
- String str = "";
- try {
- RequestConfig config1 = null;
- // 是否采用代理
- if (bUseProxy) {
- // HttpHost proxy = new HttpHost("代理服务器IP", 代理服务器端口);
- HttpHost proxy = new HttpHost("127.0.0.1", 8828);
- config1 = RequestConfig.custom().setProxy(proxy).setConnectTimeout(connectTimeOut).setSocketTimeout(readTimeOut).build();
- } else {
- config1 = RequestConfig.custom().setConnectTimeout(connectTimeOut).setSocketTimeout(readTimeOut).build();
- }
- method.setConfig(config1);
- if (null != jsonParam) {
- // 解决中文乱码问题
- StringEntity entity = new StringEntity(jsonParam, "utf-8");
- entity.setContentEncoding("UTF-8");
- entity.setContentType("application/json");
- // entity.setContentType("application/x-www-form-urlencoded");
- method.setEntity(entity);
- }
- HttpResponse result = client.execute(method);
- url = URLDecoder.decode(url, "UTF-8");
- /** 请求发送成功,并得到响应 **/
- if (result.getStatusLine().getStatusCode() == 200) {
- /** 读取服务器返回过来的json字符串数据 **/
- // str = EntityUtils.toString(result.getEntity());
- str = EntityUtils.toString(result.getEntity(), "UTF-8");
- }
- } catch (IOException e) {
- System.err.println("网络异常:" + e.getMessage());
- // 网络异常
- throw e;
- } catch (Exception e) {
- System.err.println("系统错误:" + e.getMessage());
- throw e;
- }
- return str;
- }
-
- /**
- * 获取到下载的outputstream
- *
- * @param url
- * @return
- * @throws Exception
- */
- public static ByteArrayOutputStream httpGetToStream(String url) throws Exception {
- InputStream input = null;
- CloseableHttpClient client = null;
- try {
- client = HttpClients.createDefault();
- // 发送get请求
- HttpGet request = new HttpGet(url);
- HttpResponse response = client.execute(request);
- input = response.getEntity().getContent();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- byte[] buff = new byte[1024];
- int len;
- while ((len = input.read(buff)) > -1) {
- baos.write(buff, 0, len);
- }
- baos.flush();
- return baos;
- } catch (Exception e) {
- System.err.println("系统错误:" + e.getMessage());
- return null;
- } finally {
- input.close();
- client.close();
- }
- }
-}
diff --git a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/JsonUtil.java b/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/JsonUtil.java
deleted file mode 100644
index 45489939c2..0000000000
--- a/service-acct/src/main/java/com/java110/acct/payment/adapt/bbgpay/lib/JsonUtil.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.java110.acct.payment.adapt.bbgpay.lib;
-
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.TypeReference;
-import com.alibaba.fastjson.parser.Feature;
-import com.alibaba.fastjson.serializer.SerializerFeature;
-
-public class JsonUtil {
- /**
- * 将json转化成map
- *
- * @param json
- * @return
- */
- public static Map jsonToMap(String json) {
- try {
- return JSON.parseObject(json, new TypeReference