微信公众号静默授权获取用户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}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值