xyzxy

java微信开发便捷框架

基于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);
    }

posted on 2020-08-12 16:57  咸鱼张  阅读(600)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-12-31
  • 2021-09-28
  • 2021-11-05
  • 2021-10-07
  • 2021-12-10
  • 2021-11-30
  • 2021-11-26
  • 2021-12-10
猜你喜欢
  • 2021-11-17
  • 2021-08-16
  • 2021-09-02
  • 2021-07-08
  • 2022-12-23
  • 2022-01-18
  • 2022-02-09
相关资源
相似解决方案