代码运行报"errcode":43003,"errmsg":"require https hints: [EfAd244ce-SFCF8!]"}错误,该如何解决?
错误如下:
[20-7-2 11:10:35:916 CST] 00000028 SystemOut O trytrytrytrytrytrytrytrytrytry
[20-7-2 11:10:35:916 CST] 00000028 SystemOut O 1111111111111111
[20-7-2 11:10:35:916 CST] 00000028 SystemOut O urlStr--http://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx59fcee41cd6332a2&secret=e2c516dc7003cc6c0bbfee3ebbc18e98
[20-7-2 11:10:35:958 CST] 00000028 SystemOut O str---{"errcode":43003,"errmsg":"require https hints: [EfAd244ce-SFCF8!]"}
[20-7-2 11:10:35:958 CST] 00000028 SystemOut O str3---errmsg
[20-7-2 11:10:35:958 CST] 00000028 SystemOut O accesstoken---errmsg
部分代码如下:
System.out.println("trytrytrytrytrytrytrytrytrytry");
String jsonstring = "";
String jsonstringnew="";
System.out.println("1111111111111111");
String urlStr="http://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxx&secret=xxxxxxxx";
//String urlStr="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=zzzzzzz&secret=zzzzzzz";
System.out.println("urlStr--"+urlStr);
URL url;
url = new URL(urlStr);
URLConnection urlConnection=url.openConnection();
InputStream in=urlConnection.getInputStream();
InputStreamReader read=new InputStreamReader(in,Charset.forName("UTF-8"));
BufferedReader bread=new BufferedReader(read);
String str1=null;
StringBuffer strb=new StringBuffer();
if(null!=(str1=bread.readLine())){
strb.append(str1);
}
bread.close();
read.close();
in.close();
String str=strb.toString();
System.out.println("str---"+str);
String[] ss = str.split("\"");
String str3 = ss[3];
System.out.println("str3---"+str3);
String accesstoken=str3;
System.out.println("accesstoken---"+accesstoken);
String urlStr1="https://api.weixin.qq.com/cgi-bin/get_current_selfmenu_info?access_token="+accesstoken;
URL url1=new URL(urlStr1);
URLConnection urlConnection1=url1.openConnection();
InputStream in1=urlConnection1.getInputStream();
InputStreamReader read1=new InputStreamReader(in1,Charset.forName("UTF-8"));
BufferedReader bread1=new BufferedReader(read1);
String str2=null;
StringBuffer strb1=new StringBuffer();
if(null!=(str2=bread1.readLine())){
strb1.append(str2);
}
bread.close();
read.close();
in.close();
String str34=strb1.toString();
require subscribe错误说明你没有订阅该测试号,该错误仅测试号会出现
require https hints:提示需要https请求协议,微信接口应该是https安全协议,把http改成https试试,即:
String urlStr="http://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxx&secret=xxxxxxxx";
改成
String urlStr="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxxx&secret=xxxxxxxx";
require https 应该是让请求使用HTTPS的意思吧
把你的网址改为HTTPS的
用的是nginx服务的反向代理做https请求,在http配置中添加一行resolver 8.8.8.8;就可以了