From c6aa56e95427b0e35228651e8a63b0853f120862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=97=AD?= <17615834396@163.com> Date: Fri, 13 Oct 2023 13:11:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=B3=A8=E5=86=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../applet/ResidentPatientInfoController.java | 17 +------ .../service/IResidentPatientInfoService.java | 6 +-- .../impl/ResidentPatientInfoServiceImpl.java | 44 +++++-------------- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/xinelu-admin/src/main/java/com/xinelu/web/controller/applet/ResidentPatientInfoController.java b/xinelu-admin/src/main/java/com/xinelu/web/controller/applet/ResidentPatientInfoController.java index 12d3945..da46c82 100644 --- a/xinelu-admin/src/main/java/com/xinelu/web/controller/applet/ResidentPatientInfoController.java +++ b/xinelu-admin/src/main/java/com/xinelu/web/controller/applet/ResidentPatientInfoController.java @@ -1,11 +1,8 @@ package com.xinelu.web.controller.applet; -import com.alibaba.fastjson2.JSONObject; import com.xinelu.common.config.XinELuConfig; import com.xinelu.common.core.domain.AjaxResult; -import com.xinelu.common.exception.ServiceException; -import com.xinelu.common.utils.file.FileUploadUtils; -import com.xinelu.common.utils.file.MimeTypeUtils; + import com.xinelu.familydoctor.applet.pojo.body.PatientInfoBody; import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo; import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService; @@ -47,16 +44,6 @@ public class ResidentPatientInfoController extends BaseController { } } - @ApiOperation("获取微信手机号") - @GetMapping("/getPhone/{code}") - public R getPhone(@PathVariable String code) { - try { - return R.ok(residentPatientInfoService.getPhone(code)); - } catch (Exception e) { - return R.fail(e.getMessage()); - } - } - @ApiOperation("注册完善信息") @PostMapping("") public R register(@Validated @RequestBody PatientInfoBody body) { @@ -129,7 +116,7 @@ public class ResidentPatientInfoController extends BaseController { @ApiOperation("是否已注册") @GetMapping(value = "/login/{loginCode}/{phoneCode}") - public AjaxResult isRegistered(@PathVariable("loginCode") String loginCode, @PathVariable("phoneCode") String phoneCode) { + public AjaxResult isRegistered(@PathVariable("loginCode") String loginCode, @PathVariable("phoneCode") String phoneCode) throws Exception { return AjaxResult.success(residentPatientInfoService.login(loginCode,phoneCode)); } diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/IResidentPatientInfoService.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/IResidentPatientInfoService.java index f8122e9..257ce37 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/IResidentPatientInfoService.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/IResidentPatientInfoService.java @@ -1,6 +1,6 @@ package com.xinelu.familydoctor.applet.service; -import com.alibaba.fastjson2.JSONObject; +import com.xinelu.common.entity.AppletPhoneVO; import com.xinelu.familydoctor.applet.pojo.body.PatientInfoBody; import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo; import java.util.HashMap; @@ -48,7 +48,7 @@ public interface IResidentPatientInfoService { * @Param [code] * @return java.lang.String **/ - JSONObject getPhone(String code) throws Exception; + AppletPhoneVO getPhone(String code) throws Exception; /** * @return java.lang.String @@ -121,5 +121,5 @@ public interface IResidentPatientInfoService { * @return java.lang.Object **/ //PatientInfo isRegistered(String code); - HashMap login(String logincode,String phoneCode); + HashMap login(String logincode,String phoneCode) throws Exception; } diff --git a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java index b80d9b0..de51f3c 100644 --- a/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java +++ b/xinelu-familydoctor/src/main/java/com/xinelu/familydoctor/applet/service/impl/ResidentPatientInfoServiceImpl.java @@ -1,9 +1,6 @@ package com.xinelu.familydoctor.applet.service.impl; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; import com.alibaba.fastjson2.JSON; @@ -11,7 +8,6 @@ import com.alibaba.fastjson2.JSONObject; import com.xinelu.common.config.AppletChatConfig; import com.xinelu.common.entity.AppletPhoneVO; import com.xinelu.common.exception.ServiceException; -import com.xinelu.common.utils.AppletChatUtil; import com.xinelu.common.utils.bean.BeanUtils; import com.xinelu.common.utils.http.HttpService; import com.xinelu.common.utils.http.HttpUtils; @@ -25,6 +21,7 @@ import com.xinelu.familydoctor.applet.utils.AppletAccessTokenUtils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -47,7 +44,8 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi private AppletChatConfig appletChatConfig; @Resource private AppletAccessTokenUtils appletAccessTokenUtils; - + @Resource + private RedisTemplate redisTemplate; /** * @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo * @Author mengkuiliang @@ -94,7 +92,6 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi } String openid = json.getString("openid"); return openid; - //return json.getString("openid"); } catch (Exception e) { throw new ServiceException(e.getMessage()); } @@ -108,11 +105,8 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi * @Param [code] **/ @Override - public JSONObject getPhone(String code) { - - try { + public AppletPhoneVO getPhone(String code) throws Exception { JSONObject result; - // 获取token String token_url = String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", appletChatConfig.getAppletId(), appletChatConfig.getSecret()); SslUtils.ignoreSsl(); @@ -126,25 +120,13 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi if (StringUtils.isEmpty(accessToken)) { return null; } - //获取手机号 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber" + "?access_token=" + accessToken; JSONObject params = new JSONObject(); params.put("code", code); SslUtils.ignoreSsl(); result = httpService.post(url, null, params); - if (result == null) { - return null; - } - log.info("获取小程序手机号 : {}", result.toJSONString()); - if (result.getInteger("errcode") != 0) { - return null; - } - return result; - } catch (Exception e) { - e.printStackTrace(); - } - return null; + return JSON.parseObject(result.toString(), AppletPhoneVO.class); } /** @@ -334,7 +316,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi }*/ @Override - public HashMap login(String loginCode,String phoneCode) { + public HashMap login(String loginCode,String phoneCode) throws Exception { HashMap HashMap = new HashMap<>(); try { SslUtils.ignoreSsl(); @@ -352,15 +334,11 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi } catch (Exception e) { throw new ServiceException(e.getMessage()); } - //获取微信accessToken - String accessToken; - //是否注册状态码 String code; - accessToken = appletAccessTokenUtils.getAppletAccessToken(); - //获取用户手机号 - AppletPhoneVO appletPhoneInfo = AppletChatUtil.getAppletPhoneInfo(phoneCode, accessToken); - HashMap.put("phone",appletPhoneInfo.getPhoneInfo().getPhoneNumber()); - code = residentPatientInfoMapper.selectPatientInfoByPhone(appletPhoneInfo.getPhoneInfo().getPhoneNumber()) == 0 ? "0" : "1"; + AppletPhoneVO phone = getPhone(phoneCode); + String phoneNumber = phone.getPhoneInfo().getPhoneNumber(); + HashMap.put("phone",phoneNumber); + code = residentPatientInfoMapper.selectPatientInfoByPhone(phoneNumber) == 0 ? "0" : "1"; HashMap.put("code",code); return HashMap; }