解决小程序登录问题
This commit is contained in:
parent
e1bfafabde
commit
e2e8041371
@ -102,12 +102,9 @@ public class ResidentPatientInfoController extends BaseController {
|
||||
}
|
||||
|
||||
@ApiOperation("获取当前注册居民")
|
||||
@GetMapping(value = "/getCurrentResident/{openid}/{cityCode}")
|
||||
public R<PatientInfo> getCurrentResident(@PathVariable("openid") String openid, @PathVariable("cityCode") String cityCode) {
|
||||
if(StringUtils.isBlank(cityCode) || cityCode.equals("null")) {
|
||||
R.fail("绑定城市编码不能为空");
|
||||
}
|
||||
return R.ok(residentPatientInfoService.getCurrentResident(openid, cityCode));
|
||||
@GetMapping(value = "/getCurrentResident/{openid}")
|
||||
public R<PatientInfo> getCurrentResident(@PathVariable("openid") String openid) {
|
||||
return R.ok(residentPatientInfoService.getCurrentResident(openid, null));
|
||||
}
|
||||
|
||||
/*@ApiOperation("是否已注册")
|
||||
|
||||
@ -102,11 +102,11 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
||||
try {
|
||||
SslUtils.ignoreSsl();
|
||||
String params = "appid=" + appletChatConfig.getAppletId() + "&secret=" + appletChatConfig.getSecret() + "&js_code=" + code + "&grant_type=" + appletChatConfig.getGrantType();
|
||||
log.info("获取openID请求参数{}", params);
|
||||
// log.info("获取openID请求参数{}", params);
|
||||
String result = HttpUtils.sendPost("https://api.weixin.qq.com/sns/jscode2session", params);
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
// {"errcode":40029,"errmsg":"invalid code, rid: 650bf9c3-31a6c960-2b437029"}
|
||||
log.info("获取openID响应结果{}", json.toJSONString());
|
||||
// log.info("获取openID响应结果{}", json.toJSONString());
|
||||
if (!json.containsKey("openid")) {
|
||||
throw new ServiceException(json.getString("errmsg"));
|
||||
}
|
||||
@ -135,7 +135,7 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
||||
return null;
|
||||
}
|
||||
result = JSON.parseObject(tokenResult);
|
||||
log.info("获取小程序token : {}", result.toJSONString());
|
||||
// log.info("获取小程序token : {}", result.toJSONString());
|
||||
String accessToken = result.getString("access_token");
|
||||
if (StringUtils.isEmpty(accessToken)) {
|
||||
return null;
|
||||
@ -434,40 +434,43 @@ public class ResidentPatientInfoServiceImpl implements IResidentPatientInfoServi
|
||||
}*/
|
||||
@Override
|
||||
public HashMap<String, String> login(String loginCode, String phoneCode) throws Exception {
|
||||
HashMap<String, String> HashMap = new HashMap<>();
|
||||
HashMap<String, String> resultMap = new HashMap<>();
|
||||
try {
|
||||
SslUtils.ignoreSsl();
|
||||
String params = "appid=" + appletChatConfig.getAppletId() + "&secret=" + appletChatConfig.getSecret() + "&js_code=" + loginCode + "&grant_type=" + appletChatConfig.getGrantType();
|
||||
log.info("获取openID请求参数{}", params);
|
||||
// log.info("获取openID请求参数{}", params);
|
||||
String result = HttpUtils.sendPost("https://api.weixin.qq.com/sns/jscode2session", params);
|
||||
JSONObject json = JSONObject.parseObject(result);
|
||||
// {"errcode":40029,"errmsg":"invalid code, rid: 650bf9c3-31a6c960-2b437029"}
|
||||
log.info("获取openID响应结果{}", json.toJSONString());
|
||||
// log.info("获取openID响应结果{}", json.toJSONString());
|
||||
if (!json.containsKey("openid")) {
|
||||
throw new ServiceException(json.getString("errmsg"));
|
||||
}
|
||||
String openid = json.getString("openid");
|
||||
HashMap.put("openid", openid);
|
||||
resultMap.put("openid", openid);
|
||||
|
||||
//获取手机号
|
||||
AppletPhoneVO phone = getPhone(phoneCode);
|
||||
String phoneNumber = phone.getPhoneInfo().getPhoneNumber();
|
||||
resultMap.put("phone", phoneNumber);
|
||||
List<PatientInfo> infoList = residentPatientInfoMapper.selectPatientInfoByPhone(phoneNumber);
|
||||
if(infoList != null && infoList.size() > 0) {
|
||||
if(!infoList.get(0).getBindOpenid().equals(openid)) {
|
||||
resultMap.put("code", "2");
|
||||
resultMap.put("info", "已被其他人注册");
|
||||
return resultMap;
|
||||
} else {
|
||||
resultMap.put("code", "1");
|
||||
resultMap.put("info", "已注册");
|
||||
return resultMap;
|
||||
}
|
||||
}
|
||||
resultMap.put("code", "0");
|
||||
resultMap.put("info", "未注册");
|
||||
return resultMap;
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
//获取手机号
|
||||
String code;
|
||||
String cityCode = "";
|
||||
AppletPhoneVO phone = getPhone(phoneCode);
|
||||
String phoneNumber = phone.getPhoneInfo().getPhoneNumber();
|
||||
HashMap.put("phone", phoneNumber);
|
||||
List<PatientInfo> infoList = residentPatientInfoMapper.selectPatientInfoByPhone(phoneNumber);
|
||||
code = infoList.size() == 0 ? "0" : "1";
|
||||
//返回绑定城市
|
||||
if ("1".equals(code)) {
|
||||
for (PatientInfo patientInfo : infoList) {
|
||||
cityCode = patientInfo.getCityCode();
|
||||
}
|
||||
}
|
||||
HashMap.put("code", code);
|
||||
HashMap.put("cityCode", cityCode);
|
||||
return HashMap;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -292,11 +292,11 @@
|
||||
<choose>
|
||||
<!-- 已完成 -->
|
||||
<when test="completed == 1">
|
||||
and (s.booking_status = '1' or s.approval_status in ('1','2'))
|
||||
and s.booking_status = '1'
|
||||
</when>
|
||||
<!-- 未完成 -->
|
||||
<when test="completed == 2">
|
||||
and (s.booking_status = '0' and s.approval_status = '0')
|
||||
and s.booking_status != '1'
|
||||
</when>
|
||||
<otherwise></otherwise>
|
||||
</choose>
|
||||
|
||||
@ -303,7 +303,7 @@ public class AppletLoginServiceImpl implements AppletLoginService {
|
||||
@Override
|
||||
public AjaxResult existPatientInfo(String openId) {
|
||||
PatientInfo patientInfo = appletLoginMapper.getPatientInfoByOpenId(openId);
|
||||
if (Objects.nonNull(patientInfo) && StringUtils.isNotBlank(patientInfo.getOpenid())) {
|
||||
if (Objects.nonNull(patientInfo) && StringUtils.isNotBlank(patientInfo.getBindOpenid())) {
|
||||
return AjaxResult.success("LOGIN");
|
||||
}
|
||||
return AjaxResult.success("NOT_LOGIN");
|
||||
|
||||
@ -176,6 +176,6 @@ public class PatientAndDiseaseVO implements Serializable {
|
||||
/**
|
||||
* 居民健康行为积分-总分
|
||||
*/
|
||||
private String score;
|
||||
private String score = "0";
|
||||
|
||||
}
|
||||
|
||||
@ -75,13 +75,14 @@
|
||||
community_alias_name,
|
||||
home_longitude,
|
||||
home_latitude,
|
||||
head_picture_url
|
||||
head_picture_url,
|
||||
bind_openid
|
||||
FROM
|
||||
patient_info
|
||||
<where>
|
||||
del_flag = 0
|
||||
<if test="openId != null and openId != ''">
|
||||
and openid = #{openId}
|
||||
and bind_openid = #{openId}
|
||||
</if>
|
||||
</where>
|
||||
limit 1
|
||||
|
||||
Loading…
Reference in New Issue
Block a user