cn.binarywang.wx.miniapp.bean.WxMaUserInfo Java Examples
The following examples show how to use
cn.binarywang.wx.miniapp.bean.WxMaUserInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WxUserController.java From oneplatform with Apache License 2.0 | 6 votes |
/** * <pre> * 获取用户信息接口 * </pre> */ @GetMapping("/info") @ApiPermOptions(perms = PermissionType.Logined) public String info(@PathVariable String appid, String sessionKey, String signature, String rawData, String encryptedData, String iv) { final WxMaService wxService = weixinAppManager.getMaService(appid); // 用户信息校验 if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) { return "user check failed"; } // 解密用户信息 WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv); return JsonUtils.toJson(userInfo); }
Example #2
Source File: WxMaUser.java From yue-library with Apache License 2.0 | 5 votes |
/** * <pre> * 获取用户信息 * </pre> * * @param appid APPID * @param sessionKey 会话密钥 * @param signature 数据签名 * @param rawData 微信用户基本信息 * @param encryptedData 消息密文 * @param iv 加密算法的初始向量 * @return {@linkplain WxMaUserInfo} 微信小程序用户信息 */ public WxMaUserInfo getUserInfo(String appid, String sessionKey, String signature, String rawData, String encryptedData, String iv) { WxMaService wxService = getMaService(appid); // 用户信息校验 if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) { throw new ParamException("user check failed"); } // 解密用户信息 WxMaUserInfo wxMaUserInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv); return wxMaUserInfo; }
Example #3
Source File: WxMaUserServiceImplTest.java From weixin-java-tools with Apache License 2.0 | 5 votes |
@Test public void testGetUserInfo() { WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo("tiihtNczf5v6AKRyjwEUhQ==", "CiyLU1Aw2KjvrjMdj8YKliAjtP4gsMZMQmRzooG2xrDcvSnxIMXFufNstNGTyaGS9uT5geRa0W4oTOb1WT7fJlAC+oNPdbB+3hVbJSRgv+4lGOETKUQz6OYStslQ142dNCuabNPGBzlooOmB231qMM85d2/fV6ChevvXvQP8Hkue1poOFtnEtpyxVLW1zAo6/1Xx1COxFvrc2d7UL/lmHInNlxuacJXwu0fjpXfz/YqYzBIBzD6WUfTIF9GRHpOn/Hz7saL8xz+W//FRAUid1OksQaQx4CMs8LOddcQhULW4ucetDf96JcR3g0gfRK4PC7E/r7Z6xNrXd2UIeorGj5Ef7b1pJAYB6Y5anaHqZ9J6nKEBvB4DnNLIVWSgARns/8wR2SiRS7MNACwTyrGvt9ts8p12PKFdlqYTopNHR1Vf7XjfhQlVsAJdNiKdYmYVoKlaRv85IfVunYzO0IKXsyl7JCUjCpoG20f0a04COwfneQAGGwd5oa+T8yO5hzuyDb/XcxxmK01EpqOyuxINew==", "r7BXXKkLb8qrSNn05n0qiA=="); assertNotNull(userInfo); System.out.println(userInfo.toString()); }
Example #4
Source File: WxMaUserController.java From sdb-mall with Apache License 2.0 | 5 votes |
/** * <pre> * 获取用户信息接口 * </pre> */ @GetMapping("/info") public String info(String sessionKey, String signature, String rawData, String encryptedData, String iv) { // 用户信息校验 if (!this.wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) { return "user check failed"; } // 解密用户信息 WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv); return JsonUtils.toJson(userInfo); }
Example #5
Source File: UserServiceImpl.java From sdb-mall with Apache License 2.0 | 5 votes |
@Override public User addMaUser(WxMaUserInfo wxMaUserInfo) { User user = new User(); String userId = snService.generate(SnEnum.USER); user.setUserId(userId); user.setAvatar(wxMaUserInfo.getAvatarUrl()); user.setMaOpenId(wxMaUserInfo.getOpenId()); user.setNickname(wxMaUserInfo.getNickName()); user.setGender(Integer.parseInt(wxMaUserInfo.getGender())); user.setUnionId(wxMaUserInfo.getUnionId()); Language language = Language.getByEnumName(wxMaUserInfo.getLanguage()); user.setLanguage((int)language.getValue()); user.save(); return user; }
Example #6
Source File: AuthController.java From supplierShop with MIT License | 4 votes |
/** * 小程序登陆,颁发token,暂时模拟openid * * @return token字符串 */ @PostMapping("/oauth/access_token") @ApiOperation(value = "获取token",notes = "获取token") public R loginReturnToken(@Validated @RequestBody LoginVO loginVO) { Boolean isProduct = false; //true 开启真实小程序环境 String openid = "orIMY4xGhMmipwFZoSL1vOhUNFZ0"; WxMaUserInfo userInfo = null; try{ if(isProduct){ WxMaJscode2SessionResult session = wxService.getUserService() .getSessionInfo(loginVO.getCode()); //log.info(session.getSessionKey()); //log.info(session.getOpenid()); //TODO 可以增加自己的逻辑,关联业务相关数据 String sessionKey = session.getSessionKey(); openid = session.getOpenid(); // 解密用户信息 userInfo = wxService.getUserService() .getUserInfo(sessionKey, loginVO.getEncrypted_data(), loginVO.getIv()); } StoreMember member = memberService.login(openid); User user = null; if(member == null){ //新用户插入数据 StoreMember newMember = new StoreMember(); newMember.setOpenid(userInfo.getOpenId()); newMember.setNickname(userInfo.getNickName()); newMember.setHeadimg(userInfo.getAvatarUrl()); newMember.setSex(userInfo.getGender()); newMember.setCreateTime(new Date()); memberService.save(newMember); user = User.builder() .id(newMember.getId().intValue()) .username(newMember.getNickname()) .build(); }else{ user = User.builder() .id(member.getId().intValue()) .username(member.getNickname()) .build(); } String token = operator.generateToken(user); HashMap<String,String> map = new HashMap<>(); map.put("access_token",token); return R.success(map); } catch (WxErrorException e) { log.error(e.getMessage()); return R.error(4000,e.getMessage()); } }
Example #7
Source File: WxMaUserServiceImpl.java From weixin-java-tools with Apache License 2.0 | 4 votes |
@Override public WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr) { return WxMaUserInfo.fromJson(WxMaCryptUtils.decrypt(sessionKey, encryptedData, ivStr)); }
Example #8
Source File: WxMaUserController.java From sdb-mall with Apache License 2.0 | 4 votes |
/** * 登陆接口 */ @PostMapping("/login") public R login(HttpServletRequest request, @RequestBody MaLoginForm maLoginForm) { if (StringUtils.isBlank(maLoginForm.getCode())) { return R.error("empty jscode"); } try { WxMaJscode2SessionResult session = this.wxService.getUserService().getSessionInfo(maLoginForm.getCode()); String sessionKey = session.getSessionKey(); String openId = session.getOpenid(); // 用户信息校验 if (!this.wxService.getUserService().checkUserInfo(sessionKey, maLoginForm.getRawData(), maLoginForm.getSignature())) { return R.error("user check failed"); } User user = new User(); user.setMaOpenId(openId); User dbUser = userService.findFirstByModel(user); if (dbUser == null) { // 解密用户信息 WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(sessionKey, maLoginForm.getEncryptedData(), maLoginForm.getIv()); dbUser = userService.addMaUser(userInfo); if (dbUser.getUserId() == null) { return R.error(ResultEnum.MA_LOGIN_ERROR); } } //生成token String token = jwtUtils.generateToken(dbUser.getUserId()); Map<String, Object> map = new HashMap<>(); map.put("token", token); map.put("expire", jwtUtils.getExpire()); return R.ok(map); } catch (WxErrorException e) { this.logger.error(e.getMessage(), e); return R.error(e.toString()); } }
Example #9
Source File: WxMaUserService.java From weixin-java-tools with Apache License 2.0 | 2 votes |
/** * 解密用户敏感数据. * * @param sessionKey 会话密钥 * @param encryptedData 消息密文 * @param ivStr 加密算法的初始向量 */ WxMaUserInfo getUserInfo(String sessionKey, String encryptedData, String ivStr);
Example #10
Source File: UserService.java From sdb-mall with Apache License 2.0 | votes |
User addMaUser(WxMaUserInfo wxMaUserInfo);