修改小程序注册bug
This commit is contained in:
parent
db302aa2ad
commit
c6aa56e954
@ -1,11 +1,8 @@
|
|||||||
package com.xinelu.web.controller.applet;
|
package com.xinelu.web.controller.applet;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.xinelu.common.config.XinELuConfig;
|
import com.xinelu.common.config.XinELuConfig;
|
||||||
import com.xinelu.common.core.domain.AjaxResult;
|
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.body.PatientInfoBody;
|
||||||
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
|
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
|
||||||
import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService;
|
import com.xinelu.familydoctor.applet.service.IResidentPatientInfoService;
|
||||||
@ -47,16 +44,6 @@ public class ResidentPatientInfoController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation("获取微信手机号")
|
|
||||||
@GetMapping("/getPhone/{code}")
|
|
||||||
public R<JSONObject> getPhone(@PathVariable String code) {
|
|
||||||
try {
|
|
||||||
return R.ok(residentPatientInfoService.getPhone(code));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return R.fail(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation("注册完善信息")
|
@ApiOperation("注册完善信息")
|
||||||
@PostMapping("")
|
@PostMapping("")
|
||||||
public R<String> register(@Validated @RequestBody PatientInfoBody body) {
|
public R<String> register(@Validated @RequestBody PatientInfoBody body) {
|
||||||
@ -129,7 +116,7 @@ public class ResidentPatientInfoController extends BaseController {
|
|||||||
|
|
||||||
@ApiOperation("是否已注册")
|
@ApiOperation("是否已注册")
|
||||||
@GetMapping(value = "/login/{loginCode}/{phoneCode}")
|
@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));
|
return AjaxResult.success(residentPatientInfoService.login(loginCode,phoneCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
package com.xinelu.familydoctor.applet.service;
|
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.body.PatientInfoBody;
|
||||||
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
|
import com.xinelu.familydoctor.applet.pojo.entity.PatientInfo;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -48,7 +48,7 @@ public interface IResidentPatientInfoService {
|
|||||||
* @Param [code]
|
* @Param [code]
|
||||||
* @return java.lang.String
|
* @return java.lang.String
|
||||||
**/
|
**/
|
||||||
JSONObject getPhone(String code) throws Exception;
|
AppletPhoneVO getPhone(String code) throws Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return java.lang.String
|
* @return java.lang.String
|
||||||
@ -121,5 +121,5 @@ public interface IResidentPatientInfoService {
|
|||||||
* @return java.lang.Object
|
* @return java.lang.Object
|
||||||
**/
|
**/
|
||||||
//PatientInfo isRegistered(String code);
|
//PatientInfo isRegistered(String code);
|
||||||
HashMap<String,String> login(String logincode,String phoneCode);
|
HashMap<String,String> login(String logincode,String phoneCode) throws Exception;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,6 @@
|
|||||||
package com.xinelu.familydoctor.applet.service.impl;
|
package com.xinelu.familydoctor.applet.service.impl;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
@ -11,7 +8,6 @@ import com.alibaba.fastjson2.JSONObject;
|
|||||||
import com.xinelu.common.config.AppletChatConfig;
|
import com.xinelu.common.config.AppletChatConfig;
|
||||||
import com.xinelu.common.entity.AppletPhoneVO;
|
import com.xinelu.common.entity.AppletPhoneVO;
|
||||||
import com.xinelu.common.exception.ServiceException;
|
import com.xinelu.common.exception.ServiceException;
|
||||||
import com.xinelu.common.utils.AppletChatUtil;
|
|
||||||
import com.xinelu.common.utils.bean.BeanUtils;
|
import com.xinelu.common.utils.bean.BeanUtils;
|
||||||
import com.xinelu.common.utils.http.HttpService;
|
import com.xinelu.common.utils.http.HttpService;
|
||||||
import com.xinelu.common.utils.http.HttpUtils;
|
import com.xinelu.common.utils.http.HttpUtils;
|
||||||
@ -25,6 +21,7 @@ import com.xinelu.familydoctor.applet.utils.AppletAccessTokenUtils;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -47,7 +44,8 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
private AppletChatConfig appletChatConfig;
|
private AppletChatConfig appletChatConfig;
|
||||||
@Resource
|
@Resource
|
||||||
private AppletAccessTokenUtils appletAccessTokenUtils;
|
private AppletAccessTokenUtils appletAccessTokenUtils;
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate<String, Object> redisTemplate;
|
||||||
/**
|
/**
|
||||||
* @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo
|
* @return com.xinelu.familydoctor.applet.pojo.entity.PatientInfo
|
||||||
* @Author mengkuiliang
|
* @Author mengkuiliang
|
||||||
@ -94,7 +92,6 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
}
|
}
|
||||||
String openid = json.getString("openid");
|
String openid = json.getString("openid");
|
||||||
return openid;
|
return openid;
|
||||||
//return json.getString("openid");
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
@ -108,11 +105,8 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
* @Param [code]
|
* @Param [code]
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getPhone(String code) {
|
public AppletPhoneVO getPhone(String code) throws Exception {
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject result;
|
JSONObject result;
|
||||||
|
|
||||||
// 获取token
|
// 获取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());
|
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();
|
SslUtils.ignoreSsl();
|
||||||
@ -126,25 +120,13 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
if (StringUtils.isEmpty(accessToken)) {
|
if (StringUtils.isEmpty(accessToken)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
//获取手机号 https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html
|
//获取手机号 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;
|
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber" + "?access_token=" + accessToken;
|
||||||
JSONObject params = new JSONObject();
|
JSONObject params = new JSONObject();
|
||||||
params.put("code", code);
|
params.put("code", code);
|
||||||
SslUtils.ignoreSsl();
|
SslUtils.ignoreSsl();
|
||||||
result = httpService.post(url, null, params);
|
result = httpService.post(url, null, params);
|
||||||
if (result == null) {
|
return JSON.parseObject(result.toString(), AppletPhoneVO.class);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
log.info("获取小程序手机号 : {}", result.toJSONString());
|
|
||||||
if (result.getInteger("errcode") != 0) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -334,7 +316,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<String, String> login(String loginCode,String phoneCode) {
|
public HashMap<String, String> login(String loginCode,String phoneCode) throws Exception {
|
||||||
HashMap<String, String> HashMap = new HashMap<>();
|
HashMap<String, String> HashMap = new HashMap<>();
|
||||||
try {
|
try {
|
||||||
SslUtils.ignoreSsl();
|
SslUtils.ignoreSsl();
|
||||||
@ -352,15 +334,11 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
//获取微信accessToken
|
|
||||||
String accessToken;
|
|
||||||
//是否注册状态码
|
|
||||||
String code;
|
String code;
|
||||||
accessToken = appletAccessTokenUtils.getAppletAccessToken();
|
AppletPhoneVO phone = getPhone(phoneCode);
|
||||||
//获取用户手机号
|
String phoneNumber = phone.getPhoneInfo().getPhoneNumber();
|
||||||
AppletPhoneVO appletPhoneInfo = AppletChatUtil.getAppletPhoneInfo(phoneCode, accessToken);
|
HashMap.put("phone",phoneNumber);
|
||||||
HashMap.put("phone",appletPhoneInfo.getPhoneInfo().getPhoneNumber());
|
code = residentPatientInfoMapper.selectPatientInfoByPhone(phoneNumber) == 0 ? "0" : "1";
|
||||||
code = residentPatientInfoMapper.selectPatientInfoByPhone(appletPhoneInfo.getPhoneInfo().getPhoneNumber()) == 0 ? "0" : "1";
|
|
||||||
HashMap.put("code",code);
|
HashMap.put("code",code);
|
||||||
return HashMap;
|
return HashMap;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user