修改小程序注册bug
This commit is contained in:
parent
db302aa2ad
commit
c6aa56e954
@ -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<JSONObject> getPhone(@PathVariable String code) {
|
||||
try {
|
||||
return R.ok(residentPatientInfoService.getPhone(code));
|
||||
} catch (Exception e) {
|
||||
return R.fail(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("注册完善信息")
|
||||
@PostMapping("")
|
||||
public R<String> 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));
|
||||
}
|
||||
|
||||
|
||||
@ -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<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;
|
||||
|
||||
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<String, Object> 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<String, String> login(String loginCode,String phoneCode) {
|
||||
public HashMap<String, String> login(String loginCode,String phoneCode) throws Exception {
|
||||
HashMap<String, String> 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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user