cn.binarywang.wx.miniapp.api.WxMaService.getUserService()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(5.8k)|赞(0)|评价(0)|浏览(1667)

本文整理了Java中cn.binarywang.wx.miniapp.api.WxMaService.getUserService()方法的一些代码示例,展示了WxMaService.getUserService()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WxMaService.getUserService()方法的具体详情如下:
包路径:cn.binarywang.wx.miniapp.api.WxMaService
类名称:WxMaService
方法名:getUserService

WxMaService.getUserService介绍

[英]返回用户相关接口方法的实现类对象,以方便调用其各个接口.
[中]返回用户相关接口方法的实现类对象,以方便调用其各个接口.

代码示例

代码示例来源:origin: linlinjava/litemall

  1. @PostMapping("bindPhone")
  2. public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
  3. String sessionKey = UserTokenManager.getSessionKey(userId);
  4. String encryptedData = JacksonUtil.parseString(body, "encryptedData");
  5. String iv = JacksonUtil.parseString(body, "iv");
  6. WxMaPhoneNumberInfo phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
  7. String phone = phoneNumberInfo.getPhoneNumber();
  8. LitemallUser user = userService.findById(userId);
  9. user.setMobile(phone);
  10. if (userService.updateById(user) == 0) {
  11. return ResponseUtil.updatedDataFailed();
  12. }
  13. return ResponseUtil.ok();
  14. }

代码示例来源:origin: linlinjava/litemall

  1. WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(wxCode);
  2. openId = result.getOpenid();
  3. } catch (Exception e) {

代码示例来源:origin: linlinjava/litemall

  1. String openId = null;
  2. try {
  3. WxMaJscode2SessionResult result = this.wxService.getUserService().getSessionInfo(code);
  4. sessionKey = result.getSessionKey();
  5. openId = result.getOpenid();

代码示例来源:origin: yjjdick/sdb-mall

  1. /**
  2. * <pre>
  3. * 获取用户信息接口
  4. * </pre>
  5. */
  6. @GetMapping("/info")
  7. public String info(String sessionKey, String signature, String rawData, String encryptedData, String iv) {
  8. // 用户信息校验
  9. if (!this.wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  10. return "user check failed";
  11. }
  12. // 解密用户信息
  13. WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
  14. return JsonUtils.toJson(userInfo);
  15. }

代码示例来源:origin: yjjdick/sdb-mall

  1. /**
  2. * <pre>
  3. * 获取用户绑定手机号信息
  4. * </pre>
  5. */
  6. @GetMapping("/phone")
  7. public String phone(String sessionKey, String signature, String rawData, String encryptedData, String iv) {
  8. // 用户信息校验
  9. if (!this.wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  10. return "user check failed";
  11. }
  12. // 解密
  13. WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
  14. return JsonUtils.toJson(phoneNoInfo);
  15. }
  16. }

代码示例来源:origin: binarywang/weixin-java-miniapp-demo

  1. /**
  2. * <pre>
  3. * 获取用户绑定手机号信息
  4. * </pre>
  5. */
  6. @GetMapping("/phone")
  7. public String phone(@PathVariable String appid, String sessionKey, String signature,
  8. String rawData, String encryptedData, String iv) {
  9. final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  10. // 用户信息校验
  11. if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  12. return "user check failed";
  13. }
  14. // 解密
  15. WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
  16. return JsonUtils.toJson(phoneNoInfo);
  17. }

代码示例来源:origin: binarywang/weixin-java-miniapp-demo

  1. /**
  2. * <pre>
  3. * 获取用户信息接口
  4. * </pre>
  5. */
  6. @GetMapping("/info")
  7. public String info(@PathVariable String appid, String sessionKey,
  8. String signature, String rawData, String encryptedData, String iv) {
  9. final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  10. // 用户信息校验
  11. if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
  12. return "user check failed";
  13. }
  14. // 解密用户信息
  15. WxMaUserInfo userInfo = wxService.getUserService().getUserInfo(sessionKey, encryptedData, iv);
  16. return JsonUtils.toJson(userInfo);
  17. }

代码示例来源:origin: binarywang/weixin-java-miniapp-demo

  1. /**
  2. * 登陆接口
  3. */
  4. @GetMapping("/login")
  5. public String login(@PathVariable String appid, String code) {
  6. if (StringUtils.isBlank(code)) {
  7. return "empty jscode";
  8. }
  9. final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  10. try {
  11. WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
  12. this.logger.info(session.getSessionKey());
  13. this.logger.info(session.getOpenid());
  14. //TODO 可以增加自己的逻辑,关联业务相关数据
  15. return JsonUtils.toJson(session);
  16. } catch (WxErrorException e) {
  17. this.logger.error(e.getMessage(), e);
  18. return e.toString();
  19. }
  20. }

代码示例来源:origin: yjjdick/sdb-mall

  1. WxMaJscode2SessionResult session = this.wxService.getUserService().getSessionInfo(maLoginForm.getCode());
  2. if (!this.wxService.getUserService().checkUserInfo(sessionKey, maLoginForm.getRawData(), maLoginForm.getSignature())) {
  3. return R.error("user check failed");
  4. if (dbUser == null) {
  5. WxMaUserInfo userInfo = this.wxService.getUserService().getUserInfo(sessionKey, maLoginForm.getEncryptedData(), maLoginForm.getIv());
  6. dbUser = userService.addMaUser(userInfo);
  7. if (dbUser.getUserId() == null) {

代码示例来源:origin: ustcwudi/springboot-seed

  1. String code = integrationAuthentication.getAuthParameter("password");
  2. try {
  3. session = this.wxMaService.getUserService().getSessionInfo(code);
  4. } catch (WxErrorException e) {
  5. e.printStackTrace();

代码示例来源:origin: leecho/cola-cloud

  1. @Override
  2. public SysUserAuthentication authenticate(IntegrationAuthentication integrationAuthentication) {
  3. WxMaJscode2SessionResult session = null;
  4. String password = integrationAuthentication.getAuthParameter("password");
  5. try {
  6. session = this.wxMaService.getUserService().getSessionInfo(password);
  7. WechatMiniAppToken wechatToken = new WechatMiniAppToken(session.getOpenid(), session.getUnionid(), session.getSessionKey());
  8. // 加密算法的初始向量
  9. wechatToken.setIv(integrationAuthentication.getAuthParameter("iv"));
  10. // 用户的加密数据
  11. wechatToken.setEncryptedData(integrationAuthentication.getAuthParameter("encryptedData"));
  12. } catch (WxErrorException e) {
  13. throw new InternalAuthenticationServiceException("获取微信小程序用户信息失败",e);
  14. }
  15. String openId = session.getOpenid();
  16. SysUserAuthentication sysUserAuthentication = sysUserClient.findUserBySocial(UcClientConstant.SOCIAL_TYPE_WECHAT_MINIAP, openId);
  17. if(sysUserAuthentication != null){
  18. sysUserAuthentication.setPassword(passwordEncoder.encode(password));
  19. }
  20. return sysUserAuthentication;
  21. }

相关文章