静默登录 绑定手机号
This commit is contained in:
@@ -25,7 +25,9 @@ public class LpkCustomer {
|
||||
private String isEnable;
|
||||
@TableField(value = "wx_mp_openid")
|
||||
private String wxMpOpenid;
|
||||
private String unionId;
|
||||
private String mobile;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
|
||||
private String bindDate;
|
||||
private String realName;
|
||||
private String nick;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class LpkCustomerRest {
|
||||
|
||||
@ApiOperation(value = "微信静默登录")
|
||||
@GetMapping("/wxSilentLogin")
|
||||
public ResultBean<LpkCustomerVo> wxSilentLogin(@RequestParam(value = "wxCode") String wxCode) {
|
||||
public ResultBean wxSilentLogin(@RequestParam(value = "wxCode") String wxCode) {
|
||||
return lpkCustomerService.wxSilentLogin(wxCode);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,6 @@ package com.yxt.yyth.biz.lpkcustomer;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.yxt.common.base.config.component.FileUploadComponent;
|
||||
import com.yxt.common.base.service.MybatisBaseService;
|
||||
import com.yxt.common.base.utils.PagerUtil;
|
||||
import com.yxt.common.base.utils.StringUtils;
|
||||
@@ -48,18 +46,17 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp
|
||||
|
||||
/**
|
||||
* 微信静默登录
|
||||
*
|
||||
* @param wxCode 临时凭证code值
|
||||
* @return ResultBean data:Token
|
||||
* 登陆成功后data返回用户Sid
|
||||
* 聂金毅 2022/6/8 20:30 创建
|
||||
*/
|
||||
public ResultBean<LpkCustomerVo> wxSilentLogin(String wxCode) {
|
||||
public ResultBean wxSilentLogin(String wxCode) {
|
||||
ResultBean rb = ResultBean.fireFail();
|
||||
// 通过wxCode获取unionid,失败返回微信的错误提示。
|
||||
|
||||
ResultBean<JSONObject> rbJsonObject = wxLogin(wxCode, APP_ID, SECRET);
|
||||
if (!rbJsonObject.getSuccess()) {
|
||||
ResultBean<JSONObject> rbJsonObject = wxLogin(wxCode,APP_ID,SECRET);
|
||||
if (!rbJsonObject.getSuccess()){
|
||||
JSONObject jsonObject = rbJsonObject.getData();
|
||||
String errcode = jsonObject.get("errcode").toString();
|
||||
String errmsg = jsonObject.get("errmsg").toString();
|
||||
@@ -67,36 +64,47 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp
|
||||
}
|
||||
// 判断存在不存在unionid,用户在开放平台的唯一标识符,若当前小程序已绑定到微信开放平台帐号下会返回,详见 UnionID 机制说明。、
|
||||
JSONObject jsonObject = rbJsonObject.getData();
|
||||
if (!jsonObject.containsKey("openid")) {
|
||||
if (!jsonObject.containsKey("openid")){
|
||||
return rb.setMsg("未获得openid,请联系管理员");
|
||||
}
|
||||
String unionid = jsonObject.get("unionid").toString();
|
||||
// String unionid = jsonObject.get("unionid").toString();
|
||||
String openid = jsonObject.get("openid").toString();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("unionid", unionid);
|
||||
map.put("openid", openid);
|
||||
LpkCustomer lpkCustomer = baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wx_mp_openid", openid));
|
||||
Map<String,String> map=new HashMap<>();
|
||||
// map.put("unionid",unionid);
|
||||
map.put("openid",openid);
|
||||
LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wx_mp_openid",openid));
|
||||
//查询用户是否存在
|
||||
if (null == lpkCustomer) {
|
||||
if(null==lpkCustomer){
|
||||
//新增用户
|
||||
LpkCustomer newCustomer = new LpkCustomer();
|
||||
LpkCustomer newCustomer=new LpkCustomer();
|
||||
newCustomer.setWxMpOpenid(openid);
|
||||
// newCustomer.setUnionId(unionid);
|
||||
newCustomer.setCreateTime(new Date());
|
||||
baseMapper.insert(newCustomer);
|
||||
return rb.success().setData(newCustomer);
|
||||
return rb.setData(newCustomer).setCode("110");
|
||||
}
|
||||
//判断是否绑定手机号
|
||||
if(StringUtils.isBlank(lpkCustomer.getMobile())){
|
||||
return rb.setData(lpkCustomer).setCode("110");
|
||||
}
|
||||
return rb.success().setData(lpkCustomer);
|
||||
}
|
||||
|
||||
public ResultBean wxBindMobile(WxBindMobileDto wxBindMobileDto) {
|
||||
ResultBean rb = ResultBean.fireFail();
|
||||
String mobile = wxBindMobileDto.getMobile();
|
||||
LpkCustomer lpkCustomer = baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wx_mp_openid", wxBindMobileDto.getOpenid()));
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wx_mp_openid",wxBindMobileDto.getOpenid()));
|
||||
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
lpkCustomer.setBindDate(sdf.format(new Date()));
|
||||
lpkCustomer.setMobile(mobile);
|
||||
baseMapper.insert(lpkCustomer);
|
||||
return rb.setMsg("绑定成功");
|
||||
baseMapper.updateById(lpkCustomer);
|
||||
return rb.success().setMsg("绑定成功").setData(lpkCustomer.getSid());
|
||||
}
|
||||
public ResultBean wxBindMobile(String sid) {
|
||||
ResultBean rb = ResultBean.fireFail();
|
||||
|
||||
LpkCustomer lpkCustomer= baseMapper.selectOne(new QueryWrapper<LpkCustomer>().eq("wx_mp_openid",wxBindMobileDto.getOpenid()));
|
||||
|
||||
return rb.success().setMsg("绑定成功").setData(lpkCustomer.getSid());
|
||||
}
|
||||
|
||||
public ResultBean<PagerVo<LpkCustomerVo>> customerListPage(PagerQuery<LpkCustomerQuery> pq) {
|
||||
|
||||
Reference in New Issue
Block a user