社区
Java
帖子详情
微信公众平台自定义菜单,使用JAVA get请求https://api.weixin.qq.com/cgi-bin/token?grant_type=clien
WW_NULL
2013-08-07 03:00:53
在做自定义菜单的时候,我通过在浏览器输入https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET 获取凭证后,然后使用获取的access_token完成了提交自定义菜单。但是我想通过JAVA代码来获取凭证(access_token),因为是get请求的是https协议所以无法获取到,小弟初来乍到,还请各位大神帮帮忙.
...全文
17606
7
打赏
收藏
微信公众平台自定义菜单,使用JAVA get请求https://api.weixin.qq.com/cgi-bin/token?grant_type=clien
在做自定义菜单的时候,我通过在浏览器输入https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET 获取凭证后,然后使用获取的access_token完成了提交自定义菜单。但是我想通过JAVA代码来获取凭证(access_token),因为是get请求的是https协议所以无法获取到,小弟初来乍到,还请各位大神帮帮忙.
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
Bug开发攻城狮
2016-03-16
打赏
举报
回复
参考这篇文章 http://blog.csdn.net/zy_281870667/article/details/50906817
lifeng396442668
2015-05-22
打赏
举报
回复
这样就行了 /** * 重新包装httpclient对象,忽略证书验证 * * @param httpClient * @return * @author:Administrator * @date:2014-9-2 */ private static DefaultHttpClient getSecuredHttpClient(HttpClient httpClient) { final X509Certificate[] _AcceptedIssuers = new X509Certificate[] {}; try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return _AcceptedIssuers; } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { } }; ctx.init(null, new javax.net.ssl.TrustManager[] { tm }, new SecureRandom()); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); ClientConnectionManager ccm = httpClient.getConnectionManager(); SchemeRegistry sr = ccm.getSchemeRegistry(); sr.register(new Scheme("https", 443, ssf)); return new DefaultHttpClient(ccm, httpClient.getParams()); } catch (Exception e) { System.out.println("=====:====="); e.printStackTrace(); } return null; } //获取 public static void main(String[] args) { String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET"; BufferedReader in = null; String content = null; try { HttpClient client = getSecuredHttpClient(new DefaultHttpClient()); // 实例化HTTP方法 HttpGet request = new HttpGet(); request.setURI(new URI(url)); HttpResponse response = client.execute(request); in = new BufferedReader(new InputStreamReader(response.getEntity() .getContent())); StringBuffer sb = new StringBuffer(""); String line = ""; String NL = System.getProperty("line.separator"); while ((line = in.readLine()) != null) { sb.append(line + NL); } in.close(); content = sb.toString(); System.out.println(content); } catch (Exception e) { } finally { if (in != null) { try { in.close();// 最后要关闭BufferedReader } catch (Exception e) { e.printStackTrace(); } } } }
xiaowanzi80hou
2014-07-30
打赏
举报
回复
引用 3 楼 jia20003 的回复:
创建一个SSLSocket,然后自己发给它,接受返回的JSON即可! 这个不是问题! 我一直这么干!
微信公众平台跟开发服务器可以用https通信?
I-miss-you
2014-02-13
打赏
举报
回复
加上这两句代码 HttpClient httpclient = new DefaultHttpClient(); httpclient = HttpUtil.wrapClient(httpclient); 绕过认证 /** * 避免HttpClient的”SSLPeerUnverifiedException: peer not authenticated”异常 * 不用导入SSL证书 * * @author shipengzhi(shipengzhi@sogou-inc.com) * */ public static org.apache.http.client.HttpClient wrapClient(org.apache.http.client.HttpClient base) { try { SSLContext ctx = SSLContext.getInstance("TLS"); X509TrustManager tm = new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } @SuppressWarnings("unused") public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @SuppressWarnings("unused") public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { } @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws java.security.cert.CertificateException { } }; ctx.init(null, new TrustManager[] { tm }, null); SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("https", 443, ssf)); ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(registry); return new DefaultHttpClient(mgr, base.getParams()); } catch (Exception ex) { ex.printStackTrace(); return null; } }
gloomyfish
2013-12-02
打赏
举报
回复
创建一个SSLSocket,然后自己发给它,接受返回的JSON即可! 这个不是问题! 我一直这么干!
u012981742
2013-11-28
打赏
举报
回复
http://my.csdn.net/
「已注销」
2013-11-18
打赏
举报
回复
哥们 你弄好了吗????? 我遇到了同样的问题 求教
Node.js
微信
access_
token
( js
api
_ticket ) 存取与刷新的示例
access_
token
微信
文档里存在两种access_
token
:普通 access_
token
和 网页授权 access_
token
。具体区别参考:...
GET请求
:
https
://
api
.
weixin
.
qq
.
com
/
cgi
-
bin
/
token
?
grant
_
type
=
clien
t_credential
微信
小程序 带参数二维码 C# asp.net 服务端程序
作者:采购员乙,来自原文地址 第一步 获取access_
token
: ...string result = HttpGet("
https
://
api
.
weixin
.
qq
.
com
/
cgi
-
bin
/
token
?
grant
_
type
=
clien
t_credential&appid=wx***********d&secret=a*************
Python实现
微信
公众
平台
自定义
菜单
实例
url = '
https
://
api
.
weixin
.
qq
.
com
/
cgi
-
bin
/
token
?
grant
_
type
=
clien
t_credential&appid=%s&secret=%s' % ( Config.AppID, Config.AppSecret) result = urllib2.urlopen(url).read() Config.access_
token
= json....
微信
自定义
菜单
的处理开发示例
$
token
_access_url =
https
://
api
.
weixin
.
qq
.
com
/
cgi
-
bin
/
token
?
grant
_
type
=
clien
t_credential&appid= . APPID . &secret= . APPSECRET; $res = file_get_contents($
token
_access_url); //获取文件内容或...
message-to-weapp
https
://
api
.
weixin
.
qq
.
com
/
cgi
-
bin
/
token
?
grant
_
type
=
clien
t_credential&appid=APPID&secret=APPSECRET
GET请求
,需要以下参数
grant
_
type
: 填
clien
t_credential即可。 appid: 小程序唯一凭证。可在「 - 设置 - ...
Java
51,402
社区成员
85,918
社区内容
发帖
与我相关
我的任务
Java
Java相关技术讨论
复制链接
扫一扫
分享
社区描述
Java相关技术讨论
java
spring boot
spring cloud
技术论坛(原bbs)
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章