IJPay微信退款协议不正确 No appropriate protocol
目录
- 问题发现
- 问题研究
- 解决方案
问题发现
项目中有微信支付功能,也可以微信退款,因为自己写支付代码比较臃肿,所以用了第三方包IJPay来实现支付和退款功能,它封装了一些第三方支付的方法,比如支付宝、微信、银联,使用了一年多没有问题,前端时间突然使用微信退款功能时报错:
cn.hutool.core.io.IORuntimeException: SSLHandshakeException: No appropriate protocol (protocol is disabled or cipher suites are inappropriate)
问题研究
上网搜索发现微信社区看到也有人出同样的错:微信社区链接
百度上搜索也有人说是jdk版本问题的,但是我这个一开始没错所以我觉得不关jdk的问题,也没有往这方面研究,然后我找到IJPay的码云Issues:IJPay码云链接
里面也有人提到这个问题,IJPay作者也发现了,提供了版本升级,之前退款用的方法是orderRefund,现在加了一个orderRefundByProtocol方法,可以自己手动输入协议,我想这个问题肯定立马解决了,测试orderRefundByProtocol方法的协议填null,报空指针异常,填“”、“SSLv3”、“SSLv2”均报以上同样的错误(No appropriate protocol)
就觉得很奇怪,然后追溯IJPay的源码:
// 1.自己的业务代码String refundStr = WxPayApi.orderRefundByProtocol(false, params, certPath, account.getMchid(),"");
// 2public static String orderRefundByProtocol(boolean isSandbox, Map<String, String> params, String certPath, String certPass, String protocol) {return execution(getReqUrl(WxApiType.REFUND, (WxDomain)null, isSandbox), params, certPath, certPass, protocol);}
// 3.此方法中的参数filePath为上一步中的参数protocolpublic static String execution(String apiUrl, Map<String, String> params, String certPath, String certPass, String filePath) {return doUploadSsl(apiUrl, params, certPath, certPass, filePath);}
// 4. 此方法参数filePath实际为protocolpublic static String doUploadSsl(String url, Map<String, String> params, String certPath, String certPass, String filePath) {return HttpKit.getDelegate().upload(url, WxPayKit.toXml(params), certPath, certPass, filePath);}
// 5.public String upload(String url, String data, String certPath, String certPass, String filePath) {return this.upload(url, data, certPath, certPass, filePath, "TLSv1");}
// 6.此方法中的protocol为5步骤中的代码写死的“TLSv1”,那么是否实际执行的时候还是用的TLSv1协议,而不是自己参数里面写的协议public String upload(String url, String data, String certPath, String certPass, String filePath, String protocol) {try {File file = FileUtil.newFile(filePath);return ((HttpRequest)HttpRequest.post(url).setSSLSocketFactory(SSLSocketFactoryBuilder.create().setProtocol(protocol).setKeyManagers(this.getKeyManager(certPass, certPath, (InputStream)null)).setSecureRandom(new SecureRandom()).build()).header("Content-Type", "multipart/form-data;boundary=\"boundary\"")).form("file", file).form("meta", data).execute().body();} catch (Exception var8) {throw new RuntimeException(var8);}}
以上是orderRefundByProtocol方法的调用链路,我发现可能是这个方法根本没有用上自己填写的协议,一筹莫展,如果抛弃IJPay重写代码的话,花费的时间较多,因为项目已发布在线上也怕出错,所以只好先在IJPay的Issues里面提了自己的问题,希望作者能给与解决办法,正当我想要放弃,等待作者解决办法的时候,我想到用IJPay里面封装的底层方法。
解决方案
通过以上源码追溯,orderRefund方法中调用的AbstractHttpDelegate这个抽象类的post方法,IJPay是写死的“TLSv1”,我们只需要单独调用这个方法,把里面的协议直接填写""就行了,贴上代码:
// 自己的业务代码String refundStr = HttpKit.getDelegate().post(WxPayApi.getReqUrl(WxApiType.REFUND, (WxDomain) null, false), WxPayKit.toXml(params), certPath, account.getMchid(), "");// 实际调用AbstractHttpDelegate类中的方法public String post(String url, String data, String certPath, String certPass, String protocol) {try {return HttpRequest.post(url).setSSLSocketFactory(SSLSocketFactoryBuilder.create().setProtocol(protocol).setKeyManagers(this.getKeyManager(certPass, certPath, (InputStream)null)).setSecureRandom(new SecureRandom()).build()).body(data).execute().body();} catch (Exception var7) {throw new RuntimeException(var7);}}
没有悬念,一下就成功了!
IJPay微信退款协议不正确 No appropriate protocol相关推荐
- java 微信退款接口_java版微信和支付宝退款接口
本文实例为大家分享了java微信退款接口和支付宝退款接口的具体代码,供大家参考,具体内容如下 1.微信退款接口 相对来说我感觉微信的退款接口还是比较好调用的,直接发送httppost请求即可: /** ...
- 微信退款参数格式错误
微信退款失败返回信息是: <xml><return_code><![CDATA[FAIL]]></return_code> <return_msg ...
- 微信退款流程实现整理(java)
前言 此处整理为简便,将所有应用到的方法都整理到了一起,实际开发中尽量将controller,service,mapper,工具类分开.此文章着重注意退款回调,其中应用了数据解密(作者一开始困扰在此处 ...
- SpringBoot集成微信支付微信退款
微信支付 备注:本次支付接入的是微信支付v2.0版本,其中所有的请求格式均为XML. 如有需求可直接参阅官方文档 https://pay.weixin.qq.com/wiki/doc/api/inde ...
- 微信-微信退款(三)
一.微信申请退款 微信支付退款 API 地址 https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_4&index=6 应用 ...
- java ssm框架调用微信_Java开发SSM框架微信退款的实现
这篇文章是Java微信退款的教程,退款之前用户需要先进行支付,支付之后才可以使用退款.做到退款的同学应该已经是完成了支付了,我写的退款和支付的流程很相似只是所需的参数有所不同. String outT ...
- java 微信退款配置_微信支付退款配置
微信支付退款配置 1.微信支付配置 第一步,登录商城后台,设置->交易设置->支付配置 ,选择微信支付,点击配置进入到微信支付参数配置界面. 从应用ID和应用密钥下面的提示可以看出,微信支 ...
- Niushop微信支付配置、微信退款配置、微信转账配置操作流程
前几期,阿牛ger主要与大家分享了关于宝塔配置.接口插件配置.地址设置.版权设置等的代码,今天,阿牛ger与大家分享微信支付配置. 微信支付配置: 一.开通产品 首先需要在微信商户号中需要开通一下产品 ...
- 支付退款流程设计_Niushop微信支付配置、微信退款配置、微信转账配置操作流程...
前几期,阿牛ger主要与大家分享了关于宝塔配置.接口插件配置.地址设置.版权设置等的代码,今天,阿牛ger与大家分享微信支付配置. 微信支付配置: 一.开通产品 首先需要在微信商户号中需要开通一下产品 ...
最新文章
- Neutron 网络基本概念
- JVM类加载(2)—连接
- JavaSE学习总结第08天_面向对象3
- Equipment download - post processing
- HDU 3342 Legal or Not(拓扑排序)
- python做一个考试系统_Python在线考试系统防作弊功能的思路和实现
- 企业越来越重视即时通讯内部应用
- AC+AP组网和MESH组网介绍和区别
- 如何打开剪贴板查看器?
- 数学符号——指示函数(样子像空心的1的一个数学符号)
- cad布局教程_10+篇CAD三维模型一键出工程图,你掌握了?
- 面试官:讲讲互斥锁、自旋锁吧
- 北京五险一金介绍及公积金领取办法
- 创立仅一年GMV突破3亿!这个新锐品牌如何在快手实现爆发?
- 客单价怎么算 影响客单价的主要因素有哪些?
- 会员等级进度功能前端实现
- 微信h5登录php,vue实现微信授权登录步骤详解
- ProxmoxVE 干掉 VMware
- android碰撞动画,Android实战打飞机游戏之子弹生成与碰撞以及爆炸效果(5)
- Sigar监控服务器环境CPU 内存 硬盘 网络流量