微信公众号静默授权获取用户openId
开发环境和文档
1.微信
微信公众平台接口测试帐号申请
无需公众帐号、快速申请接口测试号
直接体验和测试公众平台所有高级接口
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
微信公众号接入配置
/**
* @author scw
* @create 2018-01-18 11:38
* @desc 微信前端连接的主要控制类
**/
@Controller
public class WeChatDogPrimaryController {
/**
* 进行微信用户验证,只能是Get方法
* @param request
* @param response
*/
@RequestMapping(value = "/wechat" ,method = RequestMethod.GET)
public void connectValidate(HttpServletRequest request , HttpServletResponse response) throws IOException {
String signature = request.getParameter("signature");
String timestamp = request.getParameter("timestamp");
String nonce = request.getParameter("nonce");
String echostr = request.getParameter("echostr");
System.out.println(""+signature +"@"+timestamp +"$"+nonce +"^"+echostr);
PrintWriter out = response.getWriter();
if(CheckConnectUtils.checkConncetWithWeChat(signature,timestamp,nonce)){
out.print(echostr);
}
}
package com.example.line.utils;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
/**
* @author scw
* @create 2018-01-17 9:28
* @desc 检查微信和服务器是否链接成功
**/
public class CheckConnectUtils {
private static final String token = "wechat";
/**
* 判断是否链接匹配
* @param signature
* @param timestamp
* @param nonce
* @return
*/
public static boolean checkConncetWithWeChat(String signature,String timestamp,String nonce){
String[] arr = new String[]{
token,timestamp,nonce}