问题发现:
在进行微信公众号接口开发过程中,进行数据的上传时报出以下异常:
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed
大概意思是知道,是因为jdk对不存在信任的网站进行https访问时,就会报出该异常
可是我内网穿透和服务器地址都用的http,怎么还会有这个异常呢,而且我还用HttpCilentUitl进行访问转换过
然后翻了半天源码,发现问题出在这:
public String menuCreate(String json) throws WxErrorException {
JsonObject jsonObject = GsonParser.parse(json);
Menu url = Menu.MENU_CREATE;
if (jsonObject.get("matchrule") != null) {
url = Menu.MENU_ADDCONDITIONAL;
}
微信自带的api封装了一个固定的url格式,再跟进发现:
public static enum Menu implements WxMpApiUrl {
GET_CURRENT_SELFMENU_INFO("https://api.weixin.qq.com", "/cgi-bin/get_current_selfmenu_info"),
MENU_TRYMATCH("https://api.weixin.qq.com", "/cgi-bin/menu/trymatch"),
MENU_GET("https://api.weixin.qq.com", "/cgi-bin/menu/get"),
MENU_DELCONDITIONAL("https://api.weixin.qq.com", "/cgi-bin/menu/delconditional"),
MENU_DELETE("https://api.weixin.qq.com", "/cgi-bin/menu/delete"),
MENU_CREATE("https://api.weixin.qq.com", "/cgi-bin/menu/create"),
MENU_ADDCONDITIONAL("https://api.weixin.qq.com", "/cgi-bin/menu/addconditional");
}
全部用的https请求,那样的话,只有老办法,将证书添加到jre中了:
1、下载证书:
命名为mpwx:
保存到C:\java-se-8u41-ri\jre\lib\security
2、在该目录下执行命令安装到密钥库:
keytool -import -trustcacerts -alias mpwx -file mpwx.cer -keystore cacerts -storepass changeit
3、重启服务再次访问,完美解决。不过,今天的头发也掉完了