一.申请一个微信公众号(步骤略过)
二.java实现h5自定义分享链接
前端阅读官方文档: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
1. 获取access_token
// 获取token
private StringgetAccessToken() {
String access_token ="";
String grant_type ="client_credential";// 获取access_token填写client_credential
// 第三方用户唯一凭证密钥,即appsecret
// 这个url链接地址和参数皆不能变
String url = WechatAuthConstants.TOKEN_URL + grant_type +"&appid=" + WechatAuthConstants.WECHAT_APPID +"&secret="+ WechatAuthConstants.WECHAT_SECRET; // 访问链接
try {
URL urlGet =new URL(url);
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
http.setRequestMethod("GET"); // 必须是get方式请求
http.setRequestProperty("Content-Type", "application/x-www-form-ur