| | |
| | | * VALUES ( '9070', '北部湾银行支付', '北部湾银行支付', '2022-08-16 15:51:55', 'community_setting_key', 'setting_type'); |
| | | * <p> |
| | | * INSERT INTO `TT`.`community_setting_key` (`key_id`, `setting_type`, `setting_name`, `setting_key`, `remark`, `create_time`, `status_cd`) |
| | | * VALUES ('82', '9070', 'mchtNo_RSA2', 'mchtNo_RSA2', 'mchtNo_RSA2', '2021-10-10 21:25:46', '0'); |
| | | * 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_RSA2', 'productNo_RSA2', 'productNo_RSA2', '2021-10-10 21:25:46', '0'); |
| | | * 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', 'mcht_PrivateKey_RSA2', 'mcht_PrivateKey_RSA2', '值请填写1 私钥 请填写在备注中', '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', 'bank_PublicKey_RSA2', 'bank_PublicKey_RSA2', '值请填写1 公钥 请填写在备注中 ', '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 ('85', '9070', 'opToken_RSA2', 'opToken_RSA2', 'opToken_RSA2', '2021-10-10 21:25:46', '0'); |
| | | * VALUES ('83', '9070', 'publicKey_SM4', 'publicKey_SM4', '值请填写1 私钥 请填写在备注中', '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'); |
| | |
| | | |
| | | private static String SIGN_TYPE = "RSA2";// 加密算法:SM4、RSA2 |
| | | |
| | | private static String gzhPayUrl = "https://epaytest.bankofbbg.com/www/corepaycer/WxGzhPay"; |
| | | private static String gzhPayUrl = "https://mbank.bankofbbg.com/www/corepaycer/WxGzhPay"; |
| | | |
| | | @Autowired |
| | | private ISmallWechatV1InnerServiceSMO smallWechatV1InnerServiceSMOImpl; |
| | |
| | | ); |
| | | |
| | | |
| | | if ("SUCCESS".equals(resMap.get("return_code")) && "SUCCESS".equals(resMap.get("result_code"))) { |
| | | if (TRADE_TYPE_JSAPI.equals(tradeType)) { |
| | | |
| | | resultMap.put("appId", smallWeChatDto.getAppId()); |
| | | resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp()); |
| | | resultMap.put("nonceStr", PayUtil.makeUUID(32)); |
| | | resultMap.put("package", "prepay_id=" + resMap.get("prepay_id")); |
| | | resultMap.put("signType", "MD5"); |
| | | resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword())); |
| | | } else if (TRADE_TYPE_APP.equals(tradeType)) { |
| | | resultMap.put("appId", smallWeChatDto.getAppId()); |
| | | resultMap.put("timeStamp", PayUtil.getCurrentTimeStamp()); |
| | | resultMap.put("nonceStr", PayUtil.makeUUID(32)); |
| | | resultMap.put("partnerid", smallWeChatDto.getMchId()); |
| | | resultMap.put("prepayid", resMap.get("prepay_id")); |
| | | //resultMap.put("signType", "MD5"); |
| | | resultMap.put("sign", PayUtil.createSign(resultMap, smallWeChatDto.getPayPassword())); |
| | | } else if (TRADE_TYPE_NATIVE.equals(tradeType)) { |
| | | resultMap.put("prepayId", resMap.get("prepay_id")); |
| | | resultMap.put("codeUrl", resMap.get("code_url")); |
| | | } |
| | | resultMap.put("code", "0"); |
| | | resultMap.put("msg", "下单成功"); |
| | | logger.info("【小程序支付】统一下单成功,返回参数:" + resultMap + "===notifyUrl===" + notifyUrl); |
| | | } else { |
| | | resultMap.put("code", resMap.get("return_code")); |
| | | resultMap.put("msg", resMap.get("return_msg")); |
| | | logger.info("【小程序支付】统一下单失败,失败原因:" + resMap.get("return_msg") + "===code===" + resMap.get("return_code") + "===notifyUrl===" + notifyUrl); |
| | | } |
| | | return resultMap; |
| | | return resMap; |
| | | } |
| | | |
| | | |
| | | private Map<String, String> java110UnifieldOrder(String feeName, String orderNum, |
| | | String tradeType, double payAmount, String openid, |
| | | SmallWeChatDto smallWeChatDto, String notifyUrl) throws Exception { |
| | | String mchtNo_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "mchtNo_RSA2"); |
| | | String productNo_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "productNo_RSA2"); |
| | | String opToken_RSA2 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "opToken_RSA2"); |
| | | String mcht_PrivateKey_RSA2 = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "mcht_PrivateKey_RSA2"); |
| | | String bank_PublicKey_RSA2 = CommunitySettingFactory.getRemark(smallWeChatDto.getObjId(), "bank_PublicKey_RSA2"); |
| | | |
| | | String mchtNo_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "mchtNo_SM4"); |
| | | String productNo_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "productNo_SM4"); |
| | | String publicKey_SM4 = CommunitySettingFactory.getValue(smallWeChatDto.getObjId(), "publicKey_SM4"); |
| | | |
| | | if (feeName.length() > 127) { |
| | | feeName = feeName.substring(0, 126); |
| | |
| | | |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("version", VERSION);// 版本号 1.0 |
| | | params.put("mcht_no", mchtNo_RSA2);// 收款商户编号 |
| | | params.put("product_no", productNo_RSA2);// 产品编号 |
| | | params.put("mcht_no", mchtNo_SM4);// 收款商户编号 |
| | | params.put("product_no", productNo_SM4);// 产品编号 |
| | | params.put("biz_type", "WX_GZH");// 业务类型 |
| | | params.put("tran_no", String.valueOf(System.nanoTime()));// 商户流水 |
| | | params.put("code", "");// 授权码 |
| | |
| | | params.put("ware_name", feeName);// 商品名称 |
| | | params.put("ware_describe", "");// 商户数据包 |
| | | params.put("asyn_url", notifyUrl + "?wId=" + WechatFactory.getWId(smallWeChatDto.getAppId()));// 通知地址 |
| | | String json = JsonUtil.mapToJson(params); |
| | | System.out.println("加密前:" + json); |
| | | |
| | | Map<String, Object> soreMap = JsonUtil.sortMapByKey(params); |
| | | |
| | | // 开始加密 |
| | | byte[] en = AesEncrypt.encryptByte(json, "utf-8", opToken_RSA2); |
| | | if (en == null || en.length <= 0) { |
| | | System.err.println("加密失败"); |
| | | throw new IllegalArgumentException("加密失败"); |
| | | } |
| | | String encryptBase64Str = AesEncrypt.parseByte2HexStr(en); |
| | | System.out.println("加密后:" + encryptBase64Str); |
| | | |
| | | String signtBase64Str = CAUtil.rsa256Sign(json, "utf-8", mcht_PrivateKey_RSA2); |
| | | System.out.println("加签串:" + signtBase64Str); |
| | | |
| | | Map<String, Object> signParams = new HashMap<>(); |
| | | signParams.put("mcht_no", mchtNo_RSA2);// 收款商户编号 |
| | | signParams.put("sign_type", SIGN_TYPE); |
| | | signParams.put("sign", signtBase64Str); |
| | | signParams.put("enc_data", encryptBase64Str);// 加密后请求参数 |
| | | |
| | | String requestParams = JsonUtil.mapToJson(signParams); |
| | | System.out.println("最终请求参数:" + requestParams); |
| | | System.err.println(""); |
| | | String returnResult = HttpRequestUtil.httpPost(gzhPayUrl, requestParams); |
| | | System.out.println("支付结果返回值(原文):" + returnResult); |
| | | if (returnResult == null) { |
| | | System.err.println("通道响应异常"); |
| | | throw new IllegalArgumentException("通道响应异常"); |
| | | } |
| | | // 开始解密 |
| | | Map<String, Object> responseParams = JsonUtil.jsonToMap(returnResult); |
| | | // 开始解密 |
| | | String decryptBase64Str = (String) responseParams.get("enc_data"); |
| | | String verifyBase64Str = (String) responseParams.get("sign"); |
| | | byte[] bt = AesEncrypt.parseHexStr2Byte(decryptBase64Str); |
| | | byte[] decrypt = AesEncrypt.decryptByte(bt, opToken_RSA2); |
| | | if (decrypt == null) { |
| | | System.err.println("解密失败"); |
| | | throw new IllegalArgumentException("解密失败"); |
| | | } |
| | | boolean isSuccess = CAUtil.rsa256Verify(decrypt, verifyBase64Str, bank_PublicKey_RSA2); |
| | | System.out.println("数据验签:" + isSuccess); |
| | | if (!isSuccess) { |
| | | System.err.println("验签失败"); |
| | | throw new IllegalArgumentException("验签失败"); |
| | | } |
| | | String decryParams = new String(decrypt); |
| | | System.out.println("支付结果返回值(解密后):" + decryParams); |
| | | |
| | | String decryParams = EncryptDecryptFactory.execute(smallWeChatDto.getObjId(), 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")) |
| | | || !"SUCCESS".equals(paramOut.getString("status")) |
| | | || !"SUCCESS".equals(paramOut.getString("deal_status"))) { |
| | | && !"0001".equals(paramOut.getString("return_code")) |
| | | ) { |
| | | throw new IllegalArgumentException("支付失败" + paramOut.getString("return_message")); |
| | | } |
| | | SortedMap<String, String> resultMap = new TreeMap<String, String>(); |
| | |
| | | @Override |
| | | public PaymentOrderDto java110NotifyPayment(NotifyPaymentOrderDto notifyPaymentOrderDto) { |
| | | |
| | | String opToken_RSA2 = CommunitySettingFactory.getValue(notifyPaymentOrderDto.getCommunityId(), "opToken_RSA2"); |
| | | String bank_PublicKey_RSA2 = CommunitySettingFactory.getRemark(notifyPaymentOrderDto.getCommunityId(), "bank_PublicKey_RSA2"); |
| | | String privateKey_SM4 = CommunitySettingFactory.getValue(notifyPaymentOrderDto.getCommunityId(), "privateKey_SM4"); |
| | | |
| | | String resXml = ""; |
| | | String param = notifyPaymentOrderDto.getParam(); |
| | | PaymentOrderDto paymentOrderDto = new PaymentOrderDto(); |
| | | Map<String, Object> responseParams = JsonUtil.jsonToMap(param); |
| | | // 开始解密 |
| | | String decryptBase64Str = (String) responseParams.get("enc_data"); |
| | | String verifyBase64Str = (String) responseParams.get("sign"); |
| | | byte[] bt = AesEncrypt.parseHexStr2Byte(decryptBase64Str); |
| | | byte[] decrypt = new byte[0]; |
| | | try { |
| | | decrypt = AesEncrypt.decryptByte(bt, opToken_RSA2); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | Map<String, Object> responseParams = JsonUtil.jsonToMap(param); |
| | | if (!responseParams.containsKey("enc_data")) { |
| | | System.err.println("通知失败"); |
| | | throw new IllegalArgumentException("通知失败"); |
| | | } |
| | | if (decrypt == null) { |
| | | 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("解密失败"); |
| | | } |
| | | boolean isSuccess = false; |
| | | try { |
| | | isSuccess = CAUtil.rsa256Verify(decrypt, verifyBase64Str, bank_PublicKey_RSA2); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | System.out.println("数据验签:" + isSuccess); |
| | | if (!isSuccess) { |
| | | System.err.println("验签失败"); |
| | | throw new IllegalArgumentException("验签失败"); |
| | | } |
| | | String decryParams = new String(decrypt); |
| | | String decryParams = GmUtil.decryptSm4(decryptStr, secretKey); |
| | | |
| | | System.out.println("支付结果返回值(解密后):" + decryParams); |
| | | |
| | | JSONObject paramOut = JSONObject.parseObject(decryParams); |