Java 获取微信公众号code,openID

本文主要是关于微信公众号开发过程中获取code、openID的方法
1.首先获取code的方式有两种,一是直接后端通过微信公众号的菜单按钮中配置接口,后端直接获取code值。
在微信公众号的自定义菜单中新增一个按钮,跳转网页地址找中填写

https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://xxxxxxx/getCode&response_type=code&scope=snsapi_base&connect_redirect=1#wechat_redirect

appid 每个微信公众号不一样,已这种方式后台接口 getCode

 @RequestMapping(value = "/getCode", method = {RequestMethod.GET, RequestMethod.POST})
    public String getCode(String code)  {
        System.out.println("获取微信code" + code);
        return "redirect:跳转至指定页面";
}

2.第二种方式是直接在自定以中跳转至前端页面,由前端截取code值,返回给后端

https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://xxxx/wechat/test.html&response_type=code&scope=snsapi_base&connect_redirect=1#wech
  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值