WxPeopleAction.java 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. package net.mingsoft.tf.wx;
  2. import cn.hutool.core.util.RandomUtil;
  3. import cn.hutool.http.HttpUtil;
  4. import cn.hutool.json.JSONObject;
  5. import io.swagger.v3.oas.annotations.Operation;
  6. import io.swagger.v3.oas.annotations.Parameter;
  7. import io.swagger.v3.oas.annotations.Parameters;
  8. import io.swagger.v3.oas.annotations.enums.ParameterIn;
  9. import io.swagger.v3.oas.annotations.tags.Tag;
  10. import jakarta.servlet.http.HttpServletRequest;
  11. import jakarta.servlet.http.HttpServletResponse;
  12. import net.mingsoft.base.entity.ResultData;
  13. import net.mingsoft.base.exception.BusinessException;
  14. import net.mingsoft.mdiy.action.ModelAction;
  15. import net.mingsoft.people.action.BaseAction;
  16. import net.mingsoft.people.action.people.PeopleUserAction;
  17. import net.mingsoft.people.action.web.PeopleAction;
  18. import net.mingsoft.people.bean.PeopleBean;
  19. import net.mingsoft.people.biz.IPeopleBiz;
  20. import net.mingsoft.people.entity.PeopleEntity;
  21. import org.apache.commons.lang3.StringUtils;
  22. import org.apache.shiro.SecurityUtils;
  23. import org.apache.shiro.subject.Subject;
  24. import org.springframework.beans.factory.annotation.Autowired;
  25. import org.springframework.stereotype.Controller;
  26. import org.springframework.web.bind.annotation.PostMapping;
  27. import org.springframework.web.bind.annotation.RequestBody;
  28. import org.springframework.web.bind.annotation.ResponseBody;
  29. import java.util.HashMap;
  30. import java.util.Map;
  31. import java.util.Optional;
  32. @Tag(name = "前端-微信-会员模块接口")
  33. @Controller
  34. public class WxPeopleAction extends BaseAction {
  35. @Autowired
  36. private IPeopleBiz peopleBiz;
  37. @Autowired
  38. private PeopleUserAction peopleUserAction;
  39. @Autowired
  40. private PeopleAction peopleAction;
  41. @Autowired
  42. private ModelAction modelAction;
  43. @Operation(summary = "微信-获得电话号码")
  44. @Parameters({
  45. @Parameter(name = "code", description = "code", required = true, in = ParameterIn.QUERY)
  46. })
  47. @PostMapping(value = "/wx/phone")
  48. @ResponseBody
  49. public ResultData wxGetPhone(String code) {
  50. // TODO
  51. return null;
  52. }
  53. @Operation(summary = "微信-登录")
  54. @Parameters({
  55. @Parameter(name = "code", description = "code", required = true, in = ParameterIn.QUERY)
  56. })
  57. @PostMapping(value = "/wx/login")
  58. @ResponseBody
  59. public ResultData wxCheckLogin(String code, HttpServletRequest request, HttpServletResponse response) {
  60. return Optional.ofNullable(code)
  61. .map(c -> "https://api.weixin.qq.com/sns/jscode2session?appid=wx0a115eb69d6e9359&secret=d906c8ca51acfd61e13dd61b62364050&js_code=" + c + "&grant_type=authorization_code")
  62. .map(HttpUtil::get)
  63. .map(JSONObject::new)
  64. .map(json -> json.getStr("openid"))
  65. .filter(StringUtils::isNotBlank)
  66. .map(openid -> {
  67. Map<String, Object> map = new HashMap<>();
  68. map.put("openid", openid);
  69. PeopleEntity user = this.peopleBiz.getEntityByUserName(openid);
  70. if (user != null) {
  71. ResultData login = executeLogin(openid, request, response);
  72. if (login.isSuccess()) {
  73. map.putAll(login.getData(Map.class));
  74. }
  75. }
  76. return ResultData.build().success(map);
  77. })
  78. .orElse(ResultData.build().error("登录失败"));
  79. }
  80. @Operation(summary = "微信-用户注册")
  81. @Parameters({
  82. @Parameter(name = "peopleName", description = "openid", required = true, in = ParameterIn.QUERY),
  83. @Parameter(name = "puIcon", description = "微信头像", required = true, in = ParameterIn.QUERY),
  84. @Parameter(name = "puNickname", description = "微信昵称", required = true, in = ParameterIn.QUERY),
  85. @Parameter(name = "puRealName", description = "真实姓名", required = true, in = ParameterIn.QUERY),
  86. @Parameter(name = "peoplePhone", description = "手机号", required = true, in = ParameterIn.QUERY),
  87. @Parameter(name = "puCard", description = "身份证", required = true, in = ParameterIn.QUERY),
  88. @Parameter(name = "", description = "公司名称", required = true, in = ParameterIn.QUERY),
  89. @Parameter(name = "", description = "职位", required = true, in = ParameterIn.QUERY),
  90. @Parameter(name = "", description = "展商邀请码", required = true, in = ParameterIn.QUERY),
  91. @Parameter(name = "", description = "身份类型", required = true, in = ParameterIn.QUERY),
  92. @Parameter(name = "", description = "了解渠道", required = true, in = ParameterIn.QUERY),
  93. @Parameter(name = "", description = "参观目的", required = true, in = ParameterIn.QUERY),
  94. })
  95. @PostMapping(value = "/wx/register")
  96. @ResponseBody
  97. public ResultData wxRegister(@RequestBody PeopleBean people, HttpServletRequest request, HttpServletResponse response) {
  98. people.setPeoplePassword(RandomUtil.randomString(8));
  99. // TODO 7个新字段保存,还有一个邀请用户ID
  100. ResultData register = peopleAction.register(people, request, response);
  101. if (register.isSuccess()) {
  102. return executeLogin(people.getPeopleName(), request, response);
  103. }
  104. return register;
  105. }
  106. private ResultData executeLogin(String openid, HttpServletRequest request, HttpServletResponse response) {
  107. Subject subject = SecurityUtils.getSubject();
  108. WxCustomUserNamePasswordToken cupt = new WxCustomUserNamePasswordToken(openid);
  109. try {
  110. LOG.debug("people 尝试登陆");
  111. subject.login(cupt);
  112. LOG.debug("people 登陆成功");
  113. ResultData info = peopleUserAction.info(request, response);
  114. if (info.isSuccess()) {
  115. Map<String, Object> data = info.getData(Map.class);
  116. PeopleBean tempPeople = new PeopleBean();
  117. // TODO
  118. // tempPeople.setId(peopleEntity.getId());
  119. // tempPeople.setPeopleName(peopleEntity.getPeopleName());
  120. // tempPeople.setPeoplePhone(peopleEntity.getPeoplePhone());
  121. // tempPeople.setPuIcon(peopleEntity.getPuIcon());
  122. // tempPeople.setPuNickname(peopleEntity.getPuNickname());
  123. return ResultData.build().success(tempPeople);
  124. }
  125. return info;
  126. } catch (Exception e) {
  127. LOG.debug("people 登陆失败");
  128. if (e.getCause() instanceof BusinessException) {
  129. throw (BusinessException) e.getCause();
  130. }
  131. e.printStackTrace();
  132. }
  133. return ResultData.build().error(
  134. this.getResString("err.error", this.getResString("people.no.exist")));
  135. }
  136. @Operation(summary = "微信-邀请的用户汇总")
  137. @PostMapping(value = "/people/invitation/summary")
  138. @ResponseBody
  139. public ResultData invitationSummary() {
  140. // TODO
  141. return null;
  142. }
  143. @Operation(summary = "微信-邀请的用户明细")
  144. @PostMapping(value = "/people/invitation/details")
  145. @ResponseBody
  146. public ResultData invitationDetails() {
  147. // TODO
  148. return null;
  149. }
  150. @Operation(summary = "微信-生成入场二维码")
  151. @PostMapping(value = "/people/qrcode")
  152. @ResponseBody
  153. public ResultData qrcode() {
  154. // TODO
  155. return null;
  156. }
  157. @Operation(summary = "微信-展商-上传LOGO")
  158. @PostMapping(value = "/people/upload/logo")
  159. @ResponseBody
  160. public ResultData logo() {
  161. // TODO
  162. return null;
  163. }
  164. @Operation(summary = "微信-展商-申请")
  165. @PostMapping(value = "/people/exhibitor/create")
  166. @ResponseBody
  167. public ResultData exhibitorCreate() {
  168. // TODO
  169. return null;
  170. }
  171. @Operation(summary = "微信-展商-详情")
  172. @PostMapping(value = "/people/exhibitor/info")
  173. @ResponseBody
  174. public ResultData exhibitorInfo() {
  175. // TODO
  176. return null;
  177. }
  178. }