package cn.huge.module.pauser.controller.wechat; import cn.huge.base.common.utils.ReturnFailUtils; import cn.huge.base.common.utils.ReturnSucUtils; import cn.huge.module.pauser.dto.WeChatEmpowerDTO; import cn.huge.module.pauser.service.PaAccountService; import com.google.common.collect.Maps; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; import java.util.Map; /** * @title: 公众用户账号表接口api-wechat端 * @description: 公众用户账号表接口api-wechat端 * @company: hugeinfo */ @Slf4j @RestController @RequestMapping("/api/wechat/paAccount") public class PaAccountWechatController { @Autowired(required = false) private HttpServletRequest request; @Autowired private PaAccountService service; /** * 获取请求URL参数 * @return Map */ private Map getParameter(){ Map terms = Maps.newHashMap(); // 账号编号 String id = request.getParameter("id"); if (StringUtils.isNotBlank(id)){ terms.put("id", id); } // 当事人编号 String userId = request.getParameter("userId"); if (StringUtils.isNotBlank(userId)){ terms.put("userId", userId); } // 帐号类型,1:平台web端,2:平台小程序 String accType = request.getParameter("accType"); if (StringUtils.isNotBlank(accType)){ terms.put("accType", accType); } // 身份唯一标识(存储唯一标识,比如账号、邮箱、手机号、第三方获取的唯一标识等) String acc = request.getParameter("acc"); if (StringUtils.isNotBlank(acc)){ terms.put("acc", acc); } // 授权凭证(比如密码 、第三方登录的token、授权账号等) String cipher = request.getParameter("cipher"); if (StringUtils.isNotBlank(cipher)){ terms.put("cipher", cipher); } // 授权凭证明文 String cipherOpen = request.getParameter("cipherOpen"); if (StringUtils.isNotBlank(cipherOpen)){ terms.put("cipherOpen", cipherOpen); } // 密码最新更新时间 String cipherTime = request.getParameter("cipherTime"); if (StringUtils.isNotBlank(cipherTime)){ terms.put("cipherTime", cipherTime); } // 最新登录时间 String loginTime = request.getParameter("loginTime"); if (StringUtils.isNotBlank(loginTime)){ terms.put("loginTime", loginTime); } // 限制登录时间(密码错误次数超过限制,默认30分钟) String limitTime = request.getParameter("limitTime"); if (StringUtils.isNotBlank(limitTime)){ terms.put("limitTime", limitTime); } // 删除状态,0:未删除,1:已删除 String deleteStatus = request.getParameter("deleteStatus"); if (StringUtils.isNotBlank(deleteStatus)){ terms.put("deleteStatus", deleteStatus); } // 客户编号 String custId = request.getParameter("custId"); if (StringUtils.isNotBlank(custId)){ terms.put("custId", custId); } // 创建时间区间 String createStart = request.getParameter("createStart"); String createEnd = request.getParameter("createEnd"); if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) { terms.put("createStart", createStart); terms.put("createEnd", createEnd); } // 更新时间区间 String updateStart = request.getParameter("updateStart"); String updateEnd = request.getParameter("updateEnd"); if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) { terms.put("updateStart", updateStart); terms.put("updateEnd", updateEnd); } return terms; } /** * 当事人小程序-微信用户授权 * url: {ctx}/api/weChat/paAccount/empower * type: post */ @PostMapping(value = "/empower") public Object empower(@RequestBody WeChatEmpowerDTO weChatEmpowerDTO) { if (StringUtils.isBlank(weChatEmpowerDTO.getCode())) { return ReturnSucUtils.getRepInfo("code不能为空!"); } try { return ReturnSucUtils.getRepInfo(service.wechatEmpower(weChatEmpowerDTO)); } catch (Exception e) { log.error("Controller接口[PaAccountWechatController.empower]请求异常:"+e, e); return ReturnFailUtils.getRepInfo(e.getMessage()); } } /** * 当事人小程序-微信用户授权获取手机号码 * url: {ctx}/api/wechat/paAccount/getUserPhone * type: post */ @PostMapping(value = "/getUserPhone") public Object getUserPhone(@RequestBody WeChatEmpowerDTO weChatEmpowerDTO) { if (StringUtils.isBlank(weChatEmpowerDTO.getCode())) { return ReturnSucUtils.getRepInfo("code不能为空!"); } try { return ReturnSucUtils.getRepInfo(service.wechatGetPhone(weChatEmpowerDTO)); } catch (Exception e) { log.error("Controller接口[WeChatPaAccountController.wechatGetPhone]请求异常:"+e, e); return ReturnFailUtils.getRepInfo(e.getMessage()); } } }