登录微信公众号后台 如果自定义菜单可以直接用,就可以在这里创建
我的方式:通过代码
根据微信接口文档 https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html
需要直接跳转h5页面 已有对应 URL
使用 创建菜单接口
- 新建一个信任管理类 (网上找的)
package com.bootdo.sharebus.token;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
public class MyX509TrustManager implements X509TrustManager {
// 对于https请求,我们需要一个证书信任管理器
// 检查客户端证书
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
// 检查服务器端证书
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
// 返回受信任的X509证书数组
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
2.建立Token实体类存储 获取的access_token
package com.bootdo.sharebus.token;
public class Token {
// 接口访问凭证֤
private String accessToken;
// 凭证有效期,单位:秒
private int expiresIn;
public String getAccessToken() {
return accessToken;
}
public void setAccessToken(String accessToken) {
this.accessToken = accessToken;
}
public int getExpiresIn() {
return expiresIn;
}
public void setExpiresIn(int expiresIn) {
this.expiresIn = expiresIn;
}
}
3.创建token获取类
package com.bootdo.sharebus.token;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.bootdo.sharebus.utils.SendRequest;
import com.bootdo.sharebus.utils.WeixinParamUtil;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;
public class TokenUtil {
private static Logger log = LoggerFactory.getLogger(TokenUtil.class);
// 凭证获取(GET)https请求方式: GET
// grant_type 获取access_token填写client_credential appid 第三方用户唯一凭证 secret
// 第三方用户唯一凭证密钥,即appsecret
// https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&app