微信绑定实现
This commit is contained in:
parent
06d22250af
commit
2ed61ba13c
|
|
@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.sqx.common.annotation.Debounce;
|
import com.sqx.common.annotation.Debounce;
|
||||||
import com.sqx.common.utils.Result;
|
import com.sqx.common.utils.Result;
|
||||||
|
import com.sqx.modules.app.annotation.Login;
|
||||||
|
import com.sqx.modules.app.dto.BindWxDTO;
|
||||||
import com.sqx.modules.app.dto.LoginDTO;
|
import com.sqx.modules.app.dto.LoginDTO;
|
||||||
import com.sqx.modules.app.dto.RegisterDTO;
|
import com.sqx.modules.app.dto.RegisterDTO;
|
||||||
import com.sqx.modules.app.dto.UserInviteDTO;
|
import com.sqx.modules.app.dto.UserInviteDTO;
|
||||||
|
|
@ -168,6 +170,14 @@ public class AppLoginController {
|
||||||
return userService.register(registerDTO);
|
return userService.register(registerDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Login
|
||||||
|
@PostMapping("/bindWx")
|
||||||
|
@ResponseBody
|
||||||
|
@Debounce(interval = 2500, value = "#code")
|
||||||
|
public Result bindWx(@RequestBody BindWxDTO bindWxDTO, @RequestHeader Long userId) {
|
||||||
|
return userService.bindWx(bindWxDTO, userId);
|
||||||
|
}
|
||||||
|
|
||||||
@PostMapping("/bindWxOpenPhone")
|
@PostMapping("/bindWxOpenPhone")
|
||||||
@ApiOperation("微信公众号绑定手机号")
|
@ApiOperation("微信公众号绑定手机号")
|
||||||
public Result bindWxOpenPhone(Long userId,String phone,String msg){
|
public Result bindWxOpenPhone(Long userId,String phone,String msg){
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.sqx.modules.app.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Administrator
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class BindWxDTO {
|
||||||
|
@NotEmpty(message = "code不能为空")
|
||||||
|
private String code;
|
||||||
|
}
|
||||||
|
|
@ -238,4 +238,6 @@ public interface UserService extends IService<UserEntity> {
|
||||||
Result removeUserBlack(Long userId, Integer status);
|
Result removeUserBlack(Long userId, Integer status);
|
||||||
|
|
||||||
Map<String, Object> queryPayAndExtractInfo();
|
Map<String, Object> queryPayAndExtractInfo();
|
||||||
|
|
||||||
|
Result bindWx(BindWxDTO bindWxDTO, Long userId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,6 +80,7 @@ import org.springframework.context.annotation.Lazy;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import weixin.popular.api.SnsAPI;
|
import weixin.popular.api.SnsAPI;
|
||||||
|
import weixin.popular.bean.sns.SnsToken;
|
||||||
import weixin.popular.util.JsonUtil;
|
import weixin.popular.util.JsonUtil;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
@ -1824,4 +1825,28 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result bindWx(BindWxDTO bindWxDTO, Long userId) {
|
||||||
|
//微信appid
|
||||||
|
CommonInfo one = commonInfoService.findOne(5);
|
||||||
|
//微信秘钥
|
||||||
|
CommonInfo two = commonInfoService.findOne(21);
|
||||||
|
SnsToken snsToken = SnsAPI.oauth2AccessToken(one.getValue(), two.getValue(), bindWxDTO.getCode());
|
||||||
|
String openid = snsToken.getOpenid();
|
||||||
|
int count = count(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getWxOpenId, openid));
|
||||||
|
if (count > 0) {
|
||||||
|
return Result.error("该微信已被其他用户绑定");
|
||||||
|
}
|
||||||
|
|
||||||
|
UserEntity userEntity = getOne(new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
|
||||||
|
if (StringUtils.isNotBlank(userEntity.getWxOpenId())) {
|
||||||
|
return Result.error("当前用户已绑定微信");
|
||||||
|
}
|
||||||
|
|
||||||
|
userEntity.setWxOpenId(openid);
|
||||||
|
userEntity.setUpdateTime(DateUtil.now());
|
||||||
|
update(userEntity, new LambdaQueryWrapper<UserEntity>().eq(UserEntity::getUserId, userId));
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue