| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package net.mingsoft.tf.wx;
- import cn.hutool.core.util.RandomUtil;
- import cn.hutool.http.HttpUtil;
- import cn.hutool.json.JSONObject;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.Parameter;
- import io.swagger.v3.oas.annotations.Parameters;
- import io.swagger.v3.oas.annotations.enums.ParameterIn;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import jakarta.servlet.http.HttpServletRequest;
- import jakarta.servlet.http.HttpServletResponse;
- import net.mingsoft.base.entity.ResultData;
- import net.mingsoft.base.exception.BusinessException;
- import net.mingsoft.mdiy.action.ModelAction;
- import net.mingsoft.people.action.BaseAction;
- import net.mingsoft.people.action.people.PeopleUserAction;
- import net.mingsoft.people.action.web.PeopleAction;
- import net.mingsoft.people.bean.PeopleBean;
- import net.mingsoft.people.biz.IPeopleBiz;
- import net.mingsoft.people.entity.PeopleEntity;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.shiro.SecurityUtils;
- import org.apache.shiro.subject.Subject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.PostMapping;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.ResponseBody;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Optional;
- @Tag(name = "前端-微信-会员模块接口")
- @Controller
- public class WxPeopleAction extends BaseAction {
- @Autowired
- private IPeopleBiz peopleBiz;
- @Autowired
- private PeopleUserAction peopleUserAction;
- @Autowired
- private PeopleAction peopleAction;
- @Autowired
- private ModelAction modelAction;
- @Operation(summary = "微信-获得电话号码")
- @Parameters({
- @Parameter(name = "code", description = "code", required = true, in = ParameterIn.QUERY)
- })
- @PostMapping(value = "/wx/phone")
- @ResponseBody
- public ResultData wxGetPhone(String code) {
- // TODO
- return null;
- }
- @Operation(summary = "微信-登录")
- @Parameters({
- @Parameter(name = "code", description = "code", required = true, in = ParameterIn.QUERY)
- })
- @PostMapping(value = "/wx/login")
- @ResponseBody
- public ResultData wxCheckLogin(String code, HttpServletRequest request, HttpServletResponse response) {
- return Optional.ofNullable(code)
- .map(c -> "https://api.weixin.qq.com/sns/jscode2session?appid=wx0a115eb69d6e9359&secret=d906c8ca51acfd61e13dd61b62364050&js_code=" + c + "&grant_type=authorization_code")
- .map(HttpUtil::get)
- .map(JSONObject::new)
- .map(json -> json.getStr("openid"))
- .filter(StringUtils::isNotBlank)
- .map(openid -> {
- Map<String, Object> map = new HashMap<>();
- map.put("openid", openid);
- PeopleEntity user = this.peopleBiz.getEntityByUserName(openid);
- if (user != null) {
- ResultData login = executeLogin(openid, request, response);
- if (login.isSuccess()) {
- map.putAll(login.getData(Map.class));
- }
- }
- return ResultData.build().success(map);
- })
- .orElse(ResultData.build().error("登录失败"));
- }
- @Operation(summary = "微信-用户注册")
- @Parameters({
- @Parameter(name = "peopleName", description = "openid", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "puIcon", description = "微信头像", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "puNickname", description = "微信昵称", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "puRealName", description = "真实姓名", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "peoplePhone", description = "手机号", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "puCard", description = "身份证", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "公司名称", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "职位", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "展商邀请码", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "身份类型", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "了解渠道", required = true, in = ParameterIn.QUERY),
- @Parameter(name = "", description = "参观目的", required = true, in = ParameterIn.QUERY),
- })
- @PostMapping(value = "/wx/register")
- @ResponseBody
- public ResultData wxRegister(@RequestBody PeopleBean people, HttpServletRequest request, HttpServletResponse response) {
- people.setPeoplePassword(RandomUtil.randomString(8));
- // TODO 7个新字段保存,还有一个邀请用户ID
- ResultData register = peopleAction.register(people, request, response);
- if (register.isSuccess()) {
- return executeLogin(people.getPeopleName(), request, response);
- }
- return register;
- }
- private ResultData executeLogin(String openid, HttpServletRequest request, HttpServletResponse response) {
- Subject subject = SecurityUtils.getSubject();
- WxCustomUserNamePasswordToken cupt = new WxCustomUserNamePasswordToken(openid);
- try {
- LOG.debug("people 尝试登陆");
- subject.login(cupt);
- LOG.debug("people 登陆成功");
- ResultData info = peopleUserAction.info(request, response);
- if (info.isSuccess()) {
- Map<String, Object> data = info.getData(Map.class);
- PeopleBean tempPeople = new PeopleBean();
- // TODO
- // tempPeople.setId(peopleEntity.getId());
- // tempPeople.setPeopleName(peopleEntity.getPeopleName());
- // tempPeople.setPeoplePhone(peopleEntity.getPeoplePhone());
- // tempPeople.setPuIcon(peopleEntity.getPuIcon());
- // tempPeople.setPuNickname(peopleEntity.getPuNickname());
- return ResultData.build().success(tempPeople);
- }
- return info;
- } catch (Exception e) {
- LOG.debug("people 登陆失败");
- if (e.getCause() instanceof BusinessException) {
- throw (BusinessException) e.getCause();
- }
- e.printStackTrace();
- }
- return ResultData.build().error(
- this.getResString("err.error", this.getResString("people.no.exist")));
- }
- @Operation(summary = "微信-邀请的用户汇总")
- @PostMapping(value = "/people/invitation/summary")
- @ResponseBody
- public ResultData invitationSummary() {
- // TODO
- return null;
- }
- @Operation(summary = "微信-邀请的用户明细")
- @PostMapping(value = "/people/invitation/details")
- @ResponseBody
- public ResultData invitationDetails() {
- // TODO
- return null;
- }
- @Operation(summary = "微信-生成入场二维码")
- @PostMapping(value = "/people/qrcode")
- @ResponseBody
- public ResultData qrcode() {
- // TODO
- return null;
- }
- @Operation(summary = "微信-展商-上传LOGO")
- @PostMapping(value = "/people/upload/logo")
- @ResponseBody
- public ResultData logo() {
- // TODO
- return null;
- }
- @Operation(summary = "微信-展商-申请")
- @PostMapping(value = "/people/exhibitor/create")
- @ResponseBody
- public ResultData exhibitorCreate() {
- // TODO
- return null;
- }
- @Operation(summary = "微信-展商-详情")
- @PostMapping(value = "/people/exhibitor/info")
- @ResponseBody
- public ResultData exhibitorInfo() {
- // TODO
- return null;
- }
- }
|