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

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

本文整理了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

@PostMapping("bindPhone")
public Object bindPhone(@LoginUser Integer userId, @RequestBody String body) {
  String sessionKey = UserTokenManager.getSessionKey(userId);
  String encryptedData = JacksonUtil.parseString(body, "encryptedData");
  String iv = JacksonUtil.parseString(body, "iv");
  WxMaPhoneNumberInfo phoneNumberInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
  String phone = phoneNumberInfo.getPhoneNumber();
  LitemallUser user = userService.findById(userId);
  user.setMobile(phone);
  if (userService.updateById(user) == 0) {
    return ResponseUtil.updatedDataFailed();
  }
  return ResponseUtil.ok();
}

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

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

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

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

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

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

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

/**
   * <pre>
   * 获取用户绑定手机号信息
   * </pre>
   */
  @GetMapping("/phone")
  public String phone(String sessionKey, String signature, String rawData, String encryptedData, String iv) {
    // 用户信息校验
    if (!this.wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
      return "user check failed";
    }

    // 解密
    WxMaPhoneNumberInfo phoneNoInfo = this.wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);

    return JsonUtils.toJson(phoneNoInfo);
  }
}

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

/**
 * <pre>
 * 获取用户绑定手机号信息
 * </pre>
 */
@GetMapping("/phone")
public String phone(@PathVariable String appid, String sessionKey, String signature,
          String rawData, String encryptedData, String iv) {
  final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  // 用户信息校验
  if (!wxService.getUserService().checkUserInfo(sessionKey, rawData, signature)) {
    return "user check failed";
  }
  // 解密
  WxMaPhoneNumberInfo phoneNoInfo = wxService.getUserService().getPhoneNoInfo(sessionKey, encryptedData, iv);
  return JsonUtils.toJson(phoneNoInfo);
}

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

/**
 * <pre>
 * 获取用户信息接口
 * </pre>
 */
@GetMapping("/info")
public String info(@PathVariable String appid, String sessionKey,
          String signature, String rawData, String encryptedData, String iv) {
  final WxMaService wxService = WxMaConfiguration.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);
}

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

/**
 * 登陆接口
 */
@GetMapping("/login")
public String login(@PathVariable String appid, String code) {
  if (StringUtils.isBlank(code)) {
    return "empty jscode";
  }
  final WxMaService wxService = WxMaConfiguration.getMaService(appid);
  try {
    WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
    this.logger.info(session.getSessionKey());
    this.logger.info(session.getOpenid());
    //TODO 可以增加自己的逻辑,关联业务相关数据
    return JsonUtils.toJson(session);
  } catch (WxErrorException e) {
    this.logger.error(e.getMessage(), e);
    return e.toString();
  }
}

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

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

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

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

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

@Override
public SysUserAuthentication authenticate(IntegrationAuthentication integrationAuthentication) {
  WxMaJscode2SessionResult session = null;
  String password = integrationAuthentication.getAuthParameter("password");
  try {
    session = this.wxMaService.getUserService().getSessionInfo(password);
    WechatMiniAppToken wechatToken = new WechatMiniAppToken(session.getOpenid(), session.getUnionid(), session.getSessionKey());
    // 加密算法的初始向量
    wechatToken.setIv(integrationAuthentication.getAuthParameter("iv"));
    // 用户的加密数据
    wechatToken.setEncryptedData(integrationAuthentication.getAuthParameter("encryptedData"));
  } catch (WxErrorException e) {
    throw new InternalAuthenticationServiceException("获取微信小程序用户信息失败",e);
  }
  String openId = session.getOpenid();
  SysUserAuthentication sysUserAuthentication = sysUserClient.findUserBySocial(UcClientConstant.SOCIAL_TYPE_WECHAT_MINIAP, openId);
  if(sysUserAuthentication != null){
    sysUserAuthentication.setPassword(passwordEncoder.encode(password));
  }
  return sysUserAuthentication;
}

相关文章