| | |
| | | package com.ruoyi.member.service.impl.member; |
| | | |
| | | import cn.binarywang.wx.miniapp.api.WxMaService; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import com.alibaba.fastjson.JSONObject; |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.google.common.collect.Lists; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.constant.SecurityConstants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.utils.DateUtils; |
| | | import com.ruoyi.common.core.utils.JwtUtils; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.utils.ip.IpUtils; |
| | | import com.ruoyi.common.core.utils.uuid.IdUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | |
| | | import com.ruoyi.system.api.domain.poji.config.SysTag; |
| | | import com.ruoyi.system.api.domain.poji.member.Member; |
| | | import com.ruoyi.system.api.domain.poji.shop.Shop; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysFile; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.api.domain.vo.*; |
| | | import com.ruoyi.system.api.model.AppMiniLoginDto; |
| | | import com.ruoyi.system.api.model.AppMiniLoginVo; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import com.ruoyi.system.api.service.RemoteConfigService; |
| | | import com.ruoyi.system.api.service.RemoteOrderService; |
| | | import com.ruoyi.system.api.service.RemoteShopService; |
| | | import com.ruoyi.system.api.service.RemoteUserService; |
| | | import com.ruoyi.system.api.service.*; |
| | | import io.jsonwebtoken.lang.Assert; |
| | | import lombok.extern.log4j.Log4j2; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.ArrayUtils; |
| | | import org.apache.http.HttpResponse; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.FileCopyUtils; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.annotation.Nullable; |
| | | import javax.annotation.Resource; |
| | | import java.io.*; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | |
| | | |
| | | @Resource |
| | | private TokenService tokenService; |
| | | |
| | | @Resource |
| | | private RemoteFileService remoteFileService; |
| | | |
| | | |
| | | /** |
| | |
| | | appUserRegisterVo.setOpenid(member.getMiniOpenid()); |
| | | appUserRegisterVo.setUnionid(member.getWxUnionid()); |
| | | appUserRegisterVo.setSysUser(sysUser); |
| | | |
| | | LoginUser loginUser = new LoginUser(); |
| | | // Jwt存储信息 |
| | | Map<String, Object> claimsMap = new HashMap<String, Object>(); |
| | | loginUser.setSysUser(sysUser); |
| | | 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()); |
| | | tokenService.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); |
| | | appUserRegisterVo.setToken(JwtUtils.createToken(claimsMap)); |
| | | return appUserRegisterVo; |
| | | } |
| | | |
| | |
| | | memberTotalService.saveOrUpdate(memberTotal); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public String getWeiXinQrCode(String scene, String path) { |
| | | try { |
| | | File file = wxMaService.getQrcodeService().createWxaCodeUnlimit(scene, path); |
| | | FileInputStream input = new FileInputStream(file); |
| | | MultipartFile multipartFile = new MyMultipartFile("file", file.getName(), "text/plain", IOUtils.toByteArray(input)); |
| | | |
| | | SysFile sysFile = remoteFileService.upload(multipartFile).getData(); |
| | | return sysFile.getUrl(); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public class MyMultipartFile implements MultipartFile { |
| | | private final String name; |
| | | private final byte[] content; |
| | | private String originalFilename; |
| | | @Nullable |
| | | private String contentType; |
| | | |
| | | |
| | | public MyMultipartFile(String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) { |
| | | Assert.hasLength(name, "Name must not be null"); |
| | | this.name = name; |
| | | this.originalFilename = originalFilename != null ? originalFilename : ""; |
| | | this.contentType = contentType; |
| | | this.content = content != null ? content : new byte[0]; |
| | | } |
| | | |
| | | public String getName() { |
| | | return this.name; |
| | | } |
| | | |
| | | public String getOriginalFilename() { |
| | | return this.originalFilename; |
| | | } |
| | | |
| | | @Nullable |
| | | public String getContentType() { |
| | | return this.contentType; |
| | | } |
| | | |
| | | public boolean isEmpty() { |
| | | return this.content.length == 0; |
| | | } |
| | | |
| | | public long getSize() { |
| | | return (long) this.content.length; |
| | | } |
| | | |
| | | public byte[] getBytes() throws IOException { |
| | | return this.content; |
| | | } |
| | | |
| | | public InputStream getInputStream() throws IOException { |
| | | return new ByteArrayInputStream(this.content); |
| | | } |
| | | |
| | | public void transferTo(File dest) throws IOException, IllegalStateException { |
| | | FileCopyUtils.copy(this.content, dest); |
| | | } |
| | | } |
| | | |
| | | } |