微信公众号开发自定义菜单跳转页面

微信公众号开发:

自定义菜单:静默授权跳转服务器上的url
https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=http://www.aaa.com/bbb&response_type=code&scope=snsapi_base&state=123&connect_redirect=1#wechat_redirect
返回回调函数http://www.aaa.com/bbb?code=code&state=123调用实际需要调用的接口,获取code后,调用
https://api.weixin.qq.com/sns/oauth2/access_token?appid=appid&secret=secret&code=code&grant_type=authorization_code
获取用户access_token和openid

例如

@RequestMapping(value = "toadd", produces = "text/plain; charset=UTF-8")
    public String toadd(@RequestParam(value = "code", required = true) String code,@RequestParam(value = "state", required = true) String state,HttpServletRequest request){
        String response = "";
          String openidurl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=appid&secret=secret&code="+code+"&grant_type=authorization_code";
        String str = HttpRequestUrl.sendPost(openidurl,"");//post发送
        if("error".equals(str)){
            logger.error("url error");
        }else{
            //解析字符串
            JSONObject jObj = JSONObject.fromObject(str);
            String access_token = String.valueOf(jObj.get("access_token"));
            String openid = String.valueOf(jObj.get("openid"));
            request.setAttribute("openid",openid);
        }
        return "aa/aa/aa-zc";
    }

 

 

微信公众号点击自助菜单后,跳转到服务器上的页面,点击页面上按钮时,ajax调用失败,原因是因为需要在调用ajax时加上

contentType : "application/x-www-form-urlencoded; charset=utf-8",

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值