添加了微信小程序绑定网站账号的接口

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-09-09 16:07:07 +08:00
parent afcf629670
commit 8d58208e64
2 changed files with 25 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.SysUserService; import com.xkrs.service.SysUserService;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -251,4 +252,19 @@ public class SysUserController {
return sysUserService.findUserByOpenId(openId); return sysUserService.findUserByOpenId(openId);
} }
/**
* 绑定网站账号
* @param map
* @return
*/
@Transactional(rollbackFor=Exception.class)
@PostMapping("/updateOpenIdByPhone")
public String updateOpenIdByPhone(@RequestBody Map map){
Locale locale = LocaleContextHolder.getLocale();
String openId = (String) map.get("openId");
String phone = (String) map.get("phone");
sysUserDao.updateOpenIdByPhone(phone,openId);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale);
}
} }

View File

@ -134,4 +134,13 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
* @return * @return
*/ */
SysUserEntity findByOpenId(String openId); SysUserEntity findByOpenId(String openId);
/**
* 根据用户名手机号修改openid
* @param userName
* @param openId
*/
@Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true)
@Modifying(clearAutomatically=true)
void updateOpenIdByPhone(String userName,String openId);
} }