敏感词加密

Map<String, Object> weChatPlatformCertificateMap = payScorePartnerService.getPartnerCertificate(你的商户id, "wechat_platform_certificate");【public Map<String, Object> getPartnerCertificate(String 你的商户id, String weChatPlatformCertificateKey) throws ServiceException {//存缓存Map<String, Object> certificate = wechatPayV3CertificateCache.getPartnerWeChatPlatformCertificate(weChatPlatformCertificateKey);if (certificate.get("certificate") != null) {return certificate;}// 当前没有证书,重新拉取拉取微信证书String certNo = 你的证书编号;String v3Key = 你的v3key;你的商户id = properties.getPayscore().getPartnerMchId();String uri = WeChatPayV3Constants.PARTNER_GET_PLATFORM_CERTIFICATES;JSONObject result = weChatPayV3Template.doGet(uri, 你的商户id, 你的证件编号);【public JSONObject doGet(String uri, String 你的商户id, String 你的证件编号) throws ServiceException {String url = String.format("%1$s%2$s", WeChatPayV3Constants.DOMAIN, uri);// 添加请求头MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();headers.add("Content-Type", "application/json");headers.add("Accept", "application/json");String certKeyPath = wechatProperties.getCertKeyPath(你的商户id);//        String certKeyPath = wechatProperties.getPayscore().getPartnerPrivateKeyUrl();// 生成支付签名String token = WeChatPayV3Util.getToken("GET", uri, 你的商户id, "", 你的证件编号, certKeyPath);String authorization = WeChatPayV3Constants.WECHAT_SCHEMA + " " + token;headers.add("Authorization", authorization);log.info("#################### 微信支付v3开始请求 url:{} ####################", url);HttpEntity httpEntity = new HttpEntity<>(headers);ResponseEntity<String> responseEntity = null;try {responseEntity = reqRestTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class);} catch (HttpStatusCodeException e) {log.error("########## 请求错误:code: {}, message: {} ##########", e.getStatusCode(), e.getResponseBodyAsString());String body = e.getResponseBodyAsString();if (StringUtils.isNotEmpty(body)) {Map bodyMap = JsonUtils.toMap(body);if (bodyMap != null && bodyMap.containsKey("message")) {if ("ORDER_NOT_EXIST".equals(bodyMap.get("code").toString()) || "CONTRACT_NOT_EXIST".equals(bodyMap.get("code").toString())) {throw new ServiceException(ErrorCode.ayment_wechat_v3_request_failed_order_not_exist, bodyMap.get("message").toString());}throw new ServiceException(ErrorCode.payment_wechat_v3_request_error, bodyMap.get("message").toString());}}throw new ServiceException(ErrorCode.payment_wechat_v3_request_error, e.getResponseBodyAsString());} catch (RestClientException e) {log.error("请求接口失败", e);throw new ServiceException(ErrorCode.payment_wechat_v3_request_error, e.getMessage());}if (!responseEntity.getStatusCode().is2xxSuccessful()) {String result = responseEntity.getBody();WeChatPayV3ResultEntity wxResultEntity = JSONObject.parseObject(result, WeChatPayV3ResultEntity.class);log.error("#################### 微信支付请求失败 statusCode:{},code:{},msg:{}, detail:{} ####################",responseEntity.getStatusCode(), wxResultEntity.getCode(), wxResultEntity.getMessage(), wxResultEntity.getDetail());throw new ServiceException(ErrorCode.payment_wechat_v3_request_error, wxResultEntity.getMessage());}HttpHeaders responseHeaders = responseEntity.getHeaders();// 微信支付唯一请求IdList<String> uniqueReqId = responseHeaders.get("Request-ID");log.debug("#################### 微信支付v3收到响应,responseCode:{}, uniqueReqId:{}, data:{} ####################",responseEntity.getStatusCode(), uniqueReqId, responseEntity);return JSONObject.parseObject(responseEntity.getBody());}】List<WechatPayCertificatesVo> payCertificatesList = JSONArray.parseArray(result.getString("data"), WechatPayCertificatesVo.class);// 拿到最新的微信平台证书// 解密微信通知数据payCertificatesList.stream().forEach(item -> {WechatPayEncryptCertificateDataVo encryptCertificate = item.getEncryptCertificate();String associatedData = encryptCertificate.getAssociatedData();String nonce = encryptCertificate.getNonce();String cipherText = encryptCertificate.getCipherText();String certificateInfo = WeChatPayV3Util.decryptToString(associatedData, nonce, cipherText, v3Key);// 将证书数据缓存到redisString serialNo = item.getSerialNo();Date effectiveTime = item.getEffectiveTime();Date expireTime = item.getExpireTime();wechatPayV3CertificateCache.cacheWeChatPlatformCertificate(weChatPlatformCertificateKey,serialNo, certificateInfo, expireTime, effectiveTime);});Map<String, Object> certificateMap = wechatPayV3CertificateCache.getPartnerWeChatPlatformCertificate(weChatPlatformCertificateKey);if (Objects.isNull(certificate)) {throw new ServiceException(ErrorCode.payment_pay_score_get_cert_error);}return certificateMap;}】
String certEntityString = String.valueOf(weChatPlatformCertificateMap.get("certificate"));
String serial = String.valueOf(weChatPlatformCertificateMap.get("serial_no"));
//将证书转化成x509格式
InputStream in = new ByteArrayInputStream(certEntityString.getBytes("utf-8"));
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Certificate cert = certFactory.generateCertificate(in);
CertHttpUtil.rsaEncryptOAEP(要加密的值, (X509Certificate) cert);【public static String rsaEncryptOAEP(String message, X509Certificate certificate)throws IllegalBlockSizeException, IOException {try {Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding");cipher.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey());byte[] data = message.getBytes("utf-8");byte[] cipherdata = cipher.doFinal(data);return Base64.encodeBase64String(cipherdata);} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {throw new RuntimeException("当前Java环境不支持RSA v1.5/OAEP", e);} catch (InvalidKeyException e) {throw new IllegalArgumentException("无效的证书", e);} catch (IllegalBlockSizeException | BadPaddingException e) {throw new IllegalBlockSizeException("加密原串的长度不能超过214字节");}}】

大佬勿喷,欢迎提意见建议评论!!!!

微信支付--敏感词加密相关推荐

  1. 微信支付:小微商户申请入驻第三步:平台证书序列号解密和敏感词加密

    首先,还是上微信官方链接 微信官方平台证书解密指引 微信官方敏感词加密指引 平台证书解密 定义接口 首先,由于平台证书获取,跟解密,都是平台证书这货的,那就放在同一个service吧.pom文件之前文 ...

  2. 微信支付获取rsa加密公钥

    转载: (119条消息) Java 微信企业付款到个人银行卡-调用获取RSA公钥API__single.的博客-CSDN博客

  3. java请求url加密_SpringCloud-Config通过Java访问URL对敏感词加密解密

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  4. nodejs实现微信支付小微商户申请入驻接口

    微信支付小微商户可以通过小程序<微信买单服务商助手>来进件,也可以通过API接口来进件(详情可查阅小微商户专属接口文档). 2种方式进件后的商户是有区别的 不同进件方式下的小微商户对比   ...

  5. 微信支付的密钥和证书的使用

    微信支付的密钥和证书的使用 微信支付中使用到的密钥和证书(这里只介绍APIv3密钥) 一.密钥和证书有哪些 商户API证书(商户公钥),通过商户平台提供的证书工具产生 微信平台证书(微信公钥),通过平 ...

  6. PHP开发微信支付小微商户V3版本 图片上传、生成签名、平台证书获取、平台证书编号、敏感信息加密

    吐槽一下,看微信支付小微商户的开发文档头都大了,什么是平台证书.什么是商户API证书...... 好了废话不多说下面明确几个名词: 商户API证书:是由权威CA颁发,用于有关微信支付等操作API接口使 ...

  7. Android 微信支付加密

    项目中接入支付功能,支付宝一次过 唯独这个微信,后台说是前端自己加密(真坑爹) 如何接入微信支付就不说了,重点加密 客户端微信加密 //activity中 private IWXAPI iwxapi; ...

  8. 企业微信又更新了!聊天敏感词、下载直播回放视频、聊天文件支持10GB...

    企业微信版本已更新至3.0.36,还没有更新的速速去升级啦! 一.客户联系功能增强 企业可设置聊天敏感词,设置后将下载到成员的企业微信.当成员发送给客户的消息包含敏感词时,将予以提示或发送失败. 登录 ...

  9. 微信分享链接含敏感词被屏蔽的问题

    最近在开发一个微信活动web页面时,遇到了一个奇怪的问题.我调用了微信JS-SDK的接口,但是分享出去的链接有时正常,有时异常.而且分享时发送方分享链接有图标,接收方分享链接没有图标.截图如下: 我的 ...

最新文章

  1. 从MongoDB迁移到ES后,我们减少了80%的服务器
  2. PHP静态方法和属性
  3. Mac下文件的编码及修改编码
  4. Python初识与简介【开篇】
  5. C#Socket通信
  6. C/C++ 中判断某一文件或目录是否存在
  7. 神经网络中BP(back propagation)到底在干些什么
  8. go语言一个包含nil指针的接口不是nil接口的理解
  9. 《团队名称》第八次团队作业:Alpha冲刺day1
  10. POJ 1759 Garland
  11. mysql创建表shop_ShopXO商城-支付方式 - 数据库设计 - 数据库表结构 - 果创云
  12. python输出语句格式 f_Python基础之输出格式和If判断
  13. python把print写入文件_python print输出到文件
  14. Error response from daemon: Cannot restart container mdet_jc: OCI runtime create failed(fork/exec /)
  15. 一文读懂最新 Google 开发者大会上的 ARCore!
  16. 分享Java开发经验去鹅厂面试的经历,你值得~
  17. 【Python】list写入txt文件
  18. matlab计算特征多项式
  19. 转载自网眼的QQ微博(http://t.qq.com/zhangking)
  20. 吴京砸向MOSS的伏特加,被做成了串口助手

热门文章

  1. OpenShift 4 之让Route只运行在集群中Infra节点
  2. sata学习5:常用的概率函数
  3. 恶意代码分析-静态分析基础
  4. 【技术干货】听阿里云CDN安防技术专家金九讲SystemTap使用技巧
  5. java web应用开发技术_第一章 Java Web应用开发技术
  6. idea提示未找到包,实际上包存在 问题解决
  7. 三星 j3 android 8.0,三星J3 Pro官方台湾版安卓8.0固件线刷包:BRI-J330GDXS3BSF5
  8. HTML页面、CSS样式的以及js学习与介绍
  9. java 风的角度转风向
  10. JS文件应该放在什么位置