微信公众号开发文档:https://mp.weixin.qq.com/wiki
微信公众平台接口调试工具:https://mp.weixin.qq.com/debug/cgi-bin/apiinfo
JAVA微信公众号开发框架:Wechat4j
Wechat4j帮助文档:http://www.chengn.com/wechat4j/wiki/jieruzhinan.html
**************************************************************************
*****我们暂时先不用Wechat4j****
(第一部分)
******需结合微信公众号开发文档来看.******
1.填写服务器基本配置:
URL:必须以http://或https://开头,分别支持80端口和443端口。
没有服务器的可以去下一个花生壳 映射一下。
![](https://img-blog.csdn.net/20161203205249520?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
2.检验signature的示例代码:
- public static Boolean checkSignature(String signature,String timestamp,String nonce){
- String[] strs=new String[] {token,timestamp,nonce};
- Arrays.sort(strs);
- StringBuffer content=new StringBuffer();
- for (int i = 0; i < strs.length; i++) {
- content.append(strs[i]);
- }
- MessageDigest md = null;
- String tmpStr = null;
- try {
- <span style="white-space:pre"> </span>md = MessageDigest.getInstance("SHA-1");
-
- byte[] digest = md.digest(content.toString().getBytes());
- tmpStr = byteToStr(digest);
- } catch (NoSuchAlgorithmException e) {
- e.printStackTrace();
- }
- return signature!=null?signature.toUpperCase().equals(tmpStr.toUpperCase()):false;
- }
3.依据接口文档实现业务逻辑。
4.获取access_token:
公众号可以使用AppID和AppSecret调用接口来获取access_token
http请求方式: GET
https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
-
-
-
-
-
-
-
- public static AccessToken getAccessToken(String appid, String appsecret) {
- AccessToken accessToken = null;
- String requestUrl = access_token_url.replace("APPID", appid).replace("APPSECRET", appsecret);
- JSONObject jsonObject = httpRequest(requestUrl, "GET", null);
- if (null != jsonObject) {
- try {
- accessToken = new AccessToken();
- accessToken.setAccess_token(jsonObject.getString("access_token"));
- accessToken.setExpires_in(jsonObject.getInt("expires_in"));
- } catch (JSONException e) {
- accessToken = null;
-
- log.error("获取token失败 errcode:{} errmsg:{}", jsonObject.getInt("errcode"), jsonObject.getString("errmsg"));
- }
- }
- return accessToken;
- }
-