微信公众号开发者授权token和code接入流程

阅读: 评论:0

微信公众号开发者授权token和code接入流程

微信公众号开发者授权token和code接入流程

关于微信授权开发

微信公众号开发,在对接微信功能接口时,需要一些注意事项

  1. 明确要对接的功能接口

微信接口权限列表说明:

=table&token=1888019159&lang=zh_CN

 

  1. 确认是否已经获得接口权限

  1. 关于订阅号与服务号区别

登录mp.weixin.qq

通过微信APP客户端区别订阅号与服务号

搜索公众号,“xxx”进入公众号之后,回复一条消息,再返回到微信主界面,如果是服务号,则消息就跟朋友发消息一样,显示在主界面;

如果是订阅号,则不会显示在主界面,只能通过订阅号信息进去查看

  1. 对接过程之Token授权

准备好需要的参数

 

=wxd690fddcfe8f9cad&redirect_uri=http%3A%%2Fops-weixin%2Flogin&response_type=code&scope=snsapi_base&state=123&uin=NjYwMzAxOTIy&key=017ad372b1a9e9bfaa3fc8f5dacd0c3e674707335cedb6aa2a6351a6776999345d452feddbb7decbd85202b060d7ec1b&pass_ticket=rej60aFejS9PX7tK6Q8WYQfz+n3ArzMpNx17E77xTC2LioH42X+sE1LyMppEQUw9yJugavEiLwxTEQ3naWh76g==

网页授权回调接口Java版本

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.weixin4j.Configuration;
import org.weixin4j.util.TokenUtil;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Desc: 微信开发接口控制器
 * @author: learnworm
 * @date: 2018/4/20 8:37
 */
@Controller
@RequestMapping("/wxtoken")
public class WeixinIndexUrlController {
    private final static Logger logger = Logger(WeixinIndexUrlController.class);

    @RequestMapping(value = "/", method = {RequestMethod.POST, RequestMethod.GET})
    public void initNoFilter(ServletRequest req, ServletResponse res)  throws IOException, ServletException  {
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) res;
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        if (Configuration.isDebug()) {
            logger.debug("--> Acquire weixin request:" + Method() + " Method");
            logger.debug("--> Weixin request url:" + ServletPath());
        }
        //消息来源可靠性验证
        String signature = Parameter("signature");// 微信加密签名
        logger.debug(signature);
        String timestamp = Parameter("timestamp");// 时间戳
        logger.debug(timestamp);
        String nonce = Parameter("nonce");       // 随机数
        logger.debug(nonce);
        //Token为weixin4j.properties中配置的Token
        String token = ();
        System.out.println("token:"+token);
        logger.debug(token);
        String echostr = Parameter("echostr");
        PrintWriter out = Writer();
        if (TokenUtil.checkSignature(token, signature, timestamp, nonce)) {
            out.print(echostr);
        }
        out.close();
        out = null;
    }
}

 

本文发布于:2024-01-31 06:36:28,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170665419126293.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:开发者   公众   流程   token   code
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23