|
|
|
|
@@ -2,6 +2,8 @@ package com.yxt.yythmall.biz.lpkcustomer;
|
|
|
|
|
|
|
|
|
|
import cn.dev33.satoken.stp.SaTokenInfo;
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
@@ -14,6 +16,7 @@ import com.yxt.common.core.result.FileUploadResult;
|
|
|
|
|
import com.yxt.common.core.result.ResultBean;
|
|
|
|
|
import com.yxt.common.core.vo.PagerVo;
|
|
|
|
|
import com.yxt.yythmall.api.lpkcustomer.*;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
|
|
@@ -30,6 +33,7 @@ import java.util.*;
|
|
|
|
|
* @date 2023/11/21 15:03
|
|
|
|
|
*/
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, LpkCustomer> {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
@@ -98,7 +102,8 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp
|
|
|
|
|
// newCustomer.setUnionId(unionid);
|
|
|
|
|
newCustomer.setCreateTime(new Date());
|
|
|
|
|
newCustomer.setPhoto("headImage.jpg");
|
|
|
|
|
newCustomer.setNick("小菜窖000"+newCustomer.getId());
|
|
|
|
|
LpkCustomer lpkCustomer1 = baseMapper.selectOwn();
|
|
|
|
|
newCustomer.setNick("小主000"+ Integer.valueOf(lpkCustomer1.getId()) +1);
|
|
|
|
|
baseMapper.insert(newCustomer);
|
|
|
|
|
// return rb.setData(newCustomer).setCode("110");
|
|
|
|
|
StpUtil.login(newCustomer.getId());
|
|
|
|
|
@@ -117,7 +122,7 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp
|
|
|
|
|
lpkCustomer = fetchBySid(lpkCustomer.getSid());
|
|
|
|
|
}
|
|
|
|
|
if(StringUtils.isBlank(lpkCustomer.getNick())){
|
|
|
|
|
lpkCustomer.setNick("小菜窖000"+lpkCustomer.getId());
|
|
|
|
|
lpkCustomer.setNick("小主000"+lpkCustomer.getId());
|
|
|
|
|
baseMapper.updateById(lpkCustomer);
|
|
|
|
|
lpkCustomer = fetchBySid(lpkCustomer.getSid());
|
|
|
|
|
}
|
|
|
|
|
@@ -214,4 +219,43 @@ public class LpkCustomerService extends MybatisBaseService<LpkCustomerMapper, Lp
|
|
|
|
|
customerInfoVo.setPhoto(photo);
|
|
|
|
|
return rb.success().setData(customerInfoVo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ResultBean<String> getPhoneNumber(String code,String userSid) {
|
|
|
|
|
ResultBean<String> rb = ResultBean.fireFail();
|
|
|
|
|
try {
|
|
|
|
|
String objectStr = HttpUtil.post(String.format("https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=%s",getAccessToken()), "{\"code\":\""+code+"\"}");
|
|
|
|
|
log.info(objectStr);
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(objectStr);
|
|
|
|
|
String errCode = jsonObject.getString("errcode");
|
|
|
|
|
if(StringUtils.isNotBlank(errCode)){
|
|
|
|
|
return rb.setMsg("微信code值失效");
|
|
|
|
|
}
|
|
|
|
|
jsonObject= jsonObject.getJSONObject("phone_info");
|
|
|
|
|
String phone = jsonObject.getString("phoneNumber");
|
|
|
|
|
LpkCustomer lpkCustomer = fetchBySid(userSid);
|
|
|
|
|
if(lpkCustomer == null){
|
|
|
|
|
return rb.setMsg("该客户不存在");
|
|
|
|
|
}
|
|
|
|
|
lpkCustomer.setMobile(phone);
|
|
|
|
|
baseMapper.updateById(lpkCustomer);
|
|
|
|
|
return rb.success().setData(phone);
|
|
|
|
|
}catch (Exception e){
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error("微信code解析异常", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAccessToken() {
|
|
|
|
|
try {
|
|
|
|
|
String objectStr = HttpUtil.get(String.format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s", APP_ID,SECRET));
|
|
|
|
|
log.info(objectStr);
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(objectStr);
|
|
|
|
|
return jsonObject.getString("access_token");
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error("微信code解析异常", e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|