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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM