diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java new file mode 100644 index 0000000..83d8d28 --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/comment/CommentController.java @@ -0,0 +1,77 @@ +//package com.mcwl.web.controller.comment; +// +// +//import com.mcwl.comment.domain.ProductCommentConditionEntity; +//import com.mcwl.comment.domain.ProductCommentEntity; +//import com.mcwl.comment.service.impl.CommentServiceImpl; +//import com.mcwl.common.utils.ResponsePageEntity; +//import com.mcwl.resource.domain.MallProduct; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.web.bind.annotation.*; +// +//import javax.validation.constraints.NotNull; +//import java.util.List; +// +///** +// * @Author:ChenYan +// * @Project:McWl +// * @Package:com.mcwl.web.controller.comment +// * @Filename:CommentController +// * @Description TODO +// * @Date:2025/1/4 18:56 +// */ +//@RestController +//@RequestMapping("/comment") +//public class CommentController { +// +// @Autowired +// private CommentServiceImpl commentService; +// +// /** +// * 通过id查询商品评论信息 +// * +// * @param id 系统ID +// * @return 商品评论信息 +// */ +// @GetMapping("/findById") +// public MallProduct findById(Long id) { +// return commentService.findById(id); +// } +// +// +// +// /** +// * 添加商品评论 +// * +// * @param productCommentEntity 商品评论实体 +// * @return 影响行数 +// */ +// @PostMapping("/insert") +// public int insert(@RequestBody ProductCommentEntity productCommentEntity) { +// return commentService.insert(productCommentEntity); +// } +// +// /** +// * 修改商品评论 +// * +// * @param productCommentEntity 商品评论实体 +// * @return 影响行数 +// */ +// @PostMapping("/update") +// public int update(@RequestBody ProductCommentEntity productCommentEntity) { +// return commentService.update(productCommentEntity); +// } +// +// /** +// * 批量删除商品评论 +// * +// * @param ids 商品评论ID集合 +// * @return 影响行数 +// */ +// @PostMapping("/deleteByIds") +// public int deleteByIds(@RequestBody @NotNull List ids) { +// return commentService.deleteByIds(ids); +// } +// +// +//} diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/WxPay/WxPayController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/WxPay/WxPayController.java new file mode 100644 index 0000000..ec2efe6 --- /dev/null +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/pay/WxPay/WxPayController.java @@ -0,0 +1,65 @@ +package com.mcwl.web.controller.pay.WxPay; + +import cn.hutool.json.JSONObject; +import cn.hutool.json.JSONUtil; +import com.mcwl.web.controller.pay.WxPay.util.PayUtil; +import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; +import org.springframework.web.bind.annotation.*; + +import java.nio.charset.StandardCharsets; +import java.util.HashMap; +import java.util.Map; + +/** + * 微信支付 + * + * @author DaiZibo + * @date 2025/1/6 + * @apiNote + */ + + +@RestController +@RequestMapping(value = "/wx/pay") +public class WxPayController { + + /** + * 预支付下单 + * + * @param orderSn 订单号 + * @param total 分 + * @param description 描述 + */ + @GetMapping(value = "/getPay") + public String getPay(String orderSn, int total, String description) { + PayUtil payUtil = new PayUtil(); + try { + return payUtil.requestwxChatPay(orderSn, total, description, "oYgFI91D00GpCwccdnKDR4KNxI4k"); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + // 支付回调 + @PostMapping(value = "/returnNotify") + public Map returnNotify(@RequestBody JSONObject jsonObject) { + // v3 私钥 + String key = "xxxxx"; + String json = jsonObject.toString(); + String associated_data = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.associated_data"); + String ciphertext = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.ciphertext"); + String nonce = (String) JSONUtil.getByPath(JSONUtil.parse(json), "resource.nonce"); + try { + String decryptData = new AesUtil(key.getBytes(StandardCharsets.UTF_8)).decryptToString(associated_data.getBytes(StandardCharsets.UTF_8), nonce.getBytes(StandardCharsets.UTF_8), ciphertext); + System.out.println("decryptData = " + decryptData); + //TODO 业务校验 + } catch (Exception e) { + e.printStackTrace(); + } + HashMap stringStringHashMap = new HashMap<>(); + stringStringHashMap.put("code", "200"); + stringStringHashMap.put("message", "返回成功"); + // 返回这个说明应答成功 + return stringStringHashMap; + } +} diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/MallProductLikeController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/MallProductLikeController.java index 50e18fd..abcca5c 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/MallProductLikeController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/resource/MallProductLikeController.java @@ -16,7 +16,7 @@ import org.springframework.web.bind.annotation.*; * @apiNote */ -@RequestMapping("like") +@RequestMapping("/like") @RestController public class MallProductLikeController { diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/system/SysUserController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/system/SysUserController.java index 236581e..77ed1a6 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/system/SysUserController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/system/SysUserController.java @@ -269,4 +269,16 @@ public class SysUserController extends BaseController userService.updateUserInfo(sysUser); return AjaxResult.success("修改成功"); } + + /** + * 实名认证 + * @param sysUser + * @return + */ + @PostMapping("/updateIdCard") + public AjaxResult updateIdCard(@RequestBody SysUser sysUser){ + + return userService.updateIdCard(sysUser); + } + } diff --git a/mcwl-admin/src/main/java/com/mcwl/web/controller/system/WXController.java b/mcwl-admin/src/main/java/com/mcwl/web/controller/system/WXController.java index 199c60c..014be8a 100644 --- a/mcwl-admin/src/main/java/com/mcwl/web/controller/system/WXController.java +++ b/mcwl-admin/src/main/java/com/mcwl/web/controller/system/WXController.java @@ -14,12 +14,13 @@ import com.mcwl.system.domain.SysUserThirdAccount; import com.mcwl.system.service.ISysUserService; import com.mcwl.system.service.ISysUserThirdAccountService; import com.mcwl.system.service.IWXService; -import com.mcwl.web.controller.common.OssUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; import java.io.IOException; @@ -59,13 +60,6 @@ public class WXController { @Resource private SysPermissionService permissionService; - @Anonymous - @PostMapping("/test") - public AjaxResult test(@RequestParam MultipartFile file){ - - String s = OssUtil.uploadMultipartFile(file); - return AjaxResult.success(s); - } /** * 扫码登录用uuid生成 diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java new file mode 100644 index 0000000..202c209 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/Comment.java @@ -0,0 +1,53 @@ +//package com.mcwl.comment.domain; +// +//import com.baomidou.mybatisplus.annotation.TableId; +//import com.baomidou.mybatisplus.annotation.TableName; +//import com.mcwl.common.core.domain.BaseEntity; +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +///** +// * @Author:ChenYan +// * @Project:McWl +// * @Package:com.mcwl.comment.domain +// * @Filename:Comment +// * @Description 评论表 +// * @Date:2025/1/4 18:47 +// */ +//@AllArgsConstructor +//@NoArgsConstructor +//@Data +//@TableName("mall_product_comment") +//public class Comment extends BaseEntity { +// +// /** +// * ID +// */ +// @TableId +// private Long id; +// /** +// * 父评论ID +// */ +// private String parentId; +// /** +// * 商品ID +// */ +// private String productId; +// /** +// * 用户ID +// */ +// private String userId; +// /** +// * 评论内容 +// */ +// private String content; +// /** +// * 评分 +// */ +// private String rating; +// /** +// * 删除标志(0代表存在 2代表删除) +// */ +// private String delFlag; +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java new file mode 100644 index 0000000..e3c5832 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentConditionEntity.java @@ -0,0 +1,56 @@ +//package com.mcwl.comment.domain; +// +// +//import lombok.Data; +// +//import java.util.List; +// +///** +// * 商品评论查询条件实体 +// */ +//@Data +//public class ProductCommentConditionEntity extends RequestConditionEntity { +// +// /** +// * ID集合 +// */ +// private List idList; +// +// /** +// * ID +// */ +// private Long id; +// /** +// * 父评论ID +// */ +// private Long parentId; +// /** +// * 商品ID +// */ +// private Long productId; +// +// /** +// * 商品ID集合 +// */ +// private List productIdList; +// /** +// * 用户ID +// */ +// private Long userId; +// /** +// * 评论内容 +// */ +// private String content; +// /** +// * 评分 +// */ +// private Integer rating; +// /** +// * 删除标志(0代表存在 2代表删除) +// */ +// private String delFlag; +//// /** +//// * 评论类型 +//// */ +//// private Integer type; +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java new file mode 100644 index 0000000..ac099a7 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/ProductCommentEntity.java @@ -0,0 +1,50 @@ +//package com.mcwl.comment.domain; +// +//import com.mcwl.common.core.domain.BaseEntity; +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +///** +// * @Author:ChenYan +// * @Project:McWl +// * @Package:com.mcwl.comment.domain +// * @Filename:ProductCommentEntity +// * @Description 评论实体 +// * @Date:2025/1/6 13:21 +// */ +//@AllArgsConstructor +//@NoArgsConstructor +//@Data +//public class ProductCommentEntity extends BaseEntity { +// +// /** +// * 父评论ID +// */ +// private Long parentId; +// +// /** +// * 商品ID +// */ +// private Long productId; +// +// /** +// * 用户ID +// */ +// private Long userId; +// +// /** +// * 评论内容 +// */ +// private String content; +// +// /** +// * 评分 +// */ +// private Integer rating; +// +//// /** +//// * 评论类型 +//// */ +//// private Integer type; +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java new file mode 100644 index 0000000..0f3e740 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestConditionEntity.java @@ -0,0 +1,41 @@ +//package com.mcwl.comment.domain; +// +//import com.mcwl.common.utils.RequestPageEntity; +//import io.swagger.annotations.ApiModelProperty; +//import lombok.Data; +// +//import java.util.List; +// +///** +// * 请求条件实体 +// */ +//@Data +//public class RequestConditionEntity extends RequestPageEntity { +// +// +// /** +// * 创建日期范围 +// */ +// @ApiModelProperty("创建日期范围") +// private List betweenTime; +// +// /** +// * 创建开始时间 +// */ +// private String createBeginTime; +// +// /** +// * 创建结束时间 +// */ +// private String createEndTime; +// +// /** +// * 自定义excel表头列表 +// */ +// private List customizeColumnNameList; +// +// /** +// * 查询条件 +// */ +// private String blurry; +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java new file mode 100644 index 0000000..fff5643 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/domain/RequestPageEntity.java @@ -0,0 +1,72 @@ +//package com.mcwl.comment.domain; +// +//import cn.hutool.core.collection.CollectionUtil; +//import lombok.AllArgsConstructor; +//import lombok.Data; +//import lombok.NoArgsConstructor; +// +//import java.io.Serializable; +//import java.util.List; +//import java.util.Objects; +// +///** +// * 分页请求实体 +// */ +//@AllArgsConstructor +//@NoArgsConstructor +//@Data +//public class RequestPageEntity implements Serializable { +// +// private static final int DEFAULT_PAGE_SIZE = 10; +// +// /** +// * 页码,默认从一页开始 +// */ +// private Integer pageNo = 1; +// +// /** +// * 每页大小,默认一页查询10条数据 +// */ +// private Integer pageSize = DEFAULT_PAGE_SIZE; +// +// /** +// * 排序字段 +// */ +// private List sortField; +// +// +// /** +// * 获取分页开始位置 +// * +// * @return 分页开始位置 +// */ +// public Integer getPageBegin() { +// if (Objects.isNull(this.pageNo) || this.pageNo <= 0) { +// this.pageNo = 1; +// } +// +// if (Objects.isNull(this.pageSize)) { +// this.pageSize = DEFAULT_PAGE_SIZE; +// } +// +// return (this.pageNo - 1) * this.pageSize; +// } +// +// /** +// * 获取用户自定义排序集合 +// * +// * @return 排序集合实体 +// */ +// public String getSortString() { +// List sortField = this.getSortField(); +// if (CollectionUtil.isEmpty(sortField)) { +// return null; +// } +// StringBuilder sortBuilder = new StringBuilder(); +// for (String field : sortField) { +// String[] values = field.split(","); +// sortBuilder.append(String.format("%s %s", values[0], values[1])).append(","); +// } +// return sortBuilder.deleteCharAt(sortBuilder.length() - 1).toString(); +// } +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java b/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java new file mode 100644 index 0000000..79038a8 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/mapper/CommentMapper.java @@ -0,0 +1,31 @@ +//package com.mcwl.comment.mapper; +// +// +//import com.mcwl.comment.domain.ProductCommentConditionEntity; +//import com.mcwl.comment.domain.ProductCommentEntity; +//import com.mcwl.common.web.BaseMapper; +//import com.mcwl.resource.domain.MallProduct; +//import org.apache.ibatis.annotations.Param; +// +//import java.util.List; +// +///** +// * @Author:ChenYan +// * @Project:McWl +// * @Package:com.mcwl.comment.mapper +// * @Filename:CommentMapper +// * @Description TODO +// * @Date:2025/1/4 19:04 +// */ +//public interface CommentMapper extends BaseMapper { +// +// MallProduct findById(@Param("id") Long id); +// +// int insert(ProductCommentEntity productCommentEntity); +// +// int upda(ProductCommentEntity productCommentEntity); +// +// List findByIds(List ids); +// +// int deleteByIds(List ids, ProductCommentEntity productCommentEntity); +//} diff --git a/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java b/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java new file mode 100644 index 0000000..f3bae10 --- /dev/null +++ b/mcwl-comment/src/main/java/com/mcwl/comment/service/impl/CommentServiceImpl.java @@ -0,0 +1,88 @@ +//package com.mcwl.comment.service.impl; +// +// +//import com.mcwl.comment.domain.ProductCommentConditionEntity; +//import com.mcwl.comment.domain.ProductCommentEntity; +//import com.mcwl.comment.mapper.CommentMapper; +//import com.mcwl.common.core.domain.AjaxResult; +//import com.mcwl.common.utils.AssertUtil; +//import com.mcwl.common.utils.FillUserUtil; +//import com.mcwl.common.utils.ResponsePageEntity; +//import com.mcwl.common.utils.SecurityUtils; +//import com.mcwl.common.utils.bean.BaseService; +// +//import com.mcwl.common.web.BaseMapper; +//import com.mcwl.resource.domain.MallProduct; +//import org.springframework.beans.factory.annotation.Autowired; +//import org.springframework.stereotype.Service; +//import java.util.List; +//import java.util.Objects; +// +//import static com.mcwl.common.utils.SecurityUtils.getUsername; +// +///** +// * @Author:ChenYan +// * @Project:McWl +// * @Package:com.mcwl.comment.service.impl +// * @Filename:CommentServiceImpl +// * @Description TODO +// * @Date:2025/1/4 19:04 +// */ +//@Service +//public class CommentServiceImpl extends BaseService { +// +// @Autowired +// private CommentMapper commentMapper; +// +// +// public MallProduct findById(Long id) { +// return commentMapper.findById(id); +// } +// +// +// public int insert(ProductCommentEntity productCommentEntity) { +// // 获取当前用户 +// Long userId = SecurityUtils.getUserId(); +// productCommentEntity.setUserId(userId); +// productCommentEntity.setCreateBy(getUsername()); +// checkParam(productCommentEntity); +// return commentMapper.insert(productCommentEntity); +// } +// +// +// public int update(ProductCommentEntity productCommentEntity) { +// // 获取当前用户 +// Long userId = SecurityUtils.getUserId(); +// productCommentEntity.setUserId(userId); +// productCommentEntity.setUpdateBy(getUsername()); +// checkParam(productCommentEntity); +// return commentMapper.upda(productCommentEntity); +// } +// +// +// public int deleteByIds(List ids) { +// List entities = commentMapper.findByIds(ids); +// AssertUtil.notEmpty(entities, "商品评论已被删除"); +// +// ProductCommentEntity entity = new ProductCommentEntity(); +// FillUserUtil.fillUpdateUserInfo(entity); +// return commentMapper.deleteByIds(ids, entity); +// } +// private void checkParam(ProductCommentEntity productCommentEntity) { +// if (Objects.nonNull(productCommentEntity.getParentId()) && productCommentEntity.getParentId() > 0) { +// MallProduct productEntity = commentMapper.findById(productCommentEntity.getParentId()); +// AssertUtil.notNull(productEntity, "该父评论在系统中不存在"); +// } +// +// MallProduct userEntity = commentMapper.findById(productCommentEntity.getUserId()); +// AssertUtil.notNull(userEntity, "该用户在系统中不存在"); +// +// MallProduct productEntity = commentMapper.findById(productCommentEntity.getProductId()); +// AssertUtil.notNull(productEntity, "该商品在系统中不存在"); +// } +// +// @Override +// protected BaseMapper getBaseMapper() { +// return commentMapper; +// } +//} diff --git a/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml b/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml deleted file mode 100644 index a20b8f2..0000000 --- a/mcwl-comment/src/main/resources/mapper/comment/CommentMapper.xml +++ /dev/null @@ -1,57 +0,0 @@ - - - - - insert into mall_product_comment(id, parent_id, product_id, user_id, content, rating, create_by, create_time, - update_by, update_time, del_flag, remark) - values (#{id}, #{parentId}, #{productId}, #{userId}, #{content}, #{rating}, #{createBy}, #{createTime}, - #{updateBy}, #{updateTime}, #{remark}, #{delFlag}) - - - - - delete - from model - where id in - - #{id} - - - - - diff --git a/mcwl-common/pom.xml b/mcwl-common/pom.xml index 84f00c1..f56a827 100644 --- a/mcwl-common/pom.xml +++ b/mcwl-common/pom.xml @@ -341,7 +341,26 @@ 3.5.0 - + + + + + + + org.apache.httpcomponents + httpclient + 4.2.1 + + + org.apache.httpcomponents + httpcore + 4.2.1 + + + commons-lang + commons-lang + 2.6 + diff --git a/mcwl-common/src/main/java/com/mcwl/common/constant/CacheConstants.java b/mcwl-common/src/main/java/com/mcwl/common/constant/CacheConstants.java index aa05d09..8182e6b 100644 --- a/mcwl-common/src/main/java/com/mcwl/common/constant/CacheConstants.java +++ b/mcwl-common/src/main/java/com/mcwl/common/constant/CacheConstants.java @@ -47,5 +47,10 @@ public class CacheConstants */ public static final String WX_OPENID_KEY = "wx_openid:"; + /** + * 类型 + */ public static final String WE_CHAT = "we_chat"; + + public static final String ID_CARD_COUNT = "id_card_count:"; } diff --git a/mcwl-common/src/main/java/com/mcwl/common/core/domain/entity/SysUser.java b/mcwl-common/src/main/java/com/mcwl/common/core/domain/entity/SysUser.java index c949b91..1f39eeb 100644 --- a/mcwl-common/src/main/java/com/mcwl/common/core/domain/entity/SysUser.java +++ b/mcwl-common/src/main/java/com/mcwl/common/core/domain/entity/SysUser.java @@ -58,9 +58,6 @@ public class SysUser extends BaseEntity /** 密码 */ private String password; - /** 钱包 */ - private Long wallet; - /** 帐号状态(0正常 1停用) */ @Excel(name = "帐号状态", readConverterExp = "0=正常,1=停用") private String status; @@ -99,14 +96,14 @@ public class SysUser extends BaseEntity private String brief; /** - * 邀请人id + * 姓名 */ - private Long inviterUserId; + private String name; /** - * 免费用户积分 + * 身份证 */ - private Double freePoints; + private String idCard; public SysUser() { @@ -241,6 +238,22 @@ public class SysUser extends BaseEntity return delFlag; } + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getIdCard() { + return idCard; + } + + public void setIdCard(String idCard) { + this.idCard = idCard; + } + public void setDelFlag(String delFlag) { this.delFlag = delFlag; @@ -324,23 +337,6 @@ public class SysUser extends BaseEntity this.brief = brief; } - - public Long getInviterUserId() { - return inviterUserId; - } - - public void setInviterUserId(Long inviterUserId) { - this.inviterUserId = inviterUserId; - } - - public Double getFreePoints() { - return freePoints; - } - - public void setFreePoints(Double freePoints) { - this.freePoints = freePoints; - } - @Override public String toString() { return "SysUser{" + @@ -363,6 +359,8 @@ public class SysUser extends BaseEntity ", postIds=" + Arrays.toString(postIds) + ", roleId=" + roleId + ", brief='" + brief + '\'' + + ", name='" + name + '\'' + + ", idCard='" + idCard + '\'' + '}'; } } diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/HttpUtils.java b/mcwl-common/src/main/java/com/mcwl/common/utils/HttpUtils.java new file mode 100644 index 0000000..ee016fe --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/HttpUtils.java @@ -0,0 +1,328 @@ +package com.mcwl.common.utils; + +import org.apache.commons.lang.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; + + +/** + * 校验实名认证信息 + * @author DaiZibo + * @date 2025/1/8 + * @apiNote + */ + +public class HttpUtils { + + /** + * 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 headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpGet request = new HttpGet(buildUrl(host, path, querys)); + for (Map.Entry 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 headers, + Map querys, + Map bodys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + if (bodys != null) { + List nameValuePairList = new ArrayList(); + + 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 headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry 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 headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPost request = new HttpPost(buildUrl(host, path, querys)); + for (Map.Entry 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 headers, + Map querys, + String body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry 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 headers, + Map querys, + byte[] body) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpPut request = new HttpPut(buildUrl(host, path, querys)); + for (Map.Entry 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 headers, + Map querys) + throws Exception { + HttpClient httpClient = wrapClient(host); + + HttpDelete request = new HttpDelete(buildUrl(host, path, querys)); + for (Map.Entry e : headers.entrySet()) { + request.addHeader(e.getKey(), e.getValue()); + } + + return httpClient.execute(request); + } + + private static String buildUrl(String host, String path, Map 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 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); + } + } + +} diff --git a/mcwl-common/src/main/java/com/mcwl/common/utils/VerifyCard.java b/mcwl-common/src/main/java/com/mcwl/common/utils/VerifyCard.java new file mode 100644 index 0000000..916afef --- /dev/null +++ b/mcwl-common/src/main/java/com/mcwl/common/utils/VerifyCard.java @@ -0,0 +1,55 @@ +package com.mcwl.common.utils; + +import org.apache.http.HttpResponse; +import org.apache.http.util.EntityUtils; + +import java.util.HashMap; +import java.util.Map; + +/** + * 身份证校验 + * + * @author DaiZibo + * @date 2025/1/8 + * @apiNote + */ +public class VerifyCard { + + public static String idCard(String name, String card) { + String host = "https://kzidcardv1.market.alicloudapi.com"; + String path = "/api-mall/api/id_card/check"; + String method = "POST"; + String appcode = "680661d47eb740bcb85472cec9774ecf"; + Map headers = new HashMap(); + //最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105 + headers.put("Authorization", "APPCODE " + appcode); + //根据API的要求,定义相对应的Content-Type + headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); + Map querys = new HashMap(); + Map bodys = new HashMap(); + bodys.put("name", name); + bodys.put("idcard", card); + + + try { + /** + * 重要提示如下: + * HttpUtils请从 + * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java + * 下载 + * + * 相应的依赖请参照 + * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml + */ + HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys); + System.out.println(response.toString()); + //获取response的body + //System.out.println(EntityUtils.toString(response.getEntity())); + return EntityUtils.toString(response.getEntity()); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + +} diff --git a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java index 4de0d65..5971fea 100644 --- a/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java +++ b/mcwl-resource/src/main/java/com/mcwl/resource/service/impl/SysUserAttentionServiceImpl.java @@ -71,9 +71,8 @@ public class SysUserAttentionServiceImpl implements SysUserAttentionService { public SysUserInfo selectUserInfo() { Long userId = SecurityUtils.getUserId(); - return SysUserInfo.builder().bean(sysUserAttentionMapper.selectBean(userId)) - .download(mallProductMapper.sumNumber(userId)) +// .download(mallProductMapper.sumNumber(userId)) .likeCount(mallProductLikeMapper.countLike(userId)) .attention(sysUserAttentionMapper.selectAttentionCount(userId)).build(); } diff --git a/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java b/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java index a866592..79bd9be 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java +++ b/mcwl-system/src/main/java/com/mcwl/system/mapper/SysUserMapper.java @@ -1,6 +1,5 @@ package com.mcwl.system.mapper; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.mcwl.common.core.domain.entity.SysUser; import org.apache.ibatis.annotations.Param; @@ -133,5 +132,8 @@ public interface SysUserMapper SysUser selectUserInfoById(@Param("userId") Long userId); + void updateIdCard(SysUser sysUser); + + SysUser selectByIdCard(@Param("idCard") String idCard); } diff --git a/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java b/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java index f3df3e2..3af1402 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java +++ b/mcwl-system/src/main/java/com/mcwl/system/service/ISysUserService.java @@ -1,5 +1,6 @@ package com.mcwl.system.service; +import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.entity.SysUser; import java.util.List; @@ -213,4 +214,5 @@ public interface ISysUserService SysUser selectUserInfoById(Long userId); + AjaxResult updateIdCard(SysUser sysUser); } diff --git a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java index c9ab419..9cd5a26 100644 --- a/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java +++ b/mcwl-system/src/main/java/com/mcwl/system/service/impl/SysUserServiceImpl.java @@ -1,13 +1,17 @@ package com.mcwl.system.service.impl; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.alibaba.fastjson2.JSONObject; import com.mcwl.common.annotation.DataScope; +import com.mcwl.common.constant.CacheConstants; import com.mcwl.common.constant.UserConstants; +import com.mcwl.common.core.domain.AjaxResult; import com.mcwl.common.core.domain.entity.SysRole; import com.mcwl.common.core.domain.entity.SysUser; +import com.mcwl.common.core.redis.RedisCache; import com.mcwl.common.exception.ServiceException; import com.mcwl.common.utils.SecurityUtils; import com.mcwl.common.utils.StringUtils; +import com.mcwl.common.utils.VerifyCard; import com.mcwl.common.utils.bean.BeanValidators; import com.mcwl.common.utils.spring.SpringUtils; import com.mcwl.system.domain.SysPost; @@ -30,6 +34,7 @@ import javax.validation.Validator; import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -42,6 +47,9 @@ public class SysUserServiceImpl implements ISysUserService { private static final Logger log = LoggerFactory.getLogger(SysUserServiceImpl.class); + @Autowired + private RedisCache redisCache; + @Autowired private SysUserMapper userMapper; @@ -600,6 +608,47 @@ public class SysUserServiceImpl implements ISysUserService return userMapper.selectUserInfoById(userId); } + @Override + public AjaxResult updateIdCard(SysUser sysUser) { + + //获取次数 + Integer s = redisCache.getCacheObject(CacheConstants.ID_CARD_COUNT + sysUser.getUserId()); + Integer count = 0; + if (s != null){ + + if (3<=s){ + + return AjaxResult.error("次数上限"); + }else { + //次数+1 + s++; + count = s; + } + } + + //存入次数 + redisCache.setCacheObject(CacheConstants.ID_CARD_COUNT+sysUser.getUserId(),count,1, TimeUnit.DAYS); + + //查看身份证是否唯一 + SysUser user = userMapper.selectByIdCard(sysUser.getIdCard()); + if (user != null){ + return AjaxResult.error("该信息已绑定"); + } + //校验 + String s1 = VerifyCard.idCard(sysUser.getName(), sysUser.getIdCard()); + JSONObject jsonObject = JSONObject.parseObject(s1); + Integer code = jsonObject.getInteger("code"); + if (code != 200){ + + return AjaxResult.error(jsonObject.getString("msg")); + } + log.info("实名认证校验的结果:{}",s1); + //修改数据库 + userMapper.updateIdCard(sysUser); + + return AjaxResult.success("实名认证成功"); + } + /** * 生成随机密码 * @param length @@ -618,5 +667,4 @@ public class SysUserServiceImpl implements ISysUserService return sb.toString(); } - } diff --git a/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml b/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml index febf895..2b41535 100644 --- a/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml +++ b/mcwl-system/src/main/resources/mapper/system/SysUserMapper.xml @@ -150,7 +150,10 @@ + @@ -226,7 +229,13 @@ where user_id = #{userId} - + + update sys_user set name = #{name}, + id_card = #{idCard} + where user_id = #{userId} + + + update sys_user set del_flag = '2' where user_id = #{userId}