| @@ -1,13 +1,7 @@ | |||
| package com.simple.config; | |||
| import java.util.HashMap; | |||
| import java.util.LinkedHashMap; | |||
| import java.util.Map; | |||
| import javax.servlet.ServletRequest; | |||
| import javax.servlet.ServletResponse; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import com.simple.service.MallPermissionService; | |||
| import com.simple.shiro.MyShiroRealm; | |||
| import org.apache.shiro.authc.credential.HashedCredentialsMatcher; | |||
| import org.apache.shiro.mgt.SecurityManager; | |||
| import org.apache.shiro.spring.LifecycleBeanPostProcessor; | |||
| @@ -24,10 +18,11 @@ import org.springframework.beans.factory.annotation.Value; | |||
| import org.springframework.context.annotation.Bean; | |||
| import org.springframework.context.annotation.Configuration; | |||
| import com.simple.service.MallPermissionService; | |||
| import com.simple.shiro.MyShiroRealm; | |||
| import javax.servlet.Filter; | |||
| import javax.servlet.ServletRequest; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.util.LinkedHashMap; | |||
| import java.util.Map; | |||
| /** | |||
| @@ -127,6 +122,8 @@ public class ShiroConfig { | |||
| filterChainDefinitionMap.put("/**", "corsFilter,token,authc"); | |||
| // filterChainDefinitionMap.put("/**", "anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/add","anon"); | |||
| filterChainDefinitionMap.put("/wxMallApply/sendvalidationcode","anon"); | |||
| shiroFilterFactoryBean.setFilterChainDefinitionMap(filterChainDefinitionMap); | |||
| return shiroFilterFactoryBean; | |||
| @@ -0,0 +1,75 @@ | |||
| package com.simple.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMallApply; | |||
| import com.simple.domain.po.WxMsgValidationcode; | |||
| import com.simple.service.WxMallApplyService; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import org.apache.log4j.Logger; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| @RestController | |||
| @RequestMapping("wxMallApply") | |||
| public class WxMallApplyController extends BaseController | |||
| { | |||
| @Autowired | |||
| private WxMallApplyService wxMallApplyService; | |||
| private Logger logger = Logger.getLogger(WxMallApplyController.class); | |||
| @GetMapping("list") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||
| public ResultData list(@ModelAttribute WxMallApply wxMallApply,Integer pageNum, Integer pageSize) { | |||
| if (null == wxMallApply) wxMallApply = new WxMallApply(); | |||
| final PageInfo<WxMallApply> page = wxMallApplyService.listAsPage(wxMallApply, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @PostMapping("add") | |||
| public ResultData add(@RequestBody WxMallApply wxMallApply) { | |||
| //Assert.notNull(wxMallApply.getName(), "角色名不能为空"); | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| wxMallApplyService.saveOrUpdate(wxMallApply); | |||
| return new ResultData(); | |||
| } | |||
| @PostMapping("update") | |||
| public ResultData update(@RequestBody WxMallApply wxMallApply) { | |||
| wxMallApplyService.saveOrUpdate(wxMallApply); | |||
| return new ResultData(); | |||
| } | |||
| @GetMapping("/del") | |||
| @ApiImplicitParam(name="id",value="id",dataType="String", paramType = "query",required=true) | |||
| public ResultData delete(String id) { | |||
| wxMallApplyService.deleteById(id); | |||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||
| } | |||
| @GetMapping("/findById") | |||
| @ApiImplicitParam(name="id",value="id",dataType="String", paramType = "query",required=true) | |||
| public ResultData findById(String id) { | |||
| return new ResultData(Result.SUCCESS,"查询成功",wxMallApplyService.getById(id)); | |||
| } | |||
| @GetMapping("sendvalidationcode") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true)}) | |||
| public ResultData sendvalidationcode(String phone, Integer type) { | |||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||
| wxMsgValidationcode.setTenantId("1"); | |||
| wxMsgValidationcode.setPhone(phone); | |||
| wxMsgValidationcode.setType(type); | |||
| return wxMallApplyService.sendvalidationcode(wxMsgValidationcode); | |||
| } | |||
| } | |||
| @@ -0,0 +1,139 @@ | |||
| package com.simple.domain.po; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_mall_apply") | |||
| public class WxMallApply implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<String> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<String> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<String> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /*购物中心名称**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="购物中心名称",name="mallName") | |||
| private String mallName; | |||
| /*联系人姓名**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="联系人姓名",name="applicant") | |||
| private String applicant; | |||
| /***/ | |||
| @io.swagger.annotations.ApiModelProperty(value="",name="phone") | |||
| private String phone; | |||
| /*申请时间**/ | |||
| @io.swagger.annotations.ApiModelProperty(value="申请时间",name="applyDate") | |||
| private Date applyDate; | |||
| public String getMallName() { | |||
| return mallName; | |||
| } | |||
| public void setMallName(String _mallName) { | |||
| mallName = _mallName; | |||
| } | |||
| public String getApplicant() { | |||
| return applicant; | |||
| } | |||
| public void setApplicant(String _applicant) { | |||
| applicant = _applicant; | |||
| } | |||
| public String getPhone() { | |||
| return phone; | |||
| } | |||
| public void setPhone(String _phone) { | |||
| phone = _phone; | |||
| } | |||
| public Date getApplyDate() { | |||
| return applyDate; | |||
| } | |||
| public void setApplyDate(Date _applyDate) { | |||
| applyDate = _applyDate; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,MallName_ASC("`mall_name` ASC"),MallName_DESC("`mall_name` DESC") | |||
| ,Applicant_ASC("`applicant` ASC"),Applicant_DESC("`applicant` DESC") | |||
| ,Phone_ASC("`phone` ASC"),Phone_DESC("`phone` DESC") | |||
| ,ApplyDate_ASC("`apply_date` ASC"),ApplyDate_DESC("`apply_date` DESC") | |||
| ; | |||
| private String value; | |||
| Field(String value){ | |||
| this.value = value; | |||
| } | |||
| public String getValue() { | |||
| return value; | |||
| } | |||
| public void setCol(String value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return this.getValue(); | |||
| } | |||
| } | |||
| public void setSortColumns(Field... fields) | |||
| { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| } | |||
| for (int k = 0; k < fields.length; k++) { | |||
| if (fields[k] == null) { | |||
| return; | |||
| } | |||
| } | |||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||
| for (int k = 1; k < fields.length; k++) { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| this.sortColumns=sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) | |||
| { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| List<Field> fList = new ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(Field.valueOf(cols[k])); | |||
| } | |||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||
| } else { | |||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,17 @@ | |||
| package com.simple.mapper; | |||
| import com.simple.common.CommonMapper; | |||
| import com.simple.domain.po.WxMallApply; | |||
| import java.util.List; | |||
| public interface WxMallApplyMapper extends CommonMapper<WxMallApply, String> { | |||
| List<WxMallApply> findList(WxMallApply wxMallApply); | |||
| } | |||
| @@ -0,0 +1,45 @@ | |||
| package com.simple.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMallApply; | |||
| import com.simple.domain.po.WxMsgValidationcode; | |||
| public interface WxMallApplyService { | |||
| /** | |||
| * 根据实体查询分页列表 | |||
| * | |||
| * @param record | |||
| * @param offset | |||
| * @param limit | |||
| * @return | |||
| */ | |||
| PageInfo<WxMallApply> listAsPage(WxMallApply record, Integer pageIndex, Integer pageSize); | |||
| /** | |||
| * 根据Id获得实体 | |||
| * | |||
| * @param id | |||
| * @return | |||
| */ | |||
| WxMallApply getById(String id); | |||
| /** | |||
| * 保存或更新实体 | |||
| * | |||
| * @param record | |||
| */ | |||
| void saveOrUpdate(WxMallApply record); | |||
| /** | |||
| * 根据Id删除实体 | |||
| * | |||
| * @param id | |||
| */ | |||
| void deleteById(String id); | |||
| ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode); | |||
| } | |||
| @@ -0,0 +1,163 @@ | |||
| package com.simple.service.impl; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.simple.common.ErrorCode; | |||
| import com.simple.common.IdWorker; | |||
| import com.simple.common.Result; | |||
| import com.simple.common.ResultData; | |||
| import com.simple.domain.po.WxMallApply; | |||
| import com.simple.domain.po.WxMsgConfig; | |||
| import com.simple.domain.po.WxMsgValidationcode; | |||
| import com.simple.domain.po.WxMsgValidationcodeModel; | |||
| import com.simple.mapper.WxMallApplyMapper; | |||
| import com.simple.mapper.WxMsgConfigMapper; | |||
| import com.simple.mapper.WxMsgValidationcodeMapper; | |||
| import com.simple.mapper.WxMsgValidationcodeModelMapper; | |||
| import com.simple.service.WxMallApplyService; | |||
| import com.simple.utils.AesUtil; | |||
| import com.simple.utils.HMACSHA256; | |||
| import com.simple.utils.HttpUtil; | |||
| import com.simple.utils.RsaUtil; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.*; | |||
| import java.util.stream.Collectors; | |||
| @Service | |||
| public class WxMallApplyServiceImpl implements WxMallApplyService { | |||
| @Autowired | |||
| WxMallApplyMapper wxMallApplyMapper; | |||
| @Autowired | |||
| WxMsgValidationcodeMapper wxMsgValidationcodeMapper; | |||
| @Autowired | |||
| WxMsgConfigMapper wxMsgConfigMapper; | |||
| @Autowired | |||
| WxMsgValidationcodeModelMapper wxMsgValidationcodeModelMapper; | |||
| @Override | |||
| public PageInfo<WxMallApply> listAsPage(WxMallApply record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxMallApplyMapper.findList(record)); | |||
| } | |||
| @Override | |||
| public WxMallApply getById(String id) { | |||
| return wxMallApplyMapper.selectByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void saveOrUpdate(WxMallApply record) { | |||
| if (record.getId() == null) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| record.setId(idWorker.nextId()); | |||
| wxMallApplyMapper.insertSelective(record); | |||
| } else { | |||
| wxMallApplyMapper.updateByPrimaryKeySelective(record); | |||
| } | |||
| } | |||
| @Override | |||
| public void deleteById(String id) { | |||
| wxMallApplyMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode) { | |||
| //1、查看是否存在未过期的短信,有返回成功 没有继续 | |||
| List<WxMsgValidationcode> wxmsgvalidationcodelist = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); | |||
| Date currentdate = new Date(); | |||
| wxmsgvalidationcodelist = wxmsgvalidationcodelist.stream().filter(validationcode -> | |||
| validationcode.getExpiretime().after(currentdate)).collect(Collectors.toList()); | |||
| if(wxmsgvalidationcodelist.size()>0) return new ResultData(ErrorCode.MSG_REPEAT_SEND.getCode(),ErrorCode.MSG_REPEAT_SEND.getMessage()); | |||
| //3、从短信配置中查询密钥 bid 等信息 | |||
| WxMsgConfig wxMsgConfig = new WxMsgConfig(); | |||
| wxMsgConfig.setTenantId(wxMsgValidationcode.getTenantId()); | |||
| List<WxMsgConfig> wxMsgConfigs = wxMsgConfigMapper.findList(wxMsgConfig); | |||
| if (wxMsgConfigs.size() == 0) new ResultData(500,"发送失败"); | |||
| wxMsgConfig = wxMsgConfigs.get(0); | |||
| WxMsgValidationcodeModel wxMsgValidationcodeModel = new WxMsgValidationcodeModel(); | |||
| wxMsgValidationcodeModel.setTenantId(wxMsgConfig.getTenantId()); | |||
| wxMsgValidationcodeModel.setType(wxMsgValidationcode.getType()); | |||
| wxMsgValidationcodeModel = wxMsgValidationcodeModelMapper.findList(wxMsgValidationcodeModel).get(0); | |||
| wxMsgValidationcode.setSignature(wxMsgValidationcodeModel.getSignature()); | |||
| String secret = wxMsgConfig.getSecret(); | |||
| String bid = wxMsgConfig.getBid(); | |||
| String publickey = wxMsgConfig.getPublickey(); | |||
| //验证码 | |||
| int code = (int) ((Math.random() * 9 + 1) * 100000); | |||
| String phone = wxMsgValidationcode.getPhone(); | |||
| String signature = wxMsgValidationcode.getSignature(); | |||
| //内容 | |||
| String msg = wxMsgValidationcodeModel.getContent().replace("{s6}", String.valueOf(code)); | |||
| wxMsgValidationcode.setCode(String.valueOf(code)); | |||
| wxMsgValidationcode.setMsg(msg); | |||
| String notifyUrl = wxMsgConfig.getNotifyurl(); | |||
| TreeMap<String, String> message = new TreeMap<>(); | |||
| message.put("bid", bid); | |||
| message.put("phone", phone); | |||
| message.put("signature", signature); | |||
| message.put("msg", msg); | |||
| message.put("notify_url", notifyUrl); | |||
| message.put("verifysms","1"); | |||
| StringBuilder sb = new StringBuilder(); | |||
| Set<Map.Entry<String, String>> entries = message.entrySet(); | |||
| for (Map.Entry<String, String> entry : entries) { | |||
| sb.append(entry.getKey()).append("=").append(entry.getValue()); | |||
| } | |||
| sb.append("&secret=").append(secret); | |||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | |||
| message.put("sign", sign.toUpperCase()); | |||
| String str32 = HMACSHA256.STR2; | |||
| String iv = HMACSHA256.IV; | |||
| Map<String, String> params = new HashMap<>(); | |||
| params.put("iv", iv); | |||
| params.put("bid", bid); | |||
| try { | |||
| String data = AesUtil.AESEncode(str32, JSONObject.toJSONString(message), iv); | |||
| String sc = RsaUtil.RSAEncode(str32.getBytes(), publickey); | |||
| params.put("data", data); | |||
| params.put("sc", sc); | |||
| } catch (Exception e) { | |||
| throw new RuntimeException("发送失败"); | |||
| } | |||
| String requestUrl = "https://webapp.wiwide.com/apisms/send"; | |||
| String result = HttpUtil.doPost(requestUrl, params); | |||
| JSONObject jsonObjectResult = JSONObject.parseObject(result); | |||
| String ret = jsonObjectResult.get("ret").toString(); | |||
| if (ret.equals("1")) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| wxMsgValidationcode.setId(idWorker.nextId()); | |||
| long currentTime = System.currentTimeMillis() ; | |||
| Date createtime=new Date(currentTime); | |||
| Integer minutes = wxMsgValidationcodeModel.getMinutes(); | |||
| currentTime +=minutes*60*1000; | |||
| Date expiredate=new Date(currentTime); | |||
| wxMsgValidationcode.setExpiretime(expiredate); | |||
| wxMsgValidationcode.setCreatetime(createtime); | |||
| wxMsgValidationcodeMapper.insertSelective(wxMsgValidationcode); | |||
| return new ResultData(Result.SUCCESS,"发送成功"); | |||
| } | |||
| return new ResultData(500,"发送失败"); | |||
| } | |||
| } | |||
| @@ -0,0 +1,42 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.simple.mapper.WxMallApplyMapper"> | |||
| <resultMap id="BaseResultMap" type="com.simple.domain.po.WxMallApply"> | |||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||
| <result column="mall_name" jdbcType="VARCHAR" property="mallName" /> | |||
| <result column="applicant" jdbcType="VARCHAR" property="applicant" /> | |||
| <result column="phone" jdbcType="VARCHAR" property="phone" /> | |||
| <result column="apply_date" jdbcType="TIMESTAMP" property="applyDate" /> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`mall_name`,`applicant`,`phone`,`apply_date` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> and `id` = #{id} </if> | |||
| <if test=" null != mallName "> and `mall_name` = #{mallName} </if> | |||
| <if test=" null != applicant "> and `applicant` = #{applicant} </if> | |||
| <if test=" null != phone "> and `phone` = #{phone} </if> | |||
| <if test=" null != applyDate "> and `apply_date` = #{applyDate} </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.simple.domain.po.WxMallApply" resultMap="BaseResultMap"> | |||
| select <include refid="allColumns" /> from wx_mall_apply | |||
| <include refid="dynamicWhereConditions" /> | |||
| </select> | |||
| </mapper> | |||