
微信
在进行
微信公众平台,开发配置时,出现一系列问题,在此记录,与网友共享: 1.
服务器配置,需要填写url,但不知该如何填写,后经查阅,得知,所填url必须为可访问的接口,于是重新按网友提供的思路,整理接口如下,一共两个类文件: package com.
..wxgzh.controller; import
Java.io.IOException; import
Javax.servlet.http.HttpServletRequest; import org.
Springframework.web.bind.annotation.RequestMapping; import org.
Springframework.web.bind.annotation.RequestMethod; import org.
Springframework.web.bind.annotation.ResponseBody; import org.
Springframework.web.bind.annotation.RestController; import com.jubao.dling.wxgzh.utils.CheckUtil; import io.swagger.annotations.Api; @RestController @RequestMapping(value=/wxgzh) @Api(description=
微信公众号操作) public class WeiXinController { @RequestMapping(value=/getWxInform,method=RequestMethod.GET) @ResponseBody public String getWeiXinMethod(HttpServletRequest request) throws IOException{ String signature = request.getParameter(signature); String timestamp = request.getParameter(timestamp); String nonce = request.getParameter(nonce); String echostr = request.getParameter(echostr); if(CheckUtil.checkSignature(signature, timestamp, nonce)){ return echostr; } return error; } } package com.
..wxgzh.utils; import
Java.security.MessageDigest; import
Java.util.
Arrays; public class CheckUtil { private static final String token = yuliusa2018; public static boolean checkSignature(String signature,String timestamp,String nonce){ String[] arr = new String[]{token,timestamp,nonce}; //排序
Arrays.sort(arr); //生成字符串 StringBuffer content = new StringBuffer(); for(int i=0;i 4 & 0xf]; buf[k++] = hexDigits[byte0 & 0xf]; } return new String(buf); } catch (Exception e) { return null; } } } 2.回到公众号平台,进行配置,注意token随便写,但必须和接口中定义的token保持一致
3.点击提交,出现【系统错误,请稍后重试】 对上错误进行排查,最终把端口号443去掉,然后在提交,居然又出现“请求URL超时”,如下: 查阅网上的各种方案都没解决,后看到有网友说可能是服务器配置低,于是换了台服务器,竟然提交成功了。 以上记录是自己开发过程中的问题总结,也希望能帮助他人。