From 19918427098b2dbd98cce8a7b09a798b8cf0fa6a Mon Sep 17 00:00:00 2001 From: lc <15038716315@163.com> Date: Mon, 8 Apr 2024 09:01:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AbucoderWxuserController.java | 104 +++++++++++++ .../abuwx/domain/AbucoderWxappConfig.java | 84 +++++++++++ .../ruoyi/abuwx/domain/AbucoderWxuser.java | 98 ++++++++++++ .../mapper/AbucoderWxappConfigMapper.java | 68 +++++++++ .../abuwx/mapper/AbucoderWxuserMapper.java | 69 +++++++++ .../service/IAbucoderWxappConfigService.java | 68 +++++++++ .../abuwx/service/IAbucoderWxuserService.java | 69 +++++++++ .../impl/AbucoderWxappConfigServiceImpl.java | 106 +++++++++++++ .../impl/AbucoderWxuserServiceImpl.java | 106 +++++++++++++ .../com/ruoyi/abuwxapi/WxLoginController.java | 141 ++++++++++++++++++ .../abuwx/AbucoderWxappConfigMapper.xml | 90 +++++++++++ .../mapper/abuwx/AbucoderWxuserMapper.xml | 93 ++++++++++++ .../framework/config/SecurityConfig.java | 8 +- 13 files changed, 1100 insertions(+), 4 deletions(-) create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/controller/AbucoderWxuserController.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxappConfig.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxuser.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxappConfigMapper.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxuserMapper.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxappConfigService.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxuserService.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxappConfigServiceImpl.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxuserServiceImpl.java create mode 100644 ruoyi-abuwx/src/main/java/com/ruoyi/abuwxapi/WxLoginController.java create mode 100644 ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxappConfigMapper.xml create mode 100644 ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxuserMapper.xml diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/controller/AbucoderWxuserController.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/controller/AbucoderWxuserController.java new file mode 100644 index 0000000..5a1385b --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/controller/AbucoderWxuserController.java @@ -0,0 +1,104 @@ +package com.ruoyi.abuwx.controller; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.abuwx.domain.AbucoderWxuser; +import com.ruoyi.abuwx.service.IAbucoderWxuserService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 微信用户Controller + * + * @author 阿卜Coder QQ932696181 + * @date 2024-04-07 + */ +@RestController +@RequestMapping("/abuwx/wxuser") +public class AbucoderWxuserController extends BaseController +{ + @Autowired + private IAbucoderWxuserService abucoderWxuserService; + + /** + * 查询微信用户列表 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:list')") + @GetMapping("/list") + public TableDataInfo list(AbucoderWxuser abucoderWxuser) + { + startPage(); + List list = abucoderWxuserService.selectAbucoderWxuserList(abucoderWxuser); + return getDataTable(list); + } + + /** + * 导出微信用户列表 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:export')") + @Log(title = "微信用户", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, AbucoderWxuser abucoderWxuser) + { + List list = abucoderWxuserService.selectAbucoderWxuserList(abucoderWxuser); + ExcelUtil util = new ExcelUtil(AbucoderWxuser.class); + util.exportExcel(response, list, "微信用户数据"); + } + + /** + * 获取微信用户详细信息 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(abucoderWxuserService.selectAbucoderWxuserById(id)); + } + + /** + * 新增微信用户 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:add')") + @Log(title = "微信用户", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody AbucoderWxuser abucoderWxuser) + { + return toAjax(abucoderWxuserService.insertAbucoderWxuser(abucoderWxuser)); + } + + /** + * 修改微信用户 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:edit')") + @Log(title = "微信用户", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody AbucoderWxuser abucoderWxuser) + { + return toAjax(abucoderWxuserService.updateAbucoderWxuser(abucoderWxuser)); + } + + /** + * 删除微信用户 + */ + @PreAuthorize("@ss.hasPermi('abuwx:wxuser:remove')") + @Log(title = "微信用户", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(abucoderWxuserService.deleteAbucoderWxuserByIds(ids)); + } +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxappConfig.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxappConfig.java new file mode 100644 index 0000000..097133a --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxappConfig.java @@ -0,0 +1,84 @@ +package com.ruoyi.abuwx.domain; + +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 小程序配置对象 abucoder_wxapp_config + * + * @author 阿卜Coder QQ932696181 + * @date 2022-06-28 + */ +public class AbucoderWxappConfig extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** ID */ + private Long id; + + /** 小程序ID */ + @Excel(name = "小程序ID") + private String appid; + + /** 小程序密钥 */ + @Excel(name = "小程序密钥") + private String appSecret; + + /** 状态 */ + @Excel(name = "状态") + private Integer state; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setAppid(String appid) + { + this.appid = appid; + } + + public String getAppid() + { + return appid; + } + public void setAppSecret(String appSecret) + { + this.appSecret = appSecret; + } + + public String getAppSecret() + { + return appSecret; + } + public void setState(Integer state) + { + this.state = state; + } + + public Integer getState() + { + return state; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("appid", getAppid()) + .append("appSecret", getAppSecret()) + .append("state", getState()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxuser.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxuser.java new file mode 100644 index 0000000..c17ba8a --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/domain/AbucoderWxuser.java @@ -0,0 +1,98 @@ +package com.ruoyi.abuwx.domain; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.core.domain.BaseEntity; + +/** + * 微信用户对象 abucoder_wxuser + * + * @author 阿卜Coder QQ932696181 + * @date 2024-04-07 + */ +public class AbucoderWxuser extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** ID */ + private Long id; + + /** 微信名称 */ + @Excel(name = "微信名称") + private String nickname; + + /** 头像 */ + @Excel(name = "头像") + private String avatar; + + /** OpenID */ + @Excel(name = "OpenID") + private String openid; + + /** 性别 */ + @Excel(name = "性别") + private Integer gender; + + public void setId(Long id) + { + this.id = id; + } + + public Long getId() + { + return id; + } + public void setNickname(String nickname) + { + this.nickname = nickname; + } + + public String getNickname() + { + return nickname; + } + public void setAvatar(String avatar) + { + this.avatar = avatar; + } + + public String getAvatar() + { + return avatar; + } + public void setOpenid(String openid) + { + this.openid = openid; + } + + public String getOpenid() + { + return openid; + } + public void setGender(Integer gender) + { + this.gender = gender; + } + + public Integer getGender() + { + return gender; + } + + @Override + public String toString() { + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) + .append("id", getId()) + .append("nickname", getNickname()) + .append("avatar", getAvatar()) + .append("openid", getOpenid()) + .append("gender", getGender()) + .append("createBy", getCreateBy()) + .append("createTime", getCreateTime()) + .append("updateBy", getUpdateBy()) + .append("updateTime", getUpdateTime()) + .append("remark", getRemark()) + .toString(); + } +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxappConfigMapper.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxappConfigMapper.java new file mode 100644 index 0000000..14d2863 --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxappConfigMapper.java @@ -0,0 +1,68 @@ +package com.ruoyi.abuwx.mapper; + +import com.ruoyi.abuwx.domain.AbucoderWxappConfig; + +import java.util.List; + +/** + * 小程序配置Mapper接口 + * + * @author 阿卜Coder QQ932696181 + * @date 2022-06-28 + */ +public interface AbucoderWxappConfigMapper +{ + /** + * 查询小程序配置 + * + * @param id 小程序配置主键 + * @return 小程序配置 + */ + public AbucoderWxappConfig selectAbucoderWxappConfigById(Long id); + + /** + * 查询小程序配置列表 + * + * @param abucoderWxappConfig 小程序配置 + * @return 小程序配置集合 + */ + public List selectAbucoderWxappConfigList(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 新增小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + public int insertAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 修改小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + public int updateAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 删除小程序配置 + * + * @param id 小程序配置主键 + * @return 结果 + */ + public int deleteAbucoderWxappConfigById(Long id); + + /** + * 批量删除小程序配置 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteAbucoderWxappConfigByIds(Long[] ids); + + /** + * 查询开启的小程序配置信息 + * @return + */ + AbucoderWxappConfig selectAbucoderWxappConfig(); +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxuserMapper.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxuserMapper.java new file mode 100644 index 0000000..9f464a7 --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/mapper/AbucoderWxuserMapper.java @@ -0,0 +1,69 @@ +package com.ruoyi.abuwx.mapper; + +import com.ruoyi.abuwx.domain.AbucoderWxuser; + +import java.util.List; + +/** + * 微信用户Mapper接口 + * + * @author 阿卜Coder QQ932696181 + * @date 2024-04-07 + */ +public interface AbucoderWxuserMapper +{ + /** + * 查询微信用户 + * + * @param id 微信用户主键 + * @return 微信用户 + */ + public AbucoderWxuser selectAbucoderWxuserById(Long id); + + /** + * 查询微信用户列表 + * + * @param abucoderWxuser 微信用户 + * @return 微信用户集合 + */ + public List selectAbucoderWxuserList(AbucoderWxuser abucoderWxuser); + + /** + * 新增微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + public int insertAbucoderWxuser(AbucoderWxuser abucoderWxuser); + + /** + * 修改微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + public int updateAbucoderWxuser(AbucoderWxuser abucoderWxuser); + + /** + * 删除微信用户 + * + * @param id 微信用户主键 + * @return 结果 + */ + public int deleteAbucoderWxuserById(Long id); + + /** + * 批量删除微信用户 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteAbucoderWxuserByIds(Long[] ids); + + /** + * 通过OpenID查询微信用户信息 + * @param openid + * @return + */ + public AbucoderWxuser selectAbucoderWxuserOpenID(String openid); +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxappConfigService.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxappConfigService.java new file mode 100644 index 0000000..5db1a64 --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxappConfigService.java @@ -0,0 +1,68 @@ +package com.ruoyi.abuwx.service; + +import com.ruoyi.abuwx.domain.AbucoderWxappConfig; + +import java.util.List; + +/** + * 小程序配置Service接口 + * + * @author 阿卜Coder QQ932696181 + * @date 2022-06-28 + */ +public interface IAbucoderWxappConfigService +{ + /** + * 查询小程序配置 + * + * @param id 小程序配置主键 + * @return 小程序配置 + */ + public AbucoderWxappConfig selectAbucoderWxappConfigById(Long id); + + /** + * 查询小程序配置列表 + * + * @param abucoderWxappConfig 小程序配置 + * @return 小程序配置集合 + */ + public List selectAbucoderWxappConfigList(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 新增小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + public int insertAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 修改小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + public int updateAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig); + + /** + * 批量删除小程序配置 + * + * @param ids 需要删除的小程序配置主键集合 + * @return 结果 + */ + public int deleteAbucoderWxappConfigByIds(Long[] ids); + + /** + * 删除小程序配置信息 + * + * @param id 小程序配置主键 + * @return 结果 + */ + public int deleteAbucoderWxappConfigById(Long id); + + /** + * 查询开启的小程序配置信息 + * @return + */ + public AbucoderWxappConfig selectAbucoderWxappConfig(); +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxuserService.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxuserService.java new file mode 100644 index 0000000..45e35b1 --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/IAbucoderWxuserService.java @@ -0,0 +1,69 @@ +package com.ruoyi.abuwx.service; + +import com.ruoyi.abuwx.domain.AbucoderWxuser; + +import java.util.List; + +/** + * 微信用户Service接口 + * + * @author 阿卜Coder QQ932696181 + * @date 2024-04-07 + */ +public interface IAbucoderWxuserService +{ + /** + * 查询微信用户 + * + * @param id 微信用户主键 + * @return 微信用户 + */ + public AbucoderWxuser selectAbucoderWxuserById(Long id); + + /** + * 查询微信用户列表 + * + * @param abucoderWxuser 微信用户 + * @return 微信用户集合 + */ + public List selectAbucoderWxuserList(AbucoderWxuser abucoderWxuser); + + /** + * 新增微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + public int insertAbucoderWxuser(AbucoderWxuser abucoderWxuser); + + /** + * 修改微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + public int updateAbucoderWxuser(AbucoderWxuser abucoderWxuser); + + /** + * 批量删除微信用户 + * + * @param ids 需要删除的微信用户主键集合 + * @return 结果 + */ + public int deleteAbucoderWxuserByIds(Long[] ids); + + /** + * 删除微信用户信息 + * + * @param id 微信用户主键 + * @return 结果 + */ + public int deleteAbucoderWxuserById(Long id); + + /** + * 通过OpenID查询微信用户信息 + * @param openid + * @return + */ + public AbucoderWxuser selectAbucoderWxuserOpenID(String openid); +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxappConfigServiceImpl.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxappConfigServiceImpl.java new file mode 100644 index 0000000..6e6b46e --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxappConfigServiceImpl.java @@ -0,0 +1,106 @@ +package com.ruoyi.abuwx.service.impl; + +import com.ruoyi.abuwx.domain.AbucoderWxappConfig; +import com.ruoyi.abuwx.mapper.AbucoderWxappConfigMapper; +import com.ruoyi.abuwx.service.IAbucoderWxappConfigService; +import com.ruoyi.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 小程序配置Service业务层处理 + * + * @author 阿卜Coder QQ932696181 + * @date 2022-06-28 + */ +@Service +public class AbucoderWxappConfigServiceImpl implements IAbucoderWxappConfigService +{ + @Autowired + private AbucoderWxappConfigMapper abucoderWxappConfigMapper; + + /** + * 查询小程序配置 + * + * @param id 小程序配置主键 + * @return 小程序配置 + */ + @Override + public AbucoderWxappConfig selectAbucoderWxappConfigById(Long id) + { + return abucoderWxappConfigMapper.selectAbucoderWxappConfigById(id); + } + + /** + * 查询小程序配置列表 + * + * @param abucoderWxappConfig 小程序配置 + * @return 小程序配置 + */ + @Override + public List selectAbucoderWxappConfigList(AbucoderWxappConfig abucoderWxappConfig) + { + return abucoderWxappConfigMapper.selectAbucoderWxappConfigList(abucoderWxappConfig); + } + + /** + * 新增小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + @Override + public int insertAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig) + { + abucoderWxappConfig.setCreateTime(DateUtils.getNowDate()); + return abucoderWxappConfigMapper.insertAbucoderWxappConfig(abucoderWxappConfig); + } + + /** + * 修改小程序配置 + * + * @param abucoderWxappConfig 小程序配置 + * @return 结果 + */ + @Override + public int updateAbucoderWxappConfig(AbucoderWxappConfig abucoderWxappConfig) + { + abucoderWxappConfig.setUpdateTime(DateUtils.getNowDate()); + return abucoderWxappConfigMapper.updateAbucoderWxappConfig(abucoderWxappConfig); + } + + /** + * 批量删除小程序配置 + * + * @param ids 需要删除的小程序配置主键 + * @return 结果 + */ + @Override + public int deleteAbucoderWxappConfigByIds(Long[] ids) + { + return abucoderWxappConfigMapper.deleteAbucoderWxappConfigByIds(ids); + } + + /** + * 删除小程序配置信息 + * + * @param id 小程序配置主键 + * @return 结果 + */ + @Override + public int deleteAbucoderWxappConfigById(Long id) + { + return abucoderWxappConfigMapper.deleteAbucoderWxappConfigById(id); + } + + /** + * 查询开启的小程序配置信息 + * @return + */ + @Override + public AbucoderWxappConfig selectAbucoderWxappConfig() { + return abucoderWxappConfigMapper.selectAbucoderWxappConfig(); + } +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxuserServiceImpl.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxuserServiceImpl.java new file mode 100644 index 0000000..04b3f47 --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwx/service/impl/AbucoderWxuserServiceImpl.java @@ -0,0 +1,106 @@ +package com.ruoyi.abuwx.service.impl; + +import java.util.List; +import com.ruoyi.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.abuwx.mapper.AbucoderWxuserMapper; +import com.ruoyi.abuwx.domain.AbucoderWxuser; +import com.ruoyi.abuwx.service.IAbucoderWxuserService; + +/** + * 微信用户Service业务层处理 + * + * @author 阿卜Coder QQ932696181 + * @date 2024-04-07 + */ +@Service +public class AbucoderWxuserServiceImpl implements IAbucoderWxuserService +{ + @Autowired + private AbucoderWxuserMapper abucoderWxuserMapper; + + /** + * 查询微信用户 + * + * @param id 微信用户主键 + * @return 微信用户 + */ + @Override + public AbucoderWxuser selectAbucoderWxuserById(Long id) + { + return abucoderWxuserMapper.selectAbucoderWxuserById(id); + } + + /** + * 查询微信用户列表 + * + * @param abucoderWxuser 微信用户 + * @return 微信用户 + */ + @Override + public List selectAbucoderWxuserList(AbucoderWxuser abucoderWxuser) + { + return abucoderWxuserMapper.selectAbucoderWxuserList(abucoderWxuser); + } + + /** + * 新增微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + @Override + public int insertAbucoderWxuser(AbucoderWxuser abucoderWxuser) + { + abucoderWxuser.setCreateTime(DateUtils.getNowDate()); + return abucoderWxuserMapper.insertAbucoderWxuser(abucoderWxuser); + } + + /** + * 修改微信用户 + * + * @param abucoderWxuser 微信用户 + * @return 结果 + */ + @Override + public int updateAbucoderWxuser(AbucoderWxuser abucoderWxuser) + { + abucoderWxuser.setUpdateTime(DateUtils.getNowDate()); + return abucoderWxuserMapper.updateAbucoderWxuser(abucoderWxuser); + } + + /** + * 批量删除微信用户 + * + * @param ids 需要删除的微信用户主键 + * @return 结果 + */ + @Override + public int deleteAbucoderWxuserByIds(Long[] ids) + { + return abucoderWxuserMapper.deleteAbucoderWxuserByIds(ids); + } + + /** + * 删除微信用户信息 + * + * @param id 微信用户主键 + * @return 结果 + */ + @Override + public int deleteAbucoderWxuserById(Long id) + { + return abucoderWxuserMapper.deleteAbucoderWxuserById(id); + } + + /** + * 通过OpenID查询微信用户信息 + * @param openid + * @return + */ + @Override + public AbucoderWxuser selectAbucoderWxuserOpenID(String openid) { + return abucoderWxuserMapper.selectAbucoderWxuserOpenID(openid); + } +} diff --git a/ruoyi-abuwx/src/main/java/com/ruoyi/abuwxapi/WxLoginController.java b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwxapi/WxLoginController.java new file mode 100644 index 0000000..a725a5d --- /dev/null +++ b/ruoyi-abuwx/src/main/java/com/ruoyi/abuwxapi/WxLoginController.java @@ -0,0 +1,141 @@ +package com.ruoyi.abuwxapi; + +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.abuwx.domain.AbucoderWxuser; +import com.ruoyi.abuwx.service.IAbucoderWxappConfigService; +import com.ruoyi.abuwx.service.IAbucoderWxuserService; +import com.ruoyi.common.config.RuoYiConfig; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.common.utils.file.FileUploadUtils; +import com.ruoyi.common.utils.file.FileUtils; +import com.ruoyi.common.utils.http.HttpUtils; +import com.ruoyi.framework.config.ServerConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequestMapping("/wxapi/") +public class WxLoginController { + + /** + * 测试接口 + * @return + */ + @GetMapping("test") + public AjaxResult test(){ + return AjaxResult.success("小程序api调试成功!~"); + } + + @Autowired + private IAbucoderWxuserService iAbucoderWxuserService; + + @Autowired + private IAbucoderWxappConfigService wxappConfigService; + + @Autowired + private ServerConfig serverConfig; + + /** + * 你自己的微信小程序APPID + */ + + private final static String AppID = "wxeda4365eac6838c5"; + /** + * 你自己的微信APP密钥 + */ + private final static String AppSecret = "5005219596b2fa77ad930d06101102b1"; + + /** + * 登录时获取的 code(微信官方提供的临时凭证) + * @param object + * @return + */ + @PostMapping("/wxlogin") + public AjaxResult wxLogin(@RequestBody JSONObject object){ + //微信官方提供的微信小程序登录授权时使用的URL地址 + String url = "https://api.weixin.qq.com/sns/jscode2session"; + System.out.println(object); + + /** + * 拼接需要的参数 + * appid = AppID 你自己的微信小程序APPID + * js_code = AppSecret 你自己的微信APP密钥 + * grant_type=authorization_code = code 微信官方提供的临时凭证 + */ + String params = StrUtil.format("appid={}&secret={}&js_code={}&grant_type=authorization_code", AppID, AppSecret, object.get("code")); + //开始发起网络请求,若依管理系统自带网络请求工具,直接使用即可 + String res = HttpUtils.sendGet(url,params); + JSONObject jsonObject = JSON.parseObject(res); + String openid = (String) jsonObject.get("openid"); + if (StrUtil.isEmpty(openid)) { + return AjaxResult.error("未获取到openid"); + } + /**先通过openid来查询是否存在*/ + AbucoderWxuser abucoderWxuser = iAbucoderWxuserService.selectAbucoderWxuserOpenID(openid); + if (abucoderWxuser == null){ + /**如果不存在就插入到我们的数据库里*/ + AbucoderWxuser wxuser = new AbucoderWxuser(); + wxuser.setOpenid(openid); + wxuser.setCreateTime(DateUtils.getNowDate()); + iAbucoderWxuserService.insertAbucoderWxuser(wxuser); + /**返回结果集到前段*/ + return AjaxResult.success(wxuser); + }else { + /**返回结果集到前段*/ + return AjaxResult.success(abucoderWxuser); + } + } + + @PostMapping("/upload") + @ResponseBody + public AjaxResult uploadFile(MultipartFile file) throws Exception + { + System.out.println(file); + try + { + // 上传文件路径 + String filePath = RuoYiConfig.getUploadPath(); + // 上传并返回新文件名称 + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + AjaxResult ajax = AjaxResult.success(); + ajax.put("url", url); + ajax.put("fileName", fileName); + ajax.put("newFileName", FileUtils.getName(fileName)); + ajax.put("originalFilename", file.getOriginalFilename()); + return ajax; + } + catch (Exception e) + { + return AjaxResult.error(e.getMessage()); + } + } + + /** + * 保存昵称与头像信息到用户信息里 + * @param object + * @return + */ + @PostMapping("/saveUserInfo") + @ResponseBody + public AjaxResult saveUserInfo(@RequestBody JSONObject object){ + System.out.println(object); + AbucoderWxuser abucoderWxuser = iAbucoderWxuserService.selectAbucoderWxuserOpenID(String.valueOf(object.get("openid"))); + if (StringUtils.hasLength(String.valueOf(object.get("nickName")))){ + abucoderWxuser.setNickname(String.valueOf(object.get("nickName"))); + abucoderWxuser.setCreateBy(String.valueOf(object.get("nickName"))); + } + if (StringUtils.hasLength(String.valueOf(object.get("avatarUrl")))){ + abucoderWxuser.setAvatar(String.valueOf(object.get("avatarUrl"))); + } + abucoderWxuser.setUpdateTime(DateUtils.getNowDate()); + iAbucoderWxuserService.updateAbucoderWxuser(abucoderWxuser); + //返回前段需要的数据 + return AjaxResult.success(abucoderWxuser); + } +} diff --git a/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxappConfigMapper.xml b/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxappConfigMapper.xml new file mode 100644 index 0000000..8e365ee --- /dev/null +++ b/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxappConfigMapper.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + + + + + + + select id, appid, app_secret, state, create_by, create_time, update_by, update_time, remark from abucoder_wxapp_config + + + + + + + + + insert into abucoder_wxapp_config + + appid, + app_secret, + state, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{appid}, + #{appSecret}, + #{state}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update abucoder_wxapp_config + + appid = #{appid}, + app_secret = #{appSecret}, + state = #{state}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where id = #{id} + + + + delete from abucoder_wxapp_config where id = #{id} + + + + delete from abucoder_wxapp_config where id in + + #{id} + + + \ No newline at end of file diff --git a/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxuserMapper.xml b/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxuserMapper.xml new file mode 100644 index 0000000..10f4c27 --- /dev/null +++ b/ruoyi-abuwx/src/main/resources/mapper/abuwx/AbucoderWxuserMapper.xml @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + select id, nickname, avatar, openid, gender, create_by, create_time, update_by, update_time, remark from abucoder_wxuser + + + + + + + + insert into abucoder_wxuser + + nickname, + avatar, + openid, + gender, + create_by, + create_time, + update_by, + update_time, + remark, + + + #{nickname}, + #{avatar}, + #{openid}, + #{gender}, + #{createBy}, + #{createTime}, + #{updateBy}, + #{updateTime}, + #{remark}, + + + + + update abucoder_wxuser + + nickname = #{nickname}, + avatar = #{avatar}, + openid = #{openid}, + gender = #{gender}, + create_by = #{createBy}, + create_time = #{createTime}, + update_by = #{updateBy}, + update_time = #{updateTime}, + remark = #{remark}, + + where id = #{id} + + + + delete from abucoder_wxuser where id = #{id} + + + + delete from abucoder_wxuser where id in + + #{id} + + + + diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 2125853..ee25c53 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -22,7 +22,7 @@ import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl; /** * spring security配置 - * + * * @author ruoyi */ @EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true) @@ -33,7 +33,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter */ @Autowired private UserDetailsService userDetailsService; - + /** * 认证失败处理类 */ @@ -51,7 +51,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter */ @Autowired private JwtAuthenticationTokenFilter authenticationTokenFilter; - + /** * 跨域过滤器 */ @@ -111,7 +111,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter // 过滤请求 .authorizeRequests() // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - .antMatchers("/login", "/register", "/captchaImage").permitAll() + .antMatchers("/login", "/register", "/captchaImage","/wxapi/**","/profile/**").permitAll() // 静态资源,可匿名访问 .antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**").permitAll() .antMatchers("/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs", "/druid/**").permitAll()