基于Spring Boot 和 WxJava 实现的微信公众号Java后端Demo,支持多公众号.

支持包括微信支付、开放平台、小程序、企业微信/企业号和公众号等的后端开发.

坐标->       

  <dependency>
            <groupId>com.github.binarywang</groupId>
            <artifactId>weixin-java-miniapp</artifactId>
            <version>3.8.0</version>
        </dependency>

git:https://github.com/binarywang

示例:

 

    @Value("${wx.APPID}")
    private String APPID = "";

    @Value("${wx.secret}")
    private String SECRET = "";

    @Value("${wx.appToken}")
    private String APP_TOKEN = "";
   

    @ApiOperation(value = "获取openId(新版本)")
    @GetMapping("/getAuthOpenId")
    public Result login(String code) throws WxErrorException {
        wxMaConfig=new WxMaDefaultConfigImpl();
        wxMaConfig.setAppid(APPID);
        wxMaConfig.setSecret(SECRET);
        wxMaConfig.setMsgDataFormat("JSON");
        wxMaConfig.setToken(APP_TOKEN);
        service= new WxMaServiceImpl();
        service.setWxMaConfig(wxMaConfig);
        
        WxMaJscode2SessionResult session = service.getUserService().getSessionInfo(code);
        
        redisUtils.set(session.getOpenid(), session.getSessionKey());
        redisUtils.expire(session.getOpenid(),60*5 );//五分钟过期
        return Result.success(session.getOpenid());
    }
        /**
     *通过openId登录
     * @author ZhangYB
     * 2020年8月12日-下午3:11:53
     */
    @ApiOperation(value = "通过opendid登录")
    @GetMapping("/loginByOpenId")
    @Inner
    public Result testUserInfo(String openId ,String encryptedData,String ivStr) {
        
        Object sessionKey = redisUtils.get("openId");
        if (sessionKey==null) {
            return Result.fail(500,"session过期");
        }
        WxMaPhoneNumberInfo phoneNoInfo = service.getUserService().getPhoneNoInfo((String)sessionKey, encryptedData, ivStr);
        System.err.println(phoneNoInfo.toString());
        return Result.success(phoneNoInfo);
    }