1. 调整
This commit is contained in:
parent
4d0051d5c2
commit
b7a1c8172e
|
@ -132,10 +132,10 @@ public class SysLoginController
|
||||||
* 微信登录
|
* 微信登录
|
||||||
*/
|
*/
|
||||||
@PostMapping("/wxlogin")
|
@PostMapping("/wxlogin")
|
||||||
public AjaxResult wxlogin(String mobileCode,String openid) {
|
public AjaxResult wxlogin(String mobileCode,String jsCode) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = loginService.wxloing(mobileCode,openid);
|
String token = loginService.wxloing(mobileCode,jsCode);
|
||||||
ajax.put(Constants.TOKEN, token);
|
ajax.put(Constants.TOKEN, token);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
@ -145,10 +145,10 @@ public class SysLoginController
|
||||||
* 根据openid静默登录
|
* 根据openid静默登录
|
||||||
*/
|
*/
|
||||||
@PostMapping("/loginByopenid")
|
@PostMapping("/loginByopenid")
|
||||||
public AjaxResult loginByopenid(String openid) {
|
public AjaxResult loginByopenid(String jsCode) {
|
||||||
AjaxResult ajax = AjaxResult.success();
|
AjaxResult ajax = AjaxResult.success();
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
String token = loginService.loginByopenid(openid);
|
String token = loginService.loginByopenid(jsCode);
|
||||||
ajax.put(Constants.TOKEN, token);
|
ajax.put(Constants.TOKEN, token);
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,7 +178,7 @@ parameter:
|
||||||
templateIdRegister: 1794931
|
templateIdRegister: 1794931
|
||||||
wx:
|
wx:
|
||||||
appid: wxa6d6dfbb59b630fd
|
appid: wxa6d6dfbb59b630fd
|
||||||
appSecret: eb8eaca9843974cf464b3d5eda056514
|
appSecret: 4bc943979cf573ec3237d15d3ef0ca93
|
||||||
# 阿里云短信
|
# 阿里云短信
|
||||||
aliyun:
|
aliyun:
|
||||||
accessKeyId: LTAI5tS7bUhRvjcTy4yJkagK
|
accessKeyId: LTAI5tS7bUhRvjcTy4yJkagK
|
||||||
|
|
|
@ -17,6 +17,13 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<!--hutool-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>4.5.7</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--中文转拼音-->
|
<!--中文转拼音-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.belerweb</groupId>
|
<groupId>com.belerweb</groupId>
|
||||||
|
|
|
@ -6,11 +6,15 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||||
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
|
||||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||||
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.ruoyi.common.core.domain.entity.AsUser;
|
import com.ruoyi.common.core.domain.entity.AsUser;
|
||||||
import com.ruoyi.common.utils.http.HttpUtils;
|
import com.ruoyi.common.utils.http.HttpUtils;
|
||||||
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import com.ruoyi.common.utils.wx.AccessTokenUtil;
|
import com.ruoyi.common.utils.wx.AccessTokenUtil;
|
||||||
import com.ruoyi.common.utils.wx.vo.AccessToken;
|
import com.ruoyi.common.utils.wx.vo.AccessToken;
|
||||||
|
import com.ruoyi.device.domain.vo.WeChatMiniAuthorizeVo;
|
||||||
import com.ruoyi.device.service.IAsUserService;
|
import com.ruoyi.device.service.IAsUserService;
|
||||||
import me.chanjar.weixin.common.error.WxErrorException;
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import org.apache.commons.lang3.ObjectUtils;
|
import org.apache.commons.lang3.ObjectUtils;
|
||||||
|
@ -259,7 +263,9 @@ public class SysLoginService
|
||||||
/**
|
/**
|
||||||
* 微信登录
|
* 微信登录
|
||||||
*/
|
*/
|
||||||
public String wxloing(String mobileCode,String openid) {
|
public String wxloing(String mobileCode,String jsCode) {
|
||||||
|
//根据jsCode换取openid
|
||||||
|
String openId = getOpenId(jsCode);
|
||||||
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=";
|
||||||
String phoneNumber = null;
|
String phoneNumber = null;
|
||||||
AsUser user = null;
|
AsUser user = null;
|
||||||
|
@ -286,7 +292,7 @@ public class SysLoginService
|
||||||
asUser.setPhonenumber(phoneNumber);
|
asUser.setPhonenumber(phoneNumber);
|
||||||
asUser.setLoginIp(IpUtils.getIpAddr());
|
asUser.setLoginIp(IpUtils.getIpAddr());
|
||||||
asUser.setLoginDate(DateUtils.getNowDate());
|
asUser.setLoginDate(DateUtils.getNowDate());
|
||||||
asUser.setWxopenid(openid);
|
asUser.setWxopenid(openId);
|
||||||
asUser.setCreateTime(DateUtils.getNowDate());
|
asUser.setCreateTime(DateUtils.getNowDate());
|
||||||
int i = asUserService.insertUser(asUser);
|
int i = asUserService.insertUser(asUser);
|
||||||
user = asUser;
|
user = asUser;
|
||||||
|
@ -318,8 +324,10 @@ public class SysLoginService
|
||||||
/**
|
/**
|
||||||
* 根据openid静默登录
|
* 根据openid静默登录
|
||||||
*/
|
*/
|
||||||
public String loginByopenid(String openid) {
|
public String loginByopenid(String jsCode) {
|
||||||
AsUser user = asUserService.selectUserByWxopenid(openid);
|
//根据jsCode换取openid
|
||||||
|
String openId = getOpenId(jsCode);
|
||||||
|
AsUser user = asUserService.selectUserByWxopenid(openId);
|
||||||
if(ObjectUtils.isEmpty(user)){
|
if(ObjectUtils.isEmpty(user)){
|
||||||
throw new ServiceException("未查询到用户信息");
|
throw new ServiceException("未查询到用户信息");
|
||||||
}
|
}
|
||||||
|
@ -347,5 +355,19 @@ public class SysLoginService
|
||||||
return tokenService.createToken(loginUser);
|
return tokenService.createToken(loginUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getOpenId(String jsCode) {
|
||||||
|
//根据jsCode换取openid
|
||||||
|
String appId = SpringUtils.getRequiredProperty("wx.appid");
|
||||||
|
String secret = SpringUtils.getRequiredProperty("wx.appSecret");
|
||||||
|
String url = StrUtil.format("https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code", appId, secret, jsCode);
|
||||||
|
String s = HttpUtils.sendGet(url);
|
||||||
|
WeChatMiniAuthorizeVo authorizeVo = JSONObject.parseObject(s, WeChatMiniAuthorizeVo.class);
|
||||||
|
if (StringUtils.isEmpty(s) ) {
|
||||||
|
throw new ServiceException("微信平台接口异常,没任何数据返回!");
|
||||||
|
}
|
||||||
|
String openId = authorizeVo.getOpenid();
|
||||||
|
return openId;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -324,10 +324,10 @@ public class AppController extends BaseController
|
||||||
* 配网成功
|
* 配网成功
|
||||||
*/
|
*/
|
||||||
@Log(title = "配网成功", businessType = BusinessType.UPDATE)
|
@Log(title = "配网成功", businessType = BusinessType.UPDATE)
|
||||||
@PostMapping("/network/{deviceId}")
|
@PostMapping("/network/{mac}")
|
||||||
public AjaxResult settingNetwork(@PathVariable Long deviceId)
|
public AjaxResult settingNetwork(@PathVariable String mac)
|
||||||
{
|
{
|
||||||
return toAjax(asDeviceService.settingNetwork(deviceId));
|
return toAjax(asDeviceService.settingNetwork(mac));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.ruoyi.device.domain.vo;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 微信小程序用户授权返回数据
|
||||||
|
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class WeChatMiniAuthorizeVo implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID=1L;
|
||||||
|
|
||||||
|
private String session_key;
|
||||||
|
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
private String unionid;
|
||||||
|
|
||||||
|
private String errcode;
|
||||||
|
|
||||||
|
private String errmsg;
|
||||||
|
}
|
|
@ -54,6 +54,15 @@ public interface AsDeviceMapper extends BaseMapper<AsDevice>
|
||||||
*/
|
*/
|
||||||
public int updateAsDevice(AsDevice asDevice);
|
public int updateAsDevice(AsDevice asDevice);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备列表
|
||||||
|
*
|
||||||
|
* @param asDevice 设备列表
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateAsDeviceByMac(AsDevice asDevice);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除设备列表
|
* 删除设备列表
|
||||||
*
|
*
|
||||||
|
|
|
@ -90,10 +90,10 @@ public interface IAsDeviceService
|
||||||
/**
|
/**
|
||||||
* 配网成功
|
* 配网成功
|
||||||
*
|
*
|
||||||
* @param deviceId 设备id
|
* @param mac 设备id
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
Boolean settingNetwork(Long deviceId);
|
Boolean settingNetwork(String mac);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据mac号查询设备是否被绑定
|
* 根据mac号查询设备是否被绑定
|
||||||
|
|
|
@ -442,11 +442,12 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
throw new ServiceException("该设备已经被删除");
|
throw new ServiceException("该设备已经被删除");
|
||||||
}
|
}
|
||||||
if(ObjectUtils.isNotEmpty(device.getUserId()) && "1".equals(device.getIsNetwork())){
|
if(ObjectUtils.isNotEmpty(device.getUserId()) && "1".equals(device.getIsNetwork())){
|
||||||
throw new ServiceException("该设备已经绑定用户,请先解绑!");
|
throw new ServiceException("该设备已经绑定用户,请先!");
|
||||||
}
|
}
|
||||||
device.setUserId(asDevice.getUserId());
|
device.setUserId(asDevice.getUserId());
|
||||||
int i = asDeviceMapper.updateAsDevice(device);
|
int i = asDeviceMapper.updateAsDevice(device);
|
||||||
if(i>0){
|
if(i>0){
|
||||||
|
toggleDevice(asDevice.getUserId(), device.getDeviceId());
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
@ -461,21 +462,33 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int logicallyDelete(AsDevice device) {
|
public int logicallyDelete(AsDevice device) {
|
||||||
return asDeviceMapper.updateAsDevice(device);
|
Long deviceId = device.getDeviceId();
|
||||||
|
AsDevice device2 = asDeviceMapper.selectAsDeviceByDeviceId(deviceId);
|
||||||
|
int i = asDeviceMapper.updateAsDevice(device);
|
||||||
|
//解绑成功后,该用户如果有其他的设备则随便找一个默认的
|
||||||
|
if(i>0){
|
||||||
|
List<AsDevice> asDevices = asDeviceMapper.selectAsDeviceList(AsDevice.builder().userId(device2.getUserId()).build());
|
||||||
|
if(asDevices.size()>0){
|
||||||
|
AsDevice device1 = asDevices.get(0);
|
||||||
|
device1.setIsDefault("1");
|
||||||
|
asDeviceMapper.updateAsDevice(device1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配网成功
|
* 配网成功
|
||||||
*
|
*
|
||||||
* @param deviceId 设备id
|
* @param mac mac
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean settingNetwork(Long deviceId) {
|
public Boolean settingNetwork(String mac) {
|
||||||
AsDevice device = new AsDevice();
|
AsDevice device = new AsDevice();
|
||||||
device.setDeviceId(deviceId);
|
device.setMac(mac);
|
||||||
device.setIsNetwork("1");
|
device.setIsNetwork("1");
|
||||||
int i = asDeviceMapper.updateAsDevice(device);
|
int i = asDeviceMapper.updateAsDeviceByMac(device);
|
||||||
return i>0;
|
return i>0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,6 +182,45 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
where device_id = #{deviceId}
|
where device_id = #{deviceId}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="updateAsDeviceByMac" parameterType="AsDevice">
|
||||||
|
update as_device
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="picture != null">picture = #{picture},</if>
|
||||||
|
<if test="deviceName != null">device_name = #{deviceName},</if>
|
||||||
|
<if test="classifyId != null">classify_id = #{classifyId},</if>
|
||||||
|
<if test="classifyName != null and classifyName != ''">classify_name = #{classifyName},</if>
|
||||||
|
<if test="modelId != null">model_id = #{modelId},</if>
|
||||||
|
<if test="model != null">model = #{model},</if>
|
||||||
|
<if test="activationTime != null">activation_time = #{activationTime},</if>
|
||||||
|
<if test="onlineStatus != null">online_status = #{onlineStatus},</if>
|
||||||
|
<if test="userId != null">user_id = #{userId},</if>
|
||||||
|
<if test="userName != null and userName != ''">user_name = #{userName},</if>
|
||||||
|
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
||||||
|
<if test="regularWatering != null">regular_watering = #{regularWatering},</if>
|
||||||
|
<if test="soilMoistureOpen != null">soil_moisture_open = #{soilMoistureOpen},</if>
|
||||||
|
<if test="soilMoistureClose != null">soil_moisture_close = #{soilMoistureClose},</if>
|
||||||
|
<if test="waterIntensity != null">water_intensity = #{waterIntensity},</if>
|
||||||
|
<if test="pulseMode != null">pulse_mode = #{pulseMode},</if>
|
||||||
|
<if test="pulseModeParam != null">pulse_mode_param = #{pulseModeParam},</if>
|
||||||
|
<if test="screenRestTime != null">screen_rest_time = #{screenRestTime},</if>
|
||||||
|
<if test="version != null">version = #{version},</if>
|
||||||
|
<if test="versionId != null">version_id = #{versionId},</if>
|
||||||
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
<if test="regularWateringJson != null">regular_watering_json = #{regularWateringJson},</if>
|
||||||
|
<if test="soilMoisture != null">soil_moisture = #{soilMoisture},</if>
|
||||||
|
<if test="waterIntensitySwitch != null">water_intensity_switch = #{waterIntensitySwitch},</if>
|
||||||
|
<if test="status != null">status = #{status},</if>
|
||||||
|
<if test="isNetwork != null">is_network = #{isNetwork},</if>
|
||||||
|
<if test="isDefault != null">is_default = #{isDefault},</if>
|
||||||
|
<if test="modeStr != null">mode_str = #{modeStr}</if>
|
||||||
|
</trim>
|
||||||
|
where mac = #{mac}
|
||||||
|
</update>
|
||||||
|
|
||||||
<delete id="deleteAsDeviceByDeviceId" parameterType="Long">
|
<delete id="deleteAsDeviceByDeviceId" parameterType="Long">
|
||||||
delete from as_device where device_id = #{deviceId}
|
delete from as_device where device_id = #{deviceId}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
|
@ -118,6 +118,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="email != null and email != ''">email,</if>
|
<if test="email != null and email != ''">email,</if>
|
||||||
<if test="avatar != null and avatar != ''">avatar,</if>
|
<if test="avatar != null and avatar != ''">avatar,</if>
|
||||||
<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
|
<if test="phonenumber != null and phonenumber != ''">phonenumber,</if>
|
||||||
|
<if test="wxopenid != null and wxopenid != ''">wxopenid,</if>
|
||||||
<if test="sex != null and sex != ''">sex,</if>
|
<if test="sex != null and sex != ''">sex,</if>
|
||||||
<if test="password != null and password != ''">password,</if>
|
<if test="password != null and password != ''">password,</if>
|
||||||
<if test="status != null and status != ''">status,</if>
|
<if test="status != null and status != ''">status,</if>
|
||||||
|
@ -131,6 +132,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="email != null and email != ''">#{email},</if>
|
<if test="email != null and email != ''">#{email},</if>
|
||||||
<if test="avatar != null and avatar != ''">#{avatar},</if>
|
<if test="avatar != null and avatar != ''">#{avatar},</if>
|
||||||
<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
|
<if test="phonenumber != null and phonenumber != ''">#{phonenumber},</if>
|
||||||
|
<if test="wxopenid != null and wxopenid != ''">#{wxopenid},</if>
|
||||||
<if test="sex != null and sex != ''">#{sex},</if>
|
<if test="sex != null and sex != ''">#{sex},</if>
|
||||||
<if test="password != null and password != ''">#{password},</if>
|
<if test="password != null and password != ''">#{password},</if>
|
||||||
<if test="status != null and status != ''">#{status},</if>
|
<if test="status != null and status != ''">#{status},</if>
|
||||||
|
@ -147,6 +149,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
<if test="nickName != null and nickName != ''">nick_name = #{nickName},</if>
|
||||||
<if test="email != null ">email = #{email},</if>
|
<if test="email != null ">email = #{email},</if>
|
||||||
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
|
<if test="phonenumber != null ">phonenumber = #{phonenumber},</if>
|
||||||
|
<if test="wxopenid != null ">wxopenid = #{wxopenid},</if>
|
||||||
<if test="sex != null and sex != ''">sex = #{sex},</if>
|
<if test="sex != null and sex != ''">sex = #{sex},</if>
|
||||||
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
|
<if test="avatar != null and avatar != ''">avatar = #{avatar},</if>
|
||||||
<if test="password != null and password != ''">password = #{password},</if>
|
<if test="password != null and password != ''">password = #{password},</if>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user