| | |
| | | </description> |
| | | |
| | | <dependencies> |
| | | |
| | | <dependency> |
| | | <groupId>commons-httpclient</groupId> |
| | | <artifactId>commons-httpclient</artifactId> |
| | | <version>3.1</version> |
| | | </dependency> |
| | | |
| | | <!-- RuoYi Common Core--> |
| | | <dependency> |
| | |
| | | public R<?> changePassword(@RequestParam("username") String username, |
| | | @RequestParam("password") String password, |
| | | @RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | |
| | | @PostMapping("/user/getSysUser") |
| | | public R<SysUser> getSysUser(@RequestBody Long userId); |
| | | |
| | | @PostMapping("/user/registerUser") |
| | | public R<SysUser> registerUser(@RequestBody SysUser sysUser); |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.constants; |
| | | |
| | | /** |
| | | * @author jqs34 |
| | | * @ClassName SecurityConstant |
| | | * @description: TODO |
| | | * @date 2023年02月21日 |
| | | * @version: 1.0 |
| | | */ |
| | | public interface SecurityConstant { |
| | | |
| | | |
| | | /** |
| | | * 微信sessionKey前缀 |
| | | */ |
| | | String SESSION_KEY = "SESSION_KEY:"; |
| | | |
| | | |
| | | /** |
| | | * 用户验证码前缀key |
| | | */ |
| | | String MESSAGE_CODE = "MESSAGE_CODE:"; |
| | | |
| | | /** |
| | | * 用户验证码前缀key |
| | | */ |
| | | String MINI_CODE = "MINI_CODE:"; |
| | | |
| | | /** |
| | | * 用户验证码前缀key |
| | | */ |
| | | String WX_TOKEN = "WX_TOKEN"; |
| | | |
| | | /** |
| | | * 省市区列表key |
| | | */ |
| | | String REGION_LIST = "REGION_LIST"; |
| | | |
| | | /** |
| | | * 省市区列表key |
| | | */ |
| | | String CITY_LIST = "CITY_LIST"; |
| | | |
| | | /** |
| | | * 秒杀活动商品key前缀 |
| | | */ |
| | | String ACTIVITY_GOODS = "ACTIVITY_GOODS"; |
| | | |
| | | /** |
| | | * 自动取消订单时间 |
| | | */ |
| | | String AUTO_CANCEL_ORDER_TIME = "AUTO_CANCEL_ORDER_TIME"; |
| | | |
| | | /** |
| | | * 商户统一分成 |
| | | */ |
| | | String SHOP_COMMON_PROPORTION = "SHOP_COMMON_PROPORTION"; |
| | | |
| | | /** |
| | | * 自动取消订单时间 |
| | | */ |
| | | String PAY_MONEY_INTEGRAL = "PAY_MONEY_INTEGRAL"; |
| | | |
| | | /** |
| | | * 用户验证码前缀key |
| | | */ |
| | | String QY_TOKEN = "QY_TOKEN"; |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.domain; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AppMiniLoginVO { |
| | | |
| | | @ApiModelProperty(value = "小程序openid") |
| | | private String miniOpenid; |
| | | |
| | | @ApiModelProperty(value = "微信unionid") |
| | | private String wxUnionid; |
| | | |
| | | @ApiModelProperty(value = "微信sessionKey") |
| | | private String sessionKey; |
| | | |
| | | |
| | | @ApiModelProperty("支付宝用戶ID") |
| | | private String zfbuserid; |
| | | |
| | | @ApiModelProperty(value = "用户信息") |
| | | private SysUser sysUser; |
| | | |
| | | @ApiModelProperty(value = "会员id") |
| | | private Long memberid; |
| | | |
| | | @ApiModelProperty(value = "拍卖师电话") |
| | | private String phone; |
| | | |
| | | |
| | | |
| | | } |
| | |
| | | @ApiModelProperty(value = "1未认证,2已认证") |
| | | private Integer isAuthentication; |
| | | |
| | | |
| | | @ApiModelProperty(value = "后天对应id") |
| | | private Long userId; |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.domain.dto; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AppMiniLoginDTO { |
| | | |
| | | //微信的 |
| | | @ApiModelProperty(value = "微信的code") |
| | | private String code; |
| | | |
| | | |
| | | //支付宝微信的 |
| | | @ApiModelProperty(value = "支付宝的auth_code") |
| | | private String auth_code; |
| | | |
| | | @ApiModelProperty("1支付宝 , 2微信") |
| | | private Integer type; |
| | | |
| | | } |
New file |
| | |
| | | package com.ruoyi.system.api.domain.dto; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | @Data |
| | | public class AppMiniRegisterDTO { |
| | | @ApiModelProperty(value = "openid") |
| | | private String miniOpenid; |
| | | |
| | | @ApiModelProperty(value = "wxUnionid") |
| | | private String wxUnionid; |
| | | |
| | | @ApiModelProperty(value = "支付寶的用戶id") |
| | | private String zfbuserid; |
| | | |
| | | @ApiModelProperty("1支付宝 , 2微信") |
| | | private Integer type; |
| | | |
| | | } |
| | |
| | | package com.ruoyi.system.api.factory; |
| | | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.MemberAddress; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | |
| | | public R<List<Member>> getMemberListByIds(Set<Long> memberIdList, String source) { |
| | | return R.fail("获取用户列表失败:" + cause.getMessage()); |
| | | } |
| | | |
| | | public R<AppMiniLoginVO> miniLogin(AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | return R.fail("登录用户失败:" + cause.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<AppMiniLoginVO> actionMiniLogin(AppMiniLoginDTO appMiniLoginDto) { |
| | | return R.fail("拍卖师登录用户失败:" + cause.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<AppMiniLoginVO> miniRegister(AppMiniRegisterDTO appUserRegisterDto) { |
| | | return R.fail("注册用户失败:" + cause.getMessage()); |
| | | } |
| | | }; |
| | | |
| | | } |
| | |
| | | { |
| | | return R.fail("注册用户失败:" + throwable.getMessage()); |
| | | } |
| | | @Override |
| | | public R<SysUser> registerUser(SysUser sysUser) { |
| | | return R.fail("注册用户失败:" + throwable.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<?> changePassword(String username, String password, String source) { |
| | | return R.fail("修改密码失败:" + throwable.getMessage()); |
| | | } |
| | | |
| | | @Override |
| | | public R<SysUser> getSysUser(Long userId) { |
| | | return R.fail("获取用户失败" + throwable.getMessage()); |
| | | } |
| | | }; |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.constant.ServiceNameConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.MemberAddress; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import com.ruoyi.system.api.factory.MemberFallbackFactory; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | |
| | | @PostMapping("/member/list-by-ids") |
| | | R<List<Member>> getMemberListByIds(@RequestParam("memberIdList") Set<Long> memberIdList, |
| | | @RequestHeader(SecurityConstants.FROM_SOURCE) String source); |
| | | |
| | | @PostMapping("/member/miniLogin") |
| | | public R<AppMiniLoginVO> miniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto); |
| | | |
| | | @PostMapping("/forepart/auction-salesroom/actionMiniLogin") |
| | | public R<AppMiniLoginVO> actionMiniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto); |
| | | |
| | | |
| | | @PostMapping("/member/miniRegister") |
| | | public R<AppMiniLoginVO> miniRegister(@RequestBody AppMiniRegisterDTO appUserRegisterDto); |
| | | } |
| | |
| | | import com.ruoyi.common.security.auth.AuthUtil; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.SysRole; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import io.swagger.annotations.Api; |
| | |
| | | private SysUserClient userClient; |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | |
| | | |
| | | @ApiOperation("小程序登录") |
| | | @PostMapping("miniLogin") |
| | | public R<?> miniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | // 小程序用户登录 |
| | | AppMiniLoginVO appMiniLoginVo = sysLoginService.miniLogin(appMiniLoginDto); |
| | | // 获取登录token |
| | | return R.ok(tokenService.createMiniToken(appMiniLoginVo)); |
| | | } |
| | | |
| | | @ApiOperation("小程序注册") |
| | | @PostMapping("miniRegister") |
| | | public R<?> miniRegister(@RequestBody AppMiniRegisterDTO appUserRegisterDto) |
| | | { |
| | | // 小程序用户登录 |
| | | AppMiniLoginVO appMiniLoginVo = sysLoginService.miniRegister(appUserRegisterDto); |
| | | // 获取登录token |
| | | return R.ok(tokenService.createMiniToken(appMiniLoginVo)); |
| | | } |
| | | |
| | | |
| | | @ApiOperation("拍卖师小程序登录") |
| | | @PostMapping("actionMiniLogin") |
| | | public R<?> actionMiniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | // 小程序用户登录 |
| | | AppMiniLoginVO appMiniLoginVo = sysLoginService.actionMiniLogin(appMiniLoginDto); |
| | | // 获取登录token |
| | | return R.ok(tokenService.createMiniToken(appMiniLoginVo)); |
| | | } |
| | | |
| | | |
| | | @PostMapping("login") |
| | | @ApiOperation(value = "管理后台-用户登录") |
| | | public R<?> login(@RequestBody LoginBody form) |
| | |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.RemoteUserService; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import com.ruoyi.system.api.feignClient.MemberClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * 登录校验方法 |
| | |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private MemberClient MemberClient; |
| | | |
| | | /** |
| | | * 登录 |
| | |
| | | return userInfo; |
| | | } |
| | | |
| | | |
| | | public AppMiniLoginVO miniLogin(AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | // 查询用户信息 |
| | | R<AppMiniLoginVO> userResult = MemberClient.miniLogin(appMiniLoginDto); |
| | | if (R.FAIL == userResult.getCode()) |
| | | { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | AppMiniLoginVO userInfo = userResult.getData(); |
| | | SysUser user = userInfo.getSysUser(); |
| | | if(user!=null){ |
| | | String username = user.getUserName(); |
| | | // IP黑名单校验 |
| | | String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); |
| | | if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); |
| | | throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); |
| | | } |
| | | if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); |
| | | throw new ServiceException(username,501); |
| | | } |
| | | if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); |
| | | throw new ServiceException(username,501); |
| | | } |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); |
| | | } |
| | | return userInfo; |
| | | } |
| | | |
| | | public AppMiniLoginVO miniRegister(AppMiniRegisterDTO appUserRegisterDto) |
| | | { |
| | | // 查询用户信息 |
| | | R<AppMiniLoginVO> userResult = MemberClient.miniRegister(appUserRegisterDto); |
| | | if (R.FAIL == userResult.getCode()) |
| | | { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | AppMiniLoginVO appMiniRegisterVo = userResult.getData(); |
| | | SysUser user=appMiniRegisterVo.getSysUser(); |
| | | if(appMiniRegisterVo.getSysUser()!=null){ |
| | | String username = user.getUserName(); |
| | | // IP黑名单校验 |
| | | String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); |
| | | if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); |
| | | throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); |
| | | } |
| | | if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); |
| | | throw new ServiceException("对不起,您的账号: 已被删除"); |
| | | } |
| | | if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); |
| | | throw new ServiceException("对不起,您的账号: 已停用"); |
| | | } |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); |
| | | } |
| | | return appMiniRegisterVo; |
| | | } |
| | | |
| | | public AppMiniLoginVO actionMiniLogin(AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | // 查询用户信息 |
| | | R<AppMiniLoginVO> userResult = MemberClient.actionMiniLogin(appMiniLoginDto); |
| | | if (R.FAIL == userResult.getCode()) |
| | | { |
| | | throw new ServiceException(userResult.getMsg()); |
| | | } |
| | | AppMiniLoginVO userInfo = userResult.getData(); |
| | | SysUser user = userInfo.getSysUser(); |
| | | if(user!=null){ |
| | | String username = user.getUserName(); |
| | | // IP黑名单校验 |
| | | String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST)); |
| | | if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单"); |
| | | throw new ServiceException("很遗憾,访问IP已被列入系统黑名单"); |
| | | } |
| | | if (UserStatus.DELETED.getCode().equals(user.getDelFlag())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "对不起,您的账号已被删除"); |
| | | throw new ServiceException(username,501); |
| | | } |
| | | if (UserStatus.DISABLE.getCode().equals(user.getStatus())) |
| | | { |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户已停用,请联系管理员"); |
| | | throw new ServiceException(username,501); |
| | | } |
| | | recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功"); |
| | | } |
| | | return userInfo; |
| | | } |
| | | |
| | | |
| | | public void logout(String loginName) |
| | | { |
| | | recordLogService.recordLogininfor(loginName, Constants.LOGOUT, "退出成功"); |
| | |
| | | public static final String DATE_FORMATTER_TIME = "yyyy-MM-dd HH:mm:ss"; |
| | | public static final String DATE_FORMATTER_DATE = "yyyy-MM-dd"; |
| | | |
| | | |
| | | |
| | | /** |
| | | * 定时任务违规的字符 |
| | | */ |
| | | public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml", |
| | | "org.springframework", "org.apache", "com.ruoyi.common.core.utils.file" }; |
| | | |
| | | |
| | | public static final Integer FROM_SYSTEM = 0; |
| | | |
| | | public static final Integer FROM_SHOP = 1; |
| | | |
| | | public static final Integer FROM_STAFF = 2; |
| | | |
| | | public static final Integer FROM_MINI_APP = 3; |
| | | } |
| | |
| | | public static final String DETAILS_USER_ID = "user_id"; |
| | | |
| | | /** |
| | | * 登录端 |
| | | */ |
| | | public static final String LOGIN_FROM = "login_from"; |
| | | |
| | | /** |
| | | * 用户名字段 |
| | | */ |
| | | public static final String DETAILS_USERNAME = "username"; |
| | |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | |
| | | |
| | | protected static final long MILLIS_MINUTE = 60 * MILLIS_SECOND; |
| | | |
| | | private final static long expireTime = CacheConstants.EXPIRATION; |
| | | |
| | | private final static long EXPIRE_TIME = CacheConstants.EXPIRATION; |
| | | |
| | | private final static String ACCESS_TOKEN = CacheConstants.LOGIN_TOKEN_KEY; |
| | | |
| | |
| | | // 接口返回信息 |
| | | Map<String, Object> rspMap = new HashMap<String, Object>(); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| | | rspMap.put("expires_in", expireTime); |
| | | rspMap.put("expires_in", EXPIRE_TIME); |
| | | return rspMap; |
| | | } |
| | | |
| | | public Map<String, Object> createMiniToken(AppMiniLoginVO appMiniLoginVo) |
| | | { |
| | | LoginUser loginUser = new LoginUser(); |
| | | // Jwt存储信息 |
| | | Map<String, Object> claimsMap = new HashMap<String, Object>(); |
| | | // 接口返回信息 |
| | | Map<String, Object> rspMap = new HashMap<String, Object>(); |
| | | //用户为空只返回openid |
| | | rspMap.put("mobile",""); |
| | | rspMap.put("access_token", ""); |
| | | if(appMiniLoginVo.getSysUser()!=null){ |
| | | loginUser.setSysUser(appMiniLoginVo.getSysUser()); |
| | | String token = IdUtils.fastUUID(); |
| | | Long userId = loginUser.getSysUser().getUserId(); |
| | | String userName = loginUser.getSysUser().getUserName(); |
| | | loginUser.setToken(token); |
| | | loginUser.setUserid(userId); |
| | | loginUser.setUsername(userName); |
| | | loginUser.setIpaddr(IpUtils.getIpAddr()); |
| | | refreshToken(loginUser); |
| | | claimsMap.put(SecurityConstants.USER_KEY, token); |
| | | claimsMap.put(SecurityConstants.DETAILS_USER_ID, userId); |
| | | claimsMap.put(SecurityConstants.DETAILS_USERNAME, userName); |
| | | claimsMap.put(SecurityConstants.LOGIN_FROM, Constants.FROM_MINI_APP); |
| | | rspMap.put("access_token", JwtUtils.createToken(claimsMap)); |
| | | rspMap.put("expires_in", EXPIRE_TIME); |
| | | } |
| | | rspMap.put("wx_unionid", appMiniLoginVo.getWxUnionid()); |
| | | rspMap.put("mini_openid", appMiniLoginVo.getMiniOpenid()); |
| | | rspMap.put("zfb_userid", appMiniLoginVo.getZfbuserid()); |
| | | rspMap.put("phone",appMiniLoginVo.getPhone()); |
| | | return rspMap; |
| | | } |
| | | |
| | |
| | | public void refreshToken(LoginUser loginUser) |
| | | { |
| | | loginUser.setLoginTime(System.currentTimeMillis()); |
| | | loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE); |
| | | loginUser.setExpireTime(loginUser.getLoginTime() + EXPIRE_TIME * MILLIS_MINUTE); |
| | | // 根据uuid将loginUser缓存 |
| | | String userKey = getTokenKey(loginUser.getToken()); |
| | | redisService.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES); |
| | | redisService.setCacheObject(userKey, loginUser, EXPIRE_TIME, TimeUnit.MINUTES); |
| | | } |
| | | |
| | | private String getTokenKey(String token) |
| | |
| | | import com.ruoyi.common.core.domain.R; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | @PostMapping("/saveMemberArticleComments") |
| | | @ResponseBody |
| | | @ApiOperation(value = "添加或者修改用户评论/回复") |
| | | public R<T> saveMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) { |
| | | public R<T> saveMemberArticleComments(@RequestBody ArticleCommentsDTO articleCommentsDTO) { |
| | | articleCommentsService.saveMemberArticleComments(articleCommentsDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/delMemberArticleComments") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除用户评论/回复") |
| | | public R<T> delMemberArticleComments(ArticleCommentsDTO articleCommentsDTO) { |
| | | public R<T> delMemberArticleComments(@RequestBody ArticleCommentsDTO articleCommentsDTO) { |
| | | articleCommentsService.delMemberArticleComments(articleCommentsDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | @PostMapping("/getArticleList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取资讯") |
| | | public R<PageDTO<ArticleVO>> getArticleList(ArticleDTO articleDTO) { |
| | | public R<PageDTO<ArticleVO>> getArticleList( @RequestBody ArticleDTO articleDTO) { |
| | | return R.ok(iArticleService.getArticleList(articleDTO)); |
| | | } |
| | | |
| | | @PostMapping("/getMemberArticleList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户资讯") |
| | | public R<PageDTO<Article>> getMemberArticleList(ArticleDTO articleDTO) { |
| | | public R<PageDTO<Article>> getMemberArticleList(@RequestBody ArticleDTO articleDTO) { |
| | | return R.ok(iArticleService.getMemberArticleList(articleDTO)); |
| | | } |
| | | |
| | | @PostMapping("/saveMemberArticle") |
| | | @ResponseBody |
| | | @ApiOperation(value = "添加或者修改用户资讯") |
| | | public R<T> saveMemberArticle(ArticleDTO articleDTO) { |
| | | public R<T> saveMemberArticle(@RequestBody ArticleDTO articleDTO) { |
| | | iArticleService.saveMemberArticle(articleDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/delMemberArticle") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除用户资讯") |
| | | public R<T> delMemberArticle(ArticleDTO articleDTO) { |
| | | public R<T> delMemberArticle(@RequestBody ArticleDTO articleDTO) { |
| | | iArticleService.delMemberArticle(articleDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | @PostMapping("/saveMemberArticleCollection") |
| | | @ResponseBody |
| | | @ApiOperation(value = "文章收藏和取消收藏") |
| | | public R<T> saveMemberArticleCollection(MemberArticleCollectionDTO memberArticleCollectionDTO) { |
| | | public R<T> saveMemberArticleCollection( @RequestBody MemberArticleCollectionDTO memberArticleCollectionDTO) { |
| | | memberArticleCollectionService.saveMemberArticleCollection(memberArticleCollectionDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | package com.ruoyi.article.controller; |
| | | |
| | | |
| | | import com.ruoyi.article.dto.ArticleCommentsDTO; |
| | | import com.ruoyi.article.dto.MemberLikeDTO; |
| | | import com.ruoyi.article.service.IMemberLikeService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | |
| | | @PostMapping("/saveMemberLike") |
| | | @ResponseBody |
| | | @ApiOperation(value = "文章,评论和回复 点赞和取消点赞") |
| | | public R<T> saveMemberLike(MemberLikeDTO memberLikeDTO) { |
| | | public R<T> saveMemberLike(@RequestBody MemberLikeDTO memberLikeDTO) { |
| | | memberLikeService.saveMemberLike(memberLikeDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | <artifactId>spring-boot-starter-actuator</artifactId> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.github.binarywang</groupId> |
| | | <artifactId>weixin-java-miniapp</artifactId> |
| | | <version>4.5.0</version> |
| | | </dependency> |
| | | |
| | | |
| | | |
| | | <!-- Swagger UI --> |
| | | <dependency> |
| | | <groupId>io.springfox</groupId> |
| | |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-common-seata</artifactId> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.ruoyi</groupId> |
| | | <artifactId>ruoyi-modules-member</artifactId> |
| | | <version>3.6.2</version> |
| | | <scope>compile</scope> |
| | | </dependency> |
| | | </dependencies> |
| | | |
| | | <build> |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | @RequestMapping("/getAuctionBidRecordList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖大屏滚动出价") |
| | | public R<List<AuctionBidRecord>> getAuctionBidRecordList(AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | public R<List<AuctionBidRecord>> getAuctionBidRecordList(@RequestBody AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | return R.ok(iAuctionBidRecordService.getAuctionBidRecordList(auctionSalesroomGoodsDTO)); |
| | | |
| | | } |
| | |
| | | import com.ruoyi.auction.service.IAuctionSalesroomService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import javax.annotation.Resource; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | |
| | | @RequestMapping("getAuctionBidRecordList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖大屏获取拍卖信息") |
| | | public R<PageDTO<AuctionSalesroom>> getAuctionBidRecordList(AuctionSalesroomGoodsDTO ctionSalesroomGoodsDTO) { |
| | | public R<PageDTO<AuctionSalesroom>> getAuctionBidRecordList(@RequestBody AuctionSalesroomGoodsDTO ctionSalesroomGoodsDTO) { |
| | | return R.ok(iAuctionSalesroomService.getAuctionBidRecordList(ctionSalesroomGoodsDTO)); |
| | | |
| | | } |
| | |
| | | @RequestMapping("/getBaaner") |
| | | @ResponseBody |
| | | @ApiOperation(value = " 暖场视频or封面海报") |
| | | public R<ForepartAuctionSalesroomVO> getBaaner(AuctionSalesroomGoodsDTO ctionSalesroomGoodsDTO) { |
| | | public R<ForepartAuctionSalesroomVO> getBaaner(@RequestBody AuctionSalesroomGoodsDTO ctionSalesroomGoodsDTO) { |
| | | |
| | | return R.ok(iAuctionSalesroomService.getBaaner(ctionSalesroomGoodsDTO)); |
| | | } |
| | |
| | | return R.ok(iAuctionSalesroomService.getAuctionBidRecordOne(arepartAuctionBidRecordDTO)); |
| | | } |
| | | |
| | | @RequestMapping("/actionMiniLogin") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师第三方登陸") |
| | | public R<AppMiniLoginVO> actionMiniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto) { |
| | | return R.ok(iAuctionSalesroomService.actionMiniLogin(appMiniLoginDto)); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | @RequestMapping("/getAuctionSalesroomGoods") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖大屏的商品介绍") |
| | | public R<ForepartAuctionSalesroomGoodsVO> getAuctionSalesroomGoods(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | public R<ForepartAuctionSalesroomGoodsVO> getAuctionSalesroomGoods(@RequestBody AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | |
| | | return R.ok(iAuctionSalesroomGoodsService.getAuctionSalesroomGoods(ationSalesroomGoodsDTO)); |
| | | } |
| | |
| | | @RequestMapping("/getAuctionSalesroominfo") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师端拍卖场信息") |
| | | public R<AuctionSalesroomVO> getAuctionSalesroominfo(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | public R<AuctionSalesroomVO> getAuctionSalesroominfo(@RequestBody AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | return R.ok(iAuctionSalesroomGoodsService.getAuctionSalesroominfo(ationSalesroomGoodsDTO)); |
| | | } |
| | | |
| | |
| | | @RequestMapping("/auctionSalesroomStart") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师端拍卖场立即开始") |
| | | public R<T> auctionSalesroomStart(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | public R<T> auctionSalesroomStart(@RequestBody AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | iAuctionSalesroomGoodsService.auctionSalesroomStart(ationSalesroomGoodsDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping("/auctionSalesroomEnd") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师端拍卖场立即结束") |
| | | public R<T> auctionSalesroomEnd(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | public R<T> auctionSalesroomEnd(@RequestBody AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | iAuctionSalesroomGoodsService.auctionSalesroomEnd(ationSalesroomGoodsDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping("/isAuctionSalesroom") |
| | | @ResponseBody |
| | | @ApiOperation(value = "判断拍卖师端是否还有未拍卖商品") |
| | | public R<List<AuctionSalesroomGoods>> isAuctionSalesroom(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | public R<List<AuctionSalesroomGoods>> isAuctionSalesroom(@RequestBody AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | | |
| | | return R.ok(iAuctionSalesroomGoodsService.isAuctionSalesroom(ationSalesroomGoodsDTO)); |
| | | } |
| | |
| | | @RequestMapping("/auctionSalesroomGoodsStart") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师端拍卖场下一个立即开始") |
| | | public R<T> auctionSalesroomGoodsStart(AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | public R<T> auctionSalesroomGoodsStart(@RequestBody AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | iAuctionSalesroomGoodsService.auctionSalesroomGoodsStart(auctionSalesroomGoodsDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping("/auctionSalesroomGoodsEnd") |
| | | @ResponseBody |
| | | @ApiOperation(value = "拍卖师端拍卖商品立即结束") |
| | | public R<T> auctionSalesroomGoodsEnd(AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | public R<T> auctionSalesroomGoodsEnd(@RequestBody AuctionSalesroomGoodsDTO auctionSalesroomGoodsDTO) { |
| | | iAuctionSalesroomGoodsService.auctionSalesroomGoodsStart(auctionSalesroomGoodsDTO); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | import com.ruoyi.auction.controller.forepart.vo.ForepartAuctionSalesroomVO; |
| | | import com.ruoyi.auction.domain.AuctionSalesroom; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | |
| | | AuctionSalesroom getAuctionBidRecordOne(ForepartAuctionBidRecordDTO arepartAuctionBidRecordDTO); |
| | | |
| | | AppMiniLoginVO actionMiniLogin(@RequestBody AppMiniLoginDTO appMiniLoginDto); |
| | | } |
| | |
| | | package com.ruoyi.auction.service.impl; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
| | | import com.alipay.api.request.AlipayUserInfoShareRequest; |
| | | import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
| | | import com.alipay.api.response.AlipayUserInfoShareResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | |
| | | import com.ruoyi.auction.service.IAuctionVideoService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.page.PageDTO; |
| | | import com.ruoyi.auction.util.HttpUtils; |
| | | import com.ruoyi.system.api.constants.SecurityConstant; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static com.ruoyi.member.service.impl.MemberServiceImpl.getAccessTokenByWX; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | @Resource |
| | | private WxMaService wxMaService; |
| | | |
| | | |
| | | //微信 |
| | | private static final String ACCESS_TOKEN_HOST = "https://api.weixin.qq.com/cgi-bin/token"; |
| | | |
| | | private static final String WX_APPID = "wxb7f0ea286fc4e535"; |
| | | |
| | | private static final String WX_SECRET = "852a2512a6ab559cafc68bae5d4160ac"; |
| | | |
| | | |
| | | //支付寶 |
| | | /** |
| | | * Alipay客户端 |
| | | */ |
| | | private AlipayClient alipayClient; |
| | | |
| | | /**支付宝网关*/ |
| | | /** |
| | | * 沙箱的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_DEV = "https://openapi-sandbox.dl.alipaydev.com/gateway.do"; |
| | | /** |
| | | * 个人用户的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_PROD = "https://openapi.alipay.com/gateway.do"; |
| | | /** |
| | | * appID |
| | | **/ |
| | | private static final String APP_ID_PROD = "2021003196653501"; |
| | | /** |
| | | * 私钥 |
| | | */ |
| | | private static final String APP_PRIVATE_KEY = ""; |
| | | /** |
| | | * 支付宝公钥 |
| | | */ |
| | | private static final String ALIPAY_PUBLIC_KEY = ""; |
| | | |
| | | @Override |
| | | public PageDTO<AuctionSalesroom> getAuctionBidRecordList(AuctionSalesroomGoodsDTO ationSalesroomGoodsDTO) { |
| | |
| | | AuctionSalesroom auctionBidRecord=iAuctionSalesroomService.getOne(wrapper); |
| | | return auctionBidRecord; |
| | | } |
| | | |
| | | @Override |
| | | public AppMiniLoginVO actionMiniLogin(AppMiniLoginDTO appMiniLoginDto) { |
| | | try { |
| | | AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); |
| | | if (appMiniLoginDto.getType()==1){ |
| | | if (appMiniLoginDto.getAuth_code()== null || appMiniLoginDto.getAuth_code().length() == 0) { |
| | | } else { |
| | | AppMiniLoginVO user=new AppMiniLoginVO(); |
| | | //String serverUrl, String appId, String privateKey, String format,String charset, String alipayPublicKey, String signType |
| | | //实例化客户端 参数:正式环境URL,Appid,商户私钥 PKCS8格式,字符编码格式,字符格式,支付宝公钥,签名方式 |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | | AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); |
| | | // 值为authorization_code时,代表用code换取 |
| | | request.setGrantType("authorization_code"); |
| | | //授权码,用户对应用授权后得到的 |
| | | request.setCode(appMiniLoginDto.getAuth_code()); |
| | | //这里使用execute方法 |
| | | AlipaySystemOauthTokenResponse response = null; |
| | | try { |
| | | response = alipayClient.execute(request); |
| | | } catch (AlipayApiException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //刷新令牌,上次换取访问令牌时得到。见出参的refresh_token字段 |
| | | request.setRefreshToken(response.getAccessToken()); |
| | | |
| | | //返回成功时 就将唯一标识返回 |
| | | if (response.isSuccess()) { |
| | | System.out.println("调用成功"); |
| | | //我这里只返回了一个字段给前端用 |
| | | String user1= response.getUserId(); |
| | | appMiniLoginVo.setZfbuserid(response.getUserId()); |
| | | AlipayUserInfoShareResponse alipayUserInfoShareResponse=getAliUserInfo(response.getAccessToken()); |
| | | appMiniLoginVo.setPhone(alipayUserInfoShareResponse.getPhone()); |
| | | R<SysUser> sysUserR = sysUserClient.queryUserByPhone(alipayUserInfoShareResponse.getPhone()); |
| | | SysUser data = sysUserR.getData(); |
| | | appMiniLoginVo.setSysUser(data); |
| | | } |
| | | } |
| | | }else{ |
| | | WxMaJscode2SessionResult session = null; |
| | | String unionid; |
| | | String openid; |
| | | String sessionKey = null; |
| | | //获取session |
| | | session = wxMaService.getUserService().getSessionInfo(appMiniLoginDto.getCode()); |
| | | if (session != null && StringUtils.isNotBlank(session.getOpenid())) { |
| | | unionid = session.getUnionid(); |
| | | openid = session.getOpenid(); |
| | | sessionKey = session.getSessionKey(); |
| | | |
| | | |
| | | String responseAccessToken = getAccessTokenByWX(); |
| | | |
| | | JSONObject jsonAccessToken = JSONObject.parseObject(responseAccessToken); |
| | | String accessToken = jsonAccessToken.getString("access_token"); |
| | | String errmsg = jsonAccessToken.getString("errmsg"); |
| | | Long expiresIn = jsonAccessToken.getLong("expires_in"); |
| | | if (StringUtils.isBlank(accessToken)) { |
| | | throw new ServiceException(errmsg); |
| | | } |
| | | String responseUserPhoneNumber = getMobileByWX(accessToken, appMiniLoginDto.getCode()); |
| | | JSONObject jsonUserPhoneNumber = JSONObject.parseObject(responseUserPhoneNumber); |
| | | |
| | | |
| | | String phoneInfo = jsonUserPhoneNumber.getString("phone_info"); |
| | | JSONObject jsonUserPhoneInfo = JSONObject.parseObject(phoneInfo); |
| | | String mobile = jsonUserPhoneInfo.getString("purePhoneNumber"); |
| | | //获取用户 |
| | | R<SysUser> sysUserR = sysUserClient.queryUserByPhone(mobile); |
| | | SysUser data = sysUserR.getData(); |
| | | appMiniLoginVo.setSysUser(data); |
| | | |
| | | appMiniLoginVo.setMiniOpenid(openid); |
| | | appMiniLoginVo.setWxUnionid(unionid); |
| | | appMiniLoginVo.setPhone(mobile); |
| | | appMiniLoginVo.setSessionKey(sessionKey); |
| | | } |
| | | } |
| | | return appMiniLoginVo; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | private AlipayUserInfoShareResponse getAliUserInfo (String accessToken) throws Exception { |
| | | |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | | AlipayUserInfoShareRequest request = new AlipayUserInfoShareRequest(); |
| | | AlipayUserInfoShareResponse response = alipayClient.execute(request, accessToken); |
| | | if(response.isSuccess()){ |
| | | System.out.println("获取会员信息 - 调用成功"); |
| | | return response; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static String getAccessTokenByWX() throws Exception { |
| | | String host = ACCESS_TOKEN_HOST + "?appid=" + WX_APPID + "&secret=" + WX_SECRET + "&grant_type=client_credential"; |
| | | Map<String, String> headers = new HashMap<>(8); |
| | | HttpResponse response = HttpUtils.doGet(host, "", "GET", headers, null); |
| | | return EntityUtils.toString(response.getEntity()); |
| | | } |
| | | |
| | | public static String getMobileByWX(String accessToken, String code) throws Exception { |
| | | Map<String, String> headers = new HashMap<>(16); |
| | | headers.put("Content-Type", "application/json"); |
| | | headers.put("Accept", "application/json"); |
| | | Map<String, String> querys = new HashMap<>(16); |
| | | Map<String, String> bodys = new HashMap<>(16); |
| | | querys.put("access_token", accessToken); |
| | | bodys.put("code", code); |
| | | String body = JSONObject.toJSONString(bodys); |
| | | String host = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"; |
| | | HttpResponse response = HttpUtils.doPost(host, "", "POST", headers, querys, body); |
| | | return EntityUtils.toString(response.getEntity()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.ruoyi.auction.util; |
| | | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.HttpDelete; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.client.methods.HttpPut; |
| | | import org.apache.http.conn.ClientConnectionManager; |
| | | import org.apache.http.conn.scheme.Scheme; |
| | | import org.apache.http.conn.scheme.SchemeRegistry; |
| | | import org.apache.http.conn.ssl.SSLSocketFactory; |
| | | import org.apache.http.entity.ByteArrayEntity; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.security.KeyManagementException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.cert.X509Certificate; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @ClassName HttpUtils |
| | | * @Description TODO |
| | | * @Author zhanglin |
| | | * @Date 2020/2/11 10:30 |
| | | * @Version 1.0 |
| | | **/ |
| | | public class HttpUtils { |
| | | |
| | | public static void main(String[] args) { |
| | | } |
| | | |
| | | |
| | | /** |
| | | * get |
| | | * |
| | | * @param host |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doGet(String host)throws Exception { |
| | | return doGet(host, "", "GET", null, null); |
| | | } |
| | | |
| | | /** |
| | | * get |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpGet request = new HttpGet(buildUrl(host, path, querys)); |
| | | if(null != headers) { |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * post form |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param bodys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | Map<String, String> bodys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (bodys != null) { |
| | | List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); |
| | | |
| | | for (String key : bodys.keySet()) { |
| | | nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); |
| | | } |
| | | UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); |
| | | formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); |
| | | request.setEntity(formEntity); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Post String |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | String body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(body)) { |
| | | request.setEntity(new StringEntity(body, "utf-8")); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Post stream |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | byte[] body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (body != null) { |
| | | request.setEntity(new ByteArrayEntity(body)); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Put String |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPut(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | String body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPut request = new HttpPut(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(body)) { |
| | | request.setEntity(new StringEntity(body, "utf-8")); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Put stream |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPut(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | byte[] body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPut request = new HttpPut(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (body != null) { |
| | | request.setEntity(new ByteArrayEntity(body)); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Delete |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doDelete(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException { |
| | | StringBuilder sbUrl = new StringBuilder(); |
| | | sbUrl.append(host); |
| | | if (!StringUtils.isBlank(path)) { |
| | | sbUrl.append(path); |
| | | } |
| | | if (null != querys) { |
| | | StringBuilder sbQuery = new StringBuilder(); |
| | | for (Map.Entry<String, String> query : querys.entrySet()) { |
| | | if (0 < sbQuery.length()) { |
| | | sbQuery.append("&"); |
| | | } |
| | | if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { |
| | | sbQuery.append(query.getValue()); |
| | | } |
| | | if (!StringUtils.isBlank(query.getKey())) { |
| | | sbQuery.append(query.getKey()); |
| | | if (!StringUtils.isBlank(query.getValue())) { |
| | | sbQuery.append("="); |
| | | sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); |
| | | } |
| | | } |
| | | } |
| | | if (0 < sbQuery.length()) { |
| | | sbUrl.append("?").append(sbQuery); |
| | | } |
| | | } |
| | | |
| | | return sbUrl.toString(); |
| | | } |
| | | |
| | | private static HttpClient wrapClient(String host) { |
| | | HttpClient httpClient = new DefaultHttpClient(); |
| | | if (host.startsWith("https://")) { |
| | | sslClient(httpClient); |
| | | } |
| | | |
| | | return httpClient; |
| | | } |
| | | |
| | | private static void sslClient(HttpClient httpClient) { |
| | | try { |
| | | SSLContext ctx = SSLContext.getInstance("TLS"); |
| | | X509TrustManager tm = new X509TrustManager() { |
| | | @Override |
| | | public X509Certificate[] getAcceptedIssuers() { |
| | | return null; |
| | | } |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] xcs, String str) { |
| | | |
| | | } |
| | | @Override |
| | | public void checkServerTrusted(X509Certificate[] xcs, String str) { |
| | | |
| | | } |
| | | }; |
| | | ctx.init(null, new TrustManager[] { tm }, null); |
| | | SSLSocketFactory ssf = new SSLSocketFactory(ctx); |
| | | ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); |
| | | ClientConnectionManager ccm = httpClient.getConnectionManager(); |
| | | SchemeRegistry registry = ccm.getSchemeRegistry(); |
| | | registry.register(new Scheme("https", 443, ssf)); |
| | | } catch (KeyManagementException ex) { |
| | | throw new RuntimeException(ex); |
| | | } catch (NoSuchAlgorithmException ex) { |
| | | throw new RuntimeException(ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.github.binarywang</groupId> |
| | | <artifactId>weixin-java-miniapp</artifactId> |
| | | <version>4.5.0</version> |
| | | </dependency> |
| | | |
| | | <dependency> |
| | | <groupId>com.alipay.sdk</groupId> |
| | | <artifactId>alipay-sdk-java</artifactId> |
| | | <version>3.4.27.ALL</version> |
| | |
| | | import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
| | | import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.member.VO.AlipayUser; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | |
| | | |
| | | @RequestMapping("/getalipayInfo") |
| | | @ApiOperation(value = "获取支付宝授权码") |
| | | public R<AlipayUser> getInfo(String auth_code) throws AlipayApiException { |
| | | public R<AppMiniLoginVO> getInfo(AppMiniLoginDTO appMiniLoginDto) { |
| | | //使用支付宝小程序的固定方法获取auth_code |
| | | if (auth_code == null || auth_code.length() == 0) { |
| | | if (appMiniLoginDto.getAuth_code()== null || appMiniLoginDto.getAuth_code().length() == 0) { |
| | | return R.fail("请求参数auth_code不能为空"); |
| | | } else { |
| | | AppMiniLoginVO user=new AppMiniLoginVO(); |
| | | //String serverUrl, String appId, String privateKey, String format,String charset, String alipayPublicKey, String signType |
| | | //实例化客户端 参数:正式环境URL,Appid,商户私钥 PKCS8格式,字符编码格式,字符格式,支付宝公钥,签名方式 |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | |
| | | // 值为authorization_code时,代表用code换取 |
| | | request.setGrantType("authorization_code"); |
| | | //授权码,用户对应用授权后得到的 |
| | | request.setCode(auth_code); |
| | | request.setCode(appMiniLoginDto.getAuth_code()); |
| | | //这里使用execute方法 |
| | | AlipaySystemOauthTokenResponse response = alipayClient.execute(request); |
| | | AlipaySystemOauthTokenResponse response = null; |
| | | try { |
| | | response = alipayClient.execute(request); |
| | | } catch (AlipayApiException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //刷新令牌,上次换取访问令牌时得到。见出参的refresh_token字段 |
| | | request.setRefreshToken(response.getAccessToken()); |
| | | //返回成功时 就将唯一标识返回 |
| | | if (response.isSuccess()) { |
| | | System.out.println("调用成功"); |
| | | //我这里只返回了一个字段给前端用 |
| | | AlipayUser user=new AlipayUser(); |
| | | user.setUserid(response.getUserId()); |
| | | String user1= response.getUserId(); |
| | | user.setZfbuserid(user1); |
| | | return R.ok(user); |
| | | } else { |
| | | return R.fail("调用失败"); |
| | |
| | | @PostMapping("/getMemberAddressList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户地址") |
| | | public R<PageDTO<MemberAddress>> getMemberAddressList(MemberAddressDTO memberAddressDTO) { |
| | | public R<PageDTO<MemberAddress>> getMemberAddressList(@RequestBody MemberAddressDTO memberAddressDTO) { |
| | | return R.ok(iMemberAddressService.getMemberAddressList(memberAddressDTO)); |
| | | } |
| | | |
| | | @PostMapping("/addMemberAddress") |
| | | @ResponseBody |
| | | @ApiOperation(value = "用户添加或者修改地址") |
| | | public R<T> addMemberAddress(MemberAddressDTO memberAddressDTO) { |
| | | public R<T> addMemberAddress(@RequestBody MemberAddressDTO memberAddressDTO) { |
| | | iMemberAddressService.addMemberAddress(memberAddressDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/delMemberAddress") |
| | | @ResponseBody |
| | | @ApiOperation(value = "用户删除地址") |
| | | public R<T> delMemberAddress(MemberAddressDTO memberAddressDTO) { |
| | | public R<T> delMemberAddress(@RequestBody MemberAddressDTO memberAddressDTO) { |
| | | iMemberAddressService.delMemberAddress(memberAddressDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | import com.ruoyi.common.security.annotation.InnerAuth; |
| | | import com.ruoyi.member.dto.MemberDTO; |
| | | import com.ruoyi.member.service.IMemberService; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | import org.springframework.web.multipart.MultipartHttpServletRequest; |
| | | import util.HuaWeiOBSUtil; |
| | |
| | | } |
| | | |
| | | |
| | | @RequestMapping("/loginThird") |
| | | @RequestMapping("/miniLogin") |
| | | @ResponseBody |
| | | @ApiOperation(value = "第三方登陸和註冊") |
| | | public R<Member> loginThird(MemberDTO memberDTO) { |
| | | return R.ok(iMemberService.loginThird(memberDTO)); |
| | | @ApiOperation(value = "第三方登陸") |
| | | public R<AppMiniLoginVO> loginThird(@RequestBody AppMiniLoginDTO appMiniLoginDto) { |
| | | return R.ok(iMemberService.loginThird(appMiniLoginDto)); |
| | | } |
| | | |
| | | @PostMapping(value = "/miniRegister") |
| | | @ApiOperation(value = "小程序注册") |
| | | public R<AppMiniLoginVO> miniRegister(@RequestBody AppMiniRegisterDTO appMiniRegisterDTO) { |
| | | AppMiniLoginVO appUserRegisterVo = iMemberService.miniRegister(appMiniRegisterDTO); |
| | | if(appUserRegisterVo ==null){ |
| | | return R.fail("注册失败!"); |
| | | } |
| | | return R.ok(appUserRegisterVo); |
| | | } |
| | | |
| | | @RequestMapping("/getMembeid") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户信息") |
| | | public R<Member> getMembeid(MemberDTO memberDTO) { |
| | | public R<Member> getMembeid(@RequestBody MemberDTO memberDTO) { |
| | | return R.ok(iMemberService.getMembeid(memberDTO)); |
| | | } |
| | | |
| | |
| | | @RequestMapping("/updateMembeid") |
| | | @ResponseBody |
| | | @ApiOperation(value = "修改用户信息") |
| | | public R<T> updateMembeid(MemberDTO memberDTO) { |
| | | public R<T> updateMembeid(@RequestBody MemberDTO memberDTO) { |
| | | iMemberService.updateMembeid(memberDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping("/authentificationMembe") |
| | | @ResponseBody |
| | | @ApiOperation(value = "用户认证") |
| | | public R<T> authentificationMembe(MemberDTO memberDTO) { |
| | | public R<T> authentificationMembe(@RequestBody MemberDTO memberDTO) { |
| | | iMemberService.authentificationMembe(memberDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | import com.ruoyi.member.service.IMemberPointsService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import javax.annotation.Resource; |
| | | |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | |
| | | @RequestMapping("/getMemberPoints") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户积分") |
| | | public R<PageDTO<MemberPoints>> getMemberPoints(MemberDTO memberDTO) { |
| | | public R<PageDTO<MemberPoints>> getMemberPoints(@RequestBody MemberDTO memberDTO) { |
| | | return R.ok(iMemberPointsService.getMemberPoints(memberDTO)); |
| | | } |
| | | } |
| | |
| | | /* |
| | | package com.ruoyi.member.controller; |
| | | |
| | | import java.io.BufferedReader; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.Cipher; |
| | | import javax.crypto.spec.IvParameterSpec; |
| | | import javax.crypto.spec.SecretKeySpec; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.sign.Base64; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.member.util.*; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | |
| | | |
| | | import net.sf.json.JSON; |
| | | |
| | | import org.bouncycastle.jce.provider.BouncyCastleProvider; |
| | | |
| | | */ |
| | | /** |
| | | * 微信授权方面 |
| | | * |
| | | * @author tuzx |
| | | * @date 2018年8月9日 |
| | | * @version 1.0 |
| | | */ |
| | | *//* |
| | | |
| | | @Controller |
| | | @RequestMapping("/weixin") |
| | | public class WeiXinAppController { |
| | | |
| | | private static String appid = "wx0e4769839d84fde0"; |
| | | private static String appSecret = "ede69db0303ddde49b5db95f186918ec"; |
| | | |
| | | @Resource |
| | | private WxMaService wxMaService; |
| | | |
| | | @RequestMapping("/getAddress") |
| | | @ResponseBody |
| | |
| | | } |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getOpenId") |
| | | @ApiOperation(value = "获取微信的OpenId") |
| | | public R<Map<String, String>> getOpenId(String code) { |
| | | @PostMapping("/miniLogin") |
| | | @ApiOperation("小程序登录") |
| | | public R<AppMiniLoginVO> getMemberByCode(@RequestBody AppMiniLoginDTO appMiniLoginDto) |
| | | { |
| | | AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); |
| | | WxMaJscode2SessionResult session = null; |
| | | String unionid; |
| | | String openid; |
| | | String sessionKey = null; |
| | | //获取session |
| | | try { |
| | | String openID = JsapiTicketUtil.getOpenId(code); |
| | | Map<String,String> data=new HashMap<>(); |
| | | data.put("openID",openID); |
| | | return R.ok(data); |
| | | session = wxMaService.getUserService().getSessionInfo(appMiniLoginDto.getCode()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return null; |
| | | } |
| | | return R.fail("获取异常"); |
| | | if (session != null && StringUtils.isNotBlank(session.getOpenid())) { |
| | | unionid = session.getUnionid(); |
| | | openid = session.getOpenid(); |
| | | sessionKey = session.getSessionKey(); |
| | | |
| | | appMiniLoginVo.setMiniOpenid(openid); |
| | | appMiniLoginVo.setWxUnionid(unionid); |
| | | appMiniLoginVo.setSessionKey(sessionKey); |
| | | } |
| | | |
| | | if(appMiniLoginVo ==null){ |
| | | return R.fail("登录失败!"); |
| | | } |
| | | return R.ok(appMiniLoginVo); |
| | | } |
| | | |
| | | @ResponseBody |
| | |
| | | return R.fail("获取异常"); |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 获取微信用户信息 |
| | | * |
| | | * @param token |
| | | * @param openid |
| | | * @return |
| | | */ |
| | | *//* |
| | | |
| | | @ResponseBody |
| | | @RequestMapping("/getWXinfo") |
| | | @ApiOperation(value = "获取微信用户信息") |
| | |
| | | } |
| | | |
| | | |
| | | */ |
| | | /** |
| | | * 小程序使用jscode获取openid |
| | | * @param jscode |
| | | * @return |
| | | *//* |
| | | */ |
| | | /* |
| | | public String code2Session(String jscode){ |
| | | String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + appSecret |
| | | + "&js_code=" + jscode + "&grant_type=authorization_code"; |
| | |
| | | return jsonObject.getString("errmsg"); |
| | | } |
| | | return null; |
| | | }*/ |
| | | }*//* |
| | | |
| | | |
| | | */ |
| | | /*** |
| | | * 模拟get请求 |
| | | * |
| | |
| | | * @param charset |
| | | * @param timeout |
| | | * @return |
| | | */ |
| | | *//* |
| | | |
| | | public static String sendGet(String url, String charset, int timeout) { |
| | | String result = ""; |
| | | try { |
| | |
| | | return null; |
| | | } |
| | | } |
| | | */ |
| | |
| | | package com.ruoyi.member.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.member.dto.MemberDTO; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | |
| | |
| | | */ |
| | | public interface IMemberService extends IService<Member> { |
| | | |
| | | Member loginThird(MemberDTO memberDTO); |
| | | AppMiniLoginVO loginThird(AppMiniLoginDTO appMiniLoginDto); |
| | | |
| | | Member getMembeid(MemberDTO memberDTO); |
| | | |
| | |
| | | void authentificationMembe(MemberDTO memberDTO); |
| | | |
| | | List<Member> getMemberListByIds(Set<Long> memberIdList); |
| | | |
| | | AppMiniLoginVO miniRegister(@RequestBody AppMiniRegisterDTO appMiniRegisterDTO); |
| | | } |
| | |
| | | package com.ruoyi.member.service.impl; |
| | | |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.AlipayClient; |
| | | import com.alipay.api.DefaultAlipayClient; |
| | | import com.alipay.api.request.AlipaySystemOauthTokenRequest; |
| | | import com.alipay.api.response.AlipaySystemOauthTokenResponse; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.enums.GenderEnum; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.member.dto.MemberDTO; |
| | | import com.ruoyi.member.mapper.MemberMapper; |
| | | import com.ruoyi.member.service.IMemberService; |
| | | import com.ruoyi.member.util.HttpUtils; |
| | | import com.ruoyi.system.api.RemoteUserService; |
| | | import com.ruoyi.system.api.constants.SecurityConstant; |
| | | import com.ruoyi.system.api.domain.AppMiniLoginVO; |
| | | import com.ruoyi.system.api.domain.Member; |
| | | import java.io.IOException; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import javax.annotation.Resource; |
| | | |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniLoginDTO; |
| | | import com.ruoyi.system.api.domain.dto.AppMiniRegisterDTO; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.http.HttpEntity; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.client.config.RequestConfig; |
| | | import org.apache.http.client.methods.CloseableHttpResponse; |
| | | import org.apache.http.client.methods.HttpGet; |
| | |
| | | public static String query_url = "http://op.juhe.cn/idcard/query?key=" + APPKEY; |
| | | |
| | | |
| | | //微信 |
| | | private static final String ACCESS_TOKEN_HOST = "https://api.weixin.qq.com/cgi-bin/token"; |
| | | |
| | | private static final String WX_APPID = "wxb7f0ea286fc4e535"; |
| | | |
| | | private static final String WX_SECRET = "852a2512a6ab559cafc68bae5d4160ac"; |
| | | |
| | | //支付寶 |
| | | /** |
| | | * Alipay客户端 |
| | | */ |
| | | private AlipayClient alipayClient; |
| | | |
| | | /**支付宝网关*/ |
| | | /** |
| | | * 沙箱的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_DEV = "https://openapi-sandbox.dl.alipaydev.com/gateway.do"; |
| | | /** |
| | | * 个人用户的 |
| | | */ |
| | | private static final String ALIPAY_BORDER_PROD = "https://openapi.alipay.com/gateway.do"; |
| | | /** |
| | | * appID |
| | | **/ |
| | | private static final String APP_ID_PROD = "2021003196653501"; |
| | | /** |
| | | * 私钥 |
| | | */ |
| | | private static final String APP_PRIVATE_KEY = ""; |
| | | /** |
| | | * 支付宝公钥 |
| | | */ |
| | | private static final String ALIPAY_PUBLIC_KEY = ""; |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private IMemberService iMemberService; |
| | | |
| | | @Resource |
| | | private WxMaService wxMaService; |
| | | |
| | | @Resource |
| | | private RemoteUserService sysUserService; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Override |
| | | public Member loginThird(MemberDTO memberDTO) { |
| | | public AppMiniLoginVO loginThird(AppMiniLoginDTO appMiniLoginDto) { |
| | | AppMiniLoginVO appMiniLoginVo = new AppMiniLoginVO(); |
| | | |
| | | if(appMiniLoginDto.getType()==1){ |
| | | if (appMiniLoginDto.getAuth_code()== null || appMiniLoginDto.getAuth_code().length() == 0) { |
| | | } else { |
| | | AppMiniLoginVO user=new AppMiniLoginVO(); |
| | | //String serverUrl, String appId, String privateKey, String format,String charset, String alipayPublicKey, String signType |
| | | //实例化客户端 参数:正式环境URL,Appid,商户私钥 PKCS8格式,字符编码格式,字符格式,支付宝公钥,签名方式 |
| | | AlipayClient alipayClient = new DefaultAlipayClient(ALIPAY_BORDER_PROD,APP_ID_PROD, APP_PRIVATE_KEY, "json", "GBK", ALIPAY_PUBLIC_KEY, "RSA2"); |
| | | AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest(); |
| | | // 值为authorization_code时,代表用code换取 |
| | | request.setGrantType("authorization_code"); |
| | | //授权码,用户对应用授权后得到的 |
| | | request.setCode(appMiniLoginDto.getAuth_code()); |
| | | //这里使用execute方法 |
| | | AlipaySystemOauthTokenResponse response = null; |
| | | try { |
| | | if (memberDTO.getType() == 1) { |
| | | response = alipayClient.execute(request); |
| | | } catch (AlipayApiException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | //刷新令牌,上次换取访问令牌时得到。见出参的refresh_token字段 |
| | | request.setRefreshToken(response.getAccessToken()); |
| | | //返回成功时 就将唯一标识返回 |
| | | if (response.isSuccess()) { |
| | | System.out.println("调用成功"); |
| | | //我这里只返回了一个字段给前端用 |
| | | String user1= response.getUserId(); |
| | | |
| | | LambdaQueryWrapper<Member> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getZfbOpenid,memberDTO.getOpenid()); |
| | | wrapper.eq(Member::getZfbOpenid,response.getUserId()); |
| | | Member member=iMemberService.getOne(wrapper); |
| | | if (member==null){ |
| | | Member m=new Member(); |
| | | m.setZfbOpenid(memberDTO.getOpenid()); |
| | | m.setNickname("未知"); |
| | | m.setLevel(0); |
| | | m.setAvatar(""); |
| | | iMemberService.save(m); |
| | | return m; |
| | | SysUser sysUser = null; |
| | | if (member != null) { |
| | | sysUser = sysUserService.getSysUser(member.getUserId()).getData(); |
| | | } |
| | | appMiniLoginVo.setZfbuserid(response.getUserId()); |
| | | appMiniLoginVo.setSysUser(sysUser); |
| | | appMiniLoginVo.setMemberid(member.getId()); |
| | | redisService.setCacheObject(SecurityConstant.SESSION_KEY + response.getUserId(), null, 1L, TimeUnit.DAYS); |
| | | } |
| | | } |
| | | }else { |
| | | |
| | | return member; |
| | | } |
| | | |
| | | } |
| | | if (memberDTO.getType() == 2) { |
| | | LambdaQueryWrapper<Member> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getWxOpenid,memberDTO.getOpenid()); |
| | | Member member=iMemberService.getOne(wrapper); |
| | | if (member==null){ |
| | | Member m=new Member(); |
| | | m.setZfbOpenid(memberDTO.getOpenid()); |
| | | m.setNickname("未知"); |
| | | m.setLevel(0); |
| | | m.setAvatar(""); |
| | | iMemberService.save(m); |
| | | return m; |
| | | }else { |
| | | |
| | | return member; |
| | | } |
| | | } |
| | | WxMaJscode2SessionResult session = null; |
| | | String unionid; |
| | | String openid; |
| | | String sessionKey = null; |
| | | //获取session |
| | | try { |
| | | session = wxMaService.getUserService().getSessionInfo(appMiniLoginDto.getCode()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | |
| | | } |
| | | return null; |
| | | } |
| | | if (session != null && StringUtils.isNotBlank(session.getOpenid())) { |
| | | unionid = session.getUnionid(); |
| | | openid = session.getOpenid(); |
| | | sessionKey = session.getSessionKey(); |
| | | //获取用户 |
| | | LambdaQueryWrapper<Member> wrapper= Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getZfbOpenid,session.getOpenid()); |
| | | Member member=iMemberService.getOne(wrapper); |
| | | SysUser sysUser = null; |
| | | if (member != null) { |
| | | sysUser = sysUserService.getSysUser(member.getUserId()).getData(); |
| | | } |
| | | appMiniLoginVo.setMiniOpenid(openid); |
| | | appMiniLoginVo.setWxUnionid(unionid); |
| | | appMiniLoginVo.setMemberid(member.getId()); |
| | | appMiniLoginVo.setSysUser(sysUser); |
| | | appMiniLoginVo.setSessionKey(sessionKey); |
| | | redisService.setCacheObject(SecurityConstant.SESSION_KEY + openid, sessionKey, 1L, TimeUnit.DAYS); |
| | | } |
| | | } |
| | | |
| | | return appMiniLoginVo; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public Member getMembeid(MemberDTO memberDTO) { |
| | |
| | | public List<Member> getMemberListByIds(Set<Long> memberIdList) { |
| | | return this.listByIds(memberIdList); |
| | | } |
| | | |
| | | @Override |
| | | public AppMiniLoginVO miniRegister(AppMiniRegisterDTO appMiniRegisterDTO) { |
| | | AppMiniLoginVO appMiniLoginVO =new AppMiniLoginVO(); |
| | | SysUser sysUser; |
| | | if (appMiniRegisterDTO.getType() == 1) { |
| | | LambdaQueryWrapper<Member> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getZfbOpenid, appMiniRegisterDTO.getZfbuserid()); |
| | | Member member = iMemberService.getOne(wrapper); |
| | | |
| | | //获取用户为空则新建 |
| | | if (member == null) { |
| | | //创建新用户 |
| | | String memberId = IdUtils.simpleUUID(); |
| | | sysUser = new SysUser(); |
| | | sysUser.setUserName(memberId); |
| | | sysUser.setUserType("03"); |
| | | sysUser.setNickName("白金用户"); |
| | | sysUser.setPhonenumber(appMiniRegisterDTO.getMiniOpenid()); |
| | | sysUser.setAvatar("https://hongruitang.oss-cn-beijing.aliyuncs.com/default.png"); |
| | | String password = "123456"; |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(password)); |
| | | sysUser = sysUserService.registerUser(sysUser).getData(); |
| | | |
| | | member = new Member(); |
| | | member.setUserId(sysUser.getUserId()); |
| | | member.setDelFlag(0); |
| | | member.setRealName("白酒用户"); |
| | | member.setAvatar("https://hongruitang.oss-cn-beijing.aliyuncs.com/default.png"); |
| | | member.setWxUnionid(appMiniRegisterDTO.getWxUnionid()); |
| | | member.setMiniOpenid(appMiniRegisterDTO.getMiniOpenid()); |
| | | iMemberService.save(member); |
| | | |
| | | appMiniLoginVO.setMiniOpenid(member.getMiniOpenid()); |
| | | appMiniLoginVO.setWxUnionid(member.getWxUnionid()); |
| | | appMiniLoginVO.setSysUser(sysUser); |
| | | appMiniLoginVO.setMemberid(member.getId()); |
| | | } else { |
| | | sysUser = sysUserService.getSysUser(member.getUserId()).getData(); |
| | | appMiniLoginVO.setZfbuserid( appMiniRegisterDTO.getZfbuserid()); |
| | | appMiniLoginVO.setSysUser(sysUser); |
| | | appMiniLoginVO.setMemberid(member.getId()); |
| | | } |
| | | |
| | | } |
| | | if (appMiniRegisterDTO.getType() == 2) { |
| | | LambdaQueryWrapper<Member> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.eq(Member::getMiniOpenid, appMiniRegisterDTO.getMiniOpenid()); |
| | | Member member = iMemberService.getOne(wrapper); |
| | | //获取用户为空则新建 |
| | | if (member == null) { |
| | | //创建新用户 |
| | | String memberId = IdUtils.simpleUUID(); |
| | | sysUser = new SysUser(); |
| | | sysUser.setUserName(memberId); |
| | | sysUser.setUserType("03"); |
| | | sysUser.setNickName("白金用户"); |
| | | sysUser.setPhonenumber(appMiniRegisterDTO.getMiniOpenid()); |
| | | sysUser.setAvatar("https://hongruitang.oss-cn-beijing.aliyuncs.com/default.png"); |
| | | String password = "123456"; |
| | | sysUser.setPassword(SecurityUtils.encryptPassword(password)); |
| | | sysUser = sysUserService.registerUser(sysUser).getData(); |
| | | |
| | | member = new Member(); |
| | | member.setUserId(sysUser.getUserId()); |
| | | member.setDelFlag(0); |
| | | member.setRealName("白酒用户"); |
| | | member.setAvatar("https://hongruitang.oss-cn-beijing.aliyuncs.com/default.png"); |
| | | member.setWxUnionid(appMiniRegisterDTO.getWxUnionid()); |
| | | member.setMiniOpenid(appMiniRegisterDTO.getMiniOpenid()); |
| | | iMemberService.save(member); |
| | | |
| | | appMiniLoginVO.setMiniOpenid(member.getMiniOpenid()); |
| | | appMiniLoginVO.setWxUnionid(member.getWxUnionid()); |
| | | appMiniLoginVO.setSysUser(sysUser); |
| | | appMiniLoginVO.setMemberid(member.getId()); |
| | | } else { |
| | | sysUser = sysUserService.getSysUser(member.getUserId()).getData(); |
| | | appMiniLoginVO.setMiniOpenid(member.getMiniOpenid()); |
| | | appMiniLoginVO.setWxUnionid(member.getWxUnionid()); |
| | | appMiniLoginVO.setSysUser(sysUser); |
| | | appMiniLoginVO.setMemberid(member.getId()); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | return appMiniLoginVO; |
| | | |
| | | } |
| | | |
| | | public static String getAccessTokenByWX() throws Exception { |
| | | String host = ACCESS_TOKEN_HOST + "?appid=" + WX_APPID + "&secret=" + WX_SECRET + "&grant_type=client_credential"; |
| | | Map<String, String> headers = new HashMap<>(8); |
| | | HttpResponse response = HttpUtils.doGet(host, "", "GET", headers, null); |
| | | return EntityUtils.toString(response.getEntity()); |
| | | } |
| | | |
| | | public static String getMobileByWX(String accessToken, String code) throws Exception { |
| | | Map<String, String> headers = new HashMap<>(16); |
| | | headers.put("Content-Type", "application/json"); |
| | | headers.put("Accept", "application/json"); |
| | | Map<String, String> querys = new HashMap<>(16); |
| | | Map<String, String> bodys = new HashMap<>(16); |
| | | querys.put("access_token", accessToken); |
| | | bodys.put("code", code); |
| | | String body = JSONObject.toJSONString(bodys); |
| | | String host = "https://api.weixin.qq.com/wxa/business/getuserphonenumber"; |
| | | HttpResponse response = HttpUtils.doPost(host, "", "POST", headers, querys, body); |
| | | return EntityUtils.toString(response.getEntity()); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
New file |
| | |
| | | package com.ruoyi.member.util; |
| | | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.client.HttpClient; |
| | | import org.apache.http.client.entity.UrlEncodedFormEntity; |
| | | import org.apache.http.client.methods.HttpDelete; |
| | | import org.apache.http.client.methods.HttpGet; |
| | | import org.apache.http.client.methods.HttpPost; |
| | | import org.apache.http.client.methods.HttpPut; |
| | | import org.apache.http.conn.ClientConnectionManager; |
| | | import org.apache.http.conn.scheme.Scheme; |
| | | import org.apache.http.conn.scheme.SchemeRegistry; |
| | | import org.apache.http.conn.ssl.SSLSocketFactory; |
| | | import org.apache.http.entity.ByteArrayEntity; |
| | | import org.apache.http.entity.StringEntity; |
| | | import org.apache.http.impl.client.DefaultHttpClient; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | |
| | | import javax.net.ssl.SSLContext; |
| | | import javax.net.ssl.TrustManager; |
| | | import javax.net.ssl.X509TrustManager; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.net.URLEncoder; |
| | | import java.security.KeyManagementException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.cert.X509Certificate; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @ClassName HttpUtils |
| | | * @Description TODO |
| | | * @Author zhanglin |
| | | * @Date 2020/2/11 10:30 |
| | | * @Version 1.0 |
| | | **/ |
| | | public class HttpUtils { |
| | | |
| | | public static void main(String[] args) { |
| | | } |
| | | |
| | | |
| | | /** |
| | | * get |
| | | * |
| | | * @param host |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doGet(String host)throws Exception { |
| | | return doGet(host, "", "GET", null, null); |
| | | } |
| | | |
| | | /** |
| | | * get |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doGet(String host, String path, String method, Map<String, String> headers, Map<String, String> querys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpGet request = new HttpGet(buildUrl(host, path, querys)); |
| | | if(null != headers) { |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * post form |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param bodys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | Map<String, String> bodys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (bodys != null) { |
| | | List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>(); |
| | | |
| | | for (String key : bodys.keySet()) { |
| | | nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key))); |
| | | } |
| | | UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8"); |
| | | formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8"); |
| | | request.setEntity(formEntity); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Post String |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | String body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(body)) { |
| | | request.setEntity(new StringEntity(body, "utf-8")); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Post stream |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPost(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | byte[] body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPost request = new HttpPost(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (body != null) { |
| | | request.setEntity(new ByteArrayEntity(body)); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Put String |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPut(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | String body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPut request = new HttpPut(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (StringUtils.isNotBlank(body)) { |
| | | request.setEntity(new StringEntity(body, "utf-8")); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Put stream |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @param body |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doPut(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys, |
| | | byte[] body) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpPut request = new HttpPut(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | if (body != null) { |
| | | request.setEntity(new ByteArrayEntity(body)); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | /** |
| | | * Delete |
| | | * |
| | | * @param host |
| | | * @param path |
| | | * @param method |
| | | * @param headers |
| | | * @param querys |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static HttpResponse doDelete(String host, String path, String method, |
| | | Map<String, String> headers, |
| | | Map<String, String> querys) |
| | | throws Exception { |
| | | HttpClient httpClient = wrapClient(host); |
| | | |
| | | HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); |
| | | for (Map.Entry<String, String> e : headers.entrySet()) { |
| | | request.addHeader(e.getKey(), e.getValue()); |
| | | } |
| | | |
| | | return httpClient.execute(request); |
| | | } |
| | | |
| | | private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException { |
| | | StringBuilder sbUrl = new StringBuilder(); |
| | | sbUrl.append(host); |
| | | if (!StringUtils.isBlank(path)) { |
| | | sbUrl.append(path); |
| | | } |
| | | if (null != querys) { |
| | | StringBuilder sbQuery = new StringBuilder(); |
| | | for (Map.Entry<String, String> query : querys.entrySet()) { |
| | | if (0 < sbQuery.length()) { |
| | | sbQuery.append("&"); |
| | | } |
| | | if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) { |
| | | sbQuery.append(query.getValue()); |
| | | } |
| | | if (!StringUtils.isBlank(query.getKey())) { |
| | | sbQuery.append(query.getKey()); |
| | | if (!StringUtils.isBlank(query.getValue())) { |
| | | sbQuery.append("="); |
| | | sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8")); |
| | | } |
| | | } |
| | | } |
| | | if (0 < sbQuery.length()) { |
| | | sbUrl.append("?").append(sbQuery); |
| | | } |
| | | } |
| | | |
| | | return sbUrl.toString(); |
| | | } |
| | | |
| | | private static HttpClient wrapClient(String host) { |
| | | HttpClient httpClient = new DefaultHttpClient(); |
| | | if (host.startsWith("https://")) { |
| | | sslClient(httpClient); |
| | | } |
| | | |
| | | return httpClient; |
| | | } |
| | | |
| | | private static void sslClient(HttpClient httpClient) { |
| | | try { |
| | | SSLContext ctx = SSLContext.getInstance("TLS"); |
| | | X509TrustManager tm = new X509TrustManager() { |
| | | @Override |
| | | public X509Certificate[] getAcceptedIssuers() { |
| | | return null; |
| | | } |
| | | @Override |
| | | public void checkClientTrusted(X509Certificate[] xcs, String str) { |
| | | |
| | | } |
| | | @Override |
| | | public void checkServerTrusted(X509Certificate[] xcs, String str) { |
| | | |
| | | } |
| | | }; |
| | | ctx.init(null, new TrustManager[] { tm }, null); |
| | | SSLSocketFactory ssf = new SSLSocketFactory(ctx); |
| | | ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); |
| | | ClientConnectionManager ccm = httpClient.getConnectionManager(); |
| | | SchemeRegistry registry = ccm.getSchemeRegistry(); |
| | | registry.register(new Scheme("https", 443, ssf)); |
| | | } catch (KeyManagementException ex) { |
| | | throw new RuntimeException(ex); |
| | | } catch (NoSuchAlgorithmException ex) { |
| | | throw new RuntimeException(ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.ruoyi.order.service.IMemberInvoiceService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | |
| | | @PostMapping("/saveMemberInvoice") |
| | | @ResponseBody |
| | | @ApiOperation(value = "用户添加发票") |
| | | public R<T> saveMemberInvoice(MemberInvoiceDTO memberInvoiceDTO) { |
| | | public R<T> saveMemberInvoice(@RequestBody MemberInvoiceDTO memberInvoiceDTO) { |
| | | iMemberInvoiceService.saveMemberInvoice(memberInvoiceDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/getMemberInvoiceList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户开票历史") |
| | | public R<PageDTO<MemberInvoice>> getMemberInvoiceList(MemberInvoiceDTO memberInvoiceDTO) { |
| | | public R<PageDTO<MemberInvoice>> getMemberInvoiceList(@RequestBody MemberInvoiceDTO memberInvoiceDTO) { |
| | | return R.ok(iMemberInvoiceService.getMemberInvoiceList(memberInvoiceDTO)); |
| | | } |
| | | |
| | |
| | | import com.ruoyi.order.dto.MemberInvoiceRiseDTO; |
| | | import com.ruoyi.order.service.IMemberInvoiceOrderService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | |
| | | @PostMapping("/getMemberInvoiceInfo") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户开票历史详情") |
| | | public R<PageDTO<MemberInvoiceOrder>> getMemberInvoiceInfo(MemberInvoiceDTO memberInvoiceDTO) { |
| | | public R<PageDTO<MemberInvoiceOrder>> getMemberInvoiceInfo(@RequestBody MemberInvoiceDTO memberInvoiceDTO) { |
| | | return R.ok(iMemberInvoiceOrderService.getMemberInvoiceInfo(memberInvoiceDTO)); |
| | | } |
| | | } |
| | |
| | | import io.swagger.annotations.ApiOperation; |
| | | import javax.annotation.Resource; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @PostMapping("/getMemberInvoiceRiseList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户发票抬头") |
| | | public R<PageDTO<MemberInvoiceRise>> getMemberInvoiceRiseList(MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | public R<PageDTO<MemberInvoiceRise>> getMemberInvoiceRiseList(@RequestBody MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | return R.ok(iMemberInvoiceRiseService.getMemberInvoiceRiseList(memberInvoiceRiseDTO)); |
| | | } |
| | | |
| | | @PostMapping("/saveMemberInvoiceRise") |
| | | @ResponseBody |
| | | @ApiOperation(value = "添加编辑用户发票抬头") |
| | | public R<T> saveMemberInvoiceRise(MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | public R<T> saveMemberInvoiceRise(@RequestBody MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | iMemberInvoiceRiseService.saveMemberInvoiceRise(memberInvoiceRiseDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/saveIsDefault") |
| | | @ResponseBody |
| | | @ApiOperation(value = "设置默认") |
| | | public R<T> saveIsDefault(MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | public R<T> saveIsDefault(@RequestBody MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | iMemberInvoiceRiseService.saveIsDefault(memberInvoiceRiseDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @PostMapping("/delMemberInvoiceRise") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除用户发票抬头") |
| | | public R<T> delMemberInvoiceRise(MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | public R<T> delMemberInvoiceRise(@RequestBody MemberInvoiceRiseDTO memberInvoiceRiseDTO) { |
| | | iMemberInvoiceRiseService.delMemberInvoiceRise(memberInvoiceRiseDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | import com.ruoyi.promotion.domain.pojo.CouponMember; |
| | | import com.ruoyi.promotion.service.ICouponMemberService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | |
| | | @PostMapping("/getCouponMemberList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取用户优惠卷") |
| | | public R<PageDTO<CouponMember>> getCouponMemberList(CouponMemberDTO couponMemberDTO) { |
| | | public R<PageDTO<CouponMember>> getCouponMemberList(@RequestBody CouponMemberDTO couponMemberDTO) { |
| | | return R.ok(iCouponMemberService.getCouponMemberList(couponMemberDTO)); |
| | | } |
| | | |
| | |
| | | import com.ruoyi.promotion.service.IPromotionWishListService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.formula.functions.T; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | |
| | | @RequestMapping("/getPromotionWishList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取心愿单列表") |
| | | public R<PageDTO<PromotionWishList>> getPromotionWishList(PromotionWishListDTO promotionWishListDTO) { |
| | | public R<PageDTO<PromotionWishList>> getPromotionWishList(@RequestBody PromotionWishListDTO promotionWishListDTO) { |
| | | return R.ok(iPromotionWishListService.getPromotionWishList(promotionWishListDTO)); |
| | | } |
| | | |
| | | @RequestMapping("/savePromotionWishList") |
| | | @ResponseBody |
| | | @ApiOperation(value = "添加心愿单列表") |
| | | public R<T> savePromotionWishList(PromotionWishListDTO promotionWishListDTO) { |
| | | public R<T> savePromotionWishList(@RequestBody PromotionWishListDTO promotionWishListDTO) { |
| | | iPromotionWishListService.savePromotionWishList(promotionWishListDTO); |
| | | return R.ok(); |
| | | } |
| | |
| | | @RequestMapping("/getPromotionWishOne") |
| | | @ResponseBody |
| | | @ApiOperation(value = "获取心愿单个") |
| | | public R<PromotionWishList> getPromotionWishOne(PromotionWishListDTO promotionWishListDTO) { |
| | | public R<PromotionWishList> getPromotionWishOne(@RequestBody PromotionWishListDTO promotionWishListDTO) { |
| | | return R.ok(iPromotionWishListService.getPromotionWishOne(promotionWishListDTO)); |
| | | } |
| | | |
| | | @RequestMapping("/delPromotionWishOne") |
| | | @ResponseBody |
| | | @ApiOperation(value = "删除心愿单个") |
| | | public R<T> delPromotionWishOne(PromotionWishListDTO promotionWishListDTO) { |
| | | public R<T> delPromotionWishOne(@RequestBody PromotionWishListDTO promotionWishListDTO) { |
| | | iPromotionWishListService.delPromotionWishOne(promotionWishListDTO); |
| | | return R.ok(); |
| | | } |