获取openId接口

This commit is contained in:
小魔仙~
2024-12-26 19:05:03 +08:00
parent efd0fa1e44
commit 8ea671775e
25 changed files with 728 additions and 20 deletions

View File

@ -200,6 +200,11 @@ public class Device extends BaseEntity
@ApiModelProperty("设备型号")
private String deviceModel;
/** 测站号 */
/*@Excel(name = "测站号")
@ApiModelProperty("测站号")
private String stationNumber;*/
/**
* 关联组态,来源产品
*/

View File

@ -45,6 +45,8 @@ public class DeviceAllShortOutput
/** wifi信号强度信号极好4格[-55— 0]信号好3格[-70— -55]信号一般2格[-85— -70]信号差1格[-100— -85] */
private Integer rssi;
/** 测站号*/
private String stationNumber;
/** 激活时间 */
@JsonFormat(pattern = "yyyy-MM-dd")

View File

@ -17,6 +17,11 @@ public class DeviceMqttVO {
*/
private String serialNumber;
/**
* 测站号
*/
private String stationNumber;
/**
* 产品id
*/

View File

@ -20,6 +20,9 @@ public class ProductAuthenticateModel implements Serializable {
/** 产品ID */
private Long productId;
/** 测站号 */
private String stationNumber;
/** 产品名称 */
private String productName;

View File

@ -23,6 +23,9 @@ public class ThingsModelValuesOutput
private int isShadow;
//测站号
private String stationNumber;
/** 设备ID **/
private String serialNumber;

View File

@ -97,6 +97,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="tel" column="tel" />
<result property="caretaker" column="caretaker" />
<result property="managementUnit" column="management_unit" />
<result property="managementUnit" column="management_unit" />
</resultMap>
<resultMap type="com.fastbee.iot.model.UserAndTenant" id="UserAndTenantResult">
@ -1015,7 +1016,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
tenant_name=#{tenantName},
longitude=#{longitude},
latitude=#{latitude},
img_url=#{imgUrl}
img_url=#{imgUrl},
where serial_number = #{serialNumber}
</update>

View File

@ -0,0 +1,58 @@
package com.fastbee.rechargecard.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.BaseEntity;
/**
* 灌区对象 ng_Irrigation_area
*
* @author kerwincui
* @date 2024-12-26
*/
@ApiModel(value = "NgIrrigationArea",description = "灌区 ng_Irrigation_area")
@Data
@EqualsAndHashCode(callSuper = true)
public class NgIrrigationArea extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 主键 */
private Long id;
/** 灌区名称 */
@Excel(name = "灌区名称")
@ApiModelProperty("灌区名称")
private String name;
/** 商户号 */
@Excel(name = "商户号")
@ApiModelProperty("商户号")
private String merchantId;
/** 商户api证书序列号 */
@Excel(name = "商户api证书序列号")
@ApiModelProperty("商户api证书序列号")
private String serialNo;
/** 商户apiv3密钥 */
@Excel(name = "商户apiv3密钥")
@ApiModelProperty("商户apiv3密钥")
private String apiv3Key;
/** 微信支付公钥 */
@Excel(name = "微信支付公钥")
@ApiModelProperty("微信支付公钥")
private String publicKey;
/** 商户API私钥 */
@Excel(name = "商户API私钥")
@ApiModelProperty("商户API私钥")
private String privateKey;
}

View File

@ -0,0 +1,61 @@
package com.fastbee.rechargecard.mapper;
import java.util.List;
import com.fastbee.rechargecard.domain.NgIrrigationArea;
/**
* 灌区Mapper接口
*
* @author kerwincui
* @date 2024-12-26
*/
public interface NgIrrigationAreaMapper
{
/**
* 查询灌区
*
* @param id 灌区主键
* @return 灌区
*/
public NgIrrigationArea selectNgIrrigationAreaById(Long id);
/**
* 查询灌区列表
*
* @param ngIrrigationArea 灌区
* @return 灌区集合
*/
public List<NgIrrigationArea> selectNgIrrigationAreaList(NgIrrigationArea ngIrrigationArea);
/**
* 新增灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
public int insertNgIrrigationArea(NgIrrigationArea ngIrrigationArea);
/**
* 修改灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
public int updateNgIrrigationArea(NgIrrigationArea ngIrrigationArea);
/**
* 删除灌区
*
* @param id 灌区主键
* @return 结果
*/
public int deleteNgIrrigationAreaById(Long id);
/**
* 批量删除灌区
*
* @param ids 需要删除的数据主键集合
* @return 结果
*/
public int deleteNgIrrigationAreaByIds(Long[] ids);
}

View File

@ -5,6 +5,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fastbee.rechargecard.domain.NgWaterPumpUsageRecords;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
/**
* 水泵设备使用记录Mapper接口
@ -23,6 +24,14 @@ public interface NgWaterPumpUsageRecordsMapper extends BaseMapper<NgWaterPumpUsa
*/
public NgWaterPumpUsageRecords selectNgWaterPumpUsageRecordsById(Long id);
/**
* 查询水泵设备最细实时数据
* @param deviceNumber 水泵设备编码
* @return 水泵设备使用记录
*/
@Select("SELECT * FROM ng_water_pump_usage_records WHERE" +
" device_number=#{deviceNumber} ORDER BY pump_start_time DESC LIMIT 1")
public NgWaterPumpUsageRecords selectNgWaterPumpUsageDeviceNumber(String deviceNumber);
/**
* 查询水泵设备使用记录列表
*

View File

@ -0,0 +1,61 @@
package com.fastbee.rechargecard.service;
import java.util.List;
import com.fastbee.rechargecard.domain.NgIrrigationArea;
/**
* 灌区Service接口
*
* @author kerwincui
* @date 2024-12-26
*/
public interface INgIrrigationAreaService
{
/**
* 查询灌区
*
* @param id 灌区主键
* @return 灌区
*/
public NgIrrigationArea selectNgIrrigationAreaById(Long id);
/**
* 查询灌区列表
*
* @param ngIrrigationArea 灌区
* @return 灌区集合
*/
public List<NgIrrigationArea> selectNgIrrigationAreaList(NgIrrigationArea ngIrrigationArea);
/**
* 新增灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
public int insertNgIrrigationArea(NgIrrigationArea ngIrrigationArea);
/**
* 修改灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
public int updateNgIrrigationArea(NgIrrigationArea ngIrrigationArea);
/**
* 批量删除灌区
*
* @param ids 需要删除的灌区主键集合
* @return 结果
*/
public int deleteNgIrrigationAreaByIds(Long[] ids);
/**
* 删除灌区信息
*
* @param id 灌区主键
* @return 结果
*/
public int deleteNgIrrigationAreaById(Long id);
}

View File

@ -1,5 +1,6 @@
package com.fastbee.rechargecard.service;
import java.util.HashMap;
import java.util.List;
import com.fastbee.rechargecard.domain.NgWaterPumpUsageRecords;
@ -18,7 +19,12 @@ public interface INgWaterPumpUsageRecordsService
* @return 水泵设备使用记录
*/
public NgWaterPumpUsageRecords selectNgWaterPumpUsageRecordsById(Long id);
/**
* 查询水泵设备最细实时数据
* @param deviceNumber 水泵设备编码
* @return 水泵设备使用记录
*/
public HashMap<String,Object> selectNgWaterPumpUsageDeviceNumber(String deviceNumber);
/**
* 查询水泵设备使用记录列表
*

View File

@ -16,4 +16,12 @@ public interface IUserWechatPayService {
* @return
*/
public Map<String,String> CreateOrder(WeChatRecharge recharge) throws Exception;
/**
* 获取openId
* @param code
* @return
*/
public Map<String,Object> GetOpenId(String code);
}

View File

@ -0,0 +1,93 @@
package com.fastbee.rechargecard.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.rechargecard.mapper.NgIrrigationAreaMapper;
import com.fastbee.rechargecard.domain.NgIrrigationArea;
import com.fastbee.rechargecard.service.INgIrrigationAreaService;
/**
* 灌区Service业务层处理
*
* @author kerwincui
* @date 2024-12-26
*/
@Service
public class NgIrrigationAreaServiceImpl implements INgIrrigationAreaService
{
@Autowired
private NgIrrigationAreaMapper ngIrrigationAreaMapper;
/**
* 查询灌区
*
* @param id 灌区主键
* @return 灌区
*/
@Override
public NgIrrigationArea selectNgIrrigationAreaById(Long id)
{
return ngIrrigationAreaMapper.selectNgIrrigationAreaById(id);
}
/**
* 查询灌区列表
*
* @param ngIrrigationArea 灌区
* @return 灌区
*/
@Override
public List<NgIrrigationArea> selectNgIrrigationAreaList(NgIrrigationArea ngIrrigationArea)
{
return ngIrrigationAreaMapper.selectNgIrrigationAreaList(ngIrrigationArea);
}
/**
* 新增灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
@Override
public int insertNgIrrigationArea(NgIrrigationArea ngIrrigationArea)
{
return ngIrrigationAreaMapper.insertNgIrrigationArea(ngIrrigationArea);
}
/**
* 修改灌区
*
* @param ngIrrigationArea 灌区
* @return 结果
*/
@Override
public int updateNgIrrigationArea(NgIrrigationArea ngIrrigationArea)
{
return ngIrrigationAreaMapper.updateNgIrrigationArea(ngIrrigationArea);
}
/**
* 批量删除灌区
*
* @param ids 需要删除的灌区主键
* @return 结果
*/
@Override
public int deleteNgIrrigationAreaByIds(Long[] ids)
{
return ngIrrigationAreaMapper.deleteNgIrrigationAreaByIds(ids);
}
/**
* 删除灌区信息
*
* @param id 灌区主键
* @return 结果
*/
@Override
public int deleteNgIrrigationAreaById(Long id)
{
return ngIrrigationAreaMapper.deleteNgIrrigationAreaById(id);
}
}

View File

@ -1,6 +1,14 @@
package com.fastbee.rechargecard.service.impl;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fastbee.common.utils.json.JsonStrUtil;
import com.fastbee.common.utils.json.JsonUtils;
import com.fastbee.iot.mapper.DeviceMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.rechargecard.mapper.NgWaterPumpUsageRecordsMapper;
@ -19,6 +27,8 @@ public class NgWaterPumpUsageRecordsServiceImpl implements INgWaterPumpUsageReco
@Autowired
private NgWaterPumpUsageRecordsMapper ngWaterPumpUsageRecordsMapper;
@Autowired
private DeviceMapper deviceMapper;
/**
* 查询水泵设备使用记录
*
@ -31,6 +41,43 @@ public class NgWaterPumpUsageRecordsServiceImpl implements INgWaterPumpUsageReco
return ngWaterPumpUsageRecordsMapper.selectNgWaterPumpUsageRecordsById(id);
}
/**
* 查询水泵设备最细实时数据
* @param deviceNumber 水泵设备编码
* @return 水泵设备使用记录
*/
@Override
public HashMap<String,Object> selectNgWaterPumpUsageDeviceNumber(String deviceNumber)
{
NgWaterPumpUsageRecords result = ngWaterPumpUsageRecordsMapper.selectNgWaterPumpUsageDeviceNumber(deviceNumber);
NgWaterPumpUsageRecords ngWaterPumpUsageRecords = new NgWaterPumpUsageRecords();
System.err.println(result);
HashMap<String,Object> map = new HashMap<String,Object>();
if (result != null) {
String message= result.getMessageContent();
JSONObject jsonObject1 = JSONUtil.parseObj(message);
String jsonStr = jsonObject1.getStr("data");
JSONObject jsonObject2 = JSONUtil.parseObj(jsonStr);
if (jsonObject2.getStr("meterIns")!=null){
map.put("meterIns",jsonObject2.getStr("meterIns"));
}else {
map.put("meterIns",0);
}
if (jsonObject2.getStr("meterSum")!=null){
map.put("meterSum",jsonObject2.getStr("meterSum"));
}else {
map.put("meterSum",0);
}
System.err.println(jsonStr);
return map;
} else {
map.put("meterIns",0);
map.put("meterSum",0);
return map;
}
}
/**
* 查询水泵设备使用记录列表
*

View File

@ -9,37 +9,47 @@ import com.fastbee.rechargecard.service.IUserConsumptionDetailsService;
import com.fastbee.rechargecard.service.IUserRechargeCardsService;
import com.fastbee.rechargecard.service.IUserWechatPayService;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.security.PrivateKey;
import java.security.Signature;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.*;
@Service
public class UserWechatPayServiceImpl implements IUserWechatPayService {
/** 商户号 */
public static String mchId = "1531795301";
//public static String mchId = "1531795301";
public static String mchId = "1503198881";
/** 商户API私钥文件路径 */
public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/apiclient_key.pem";
//public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/apiclient_key.pem";
public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_apiclient_key.pem";
/** 商户API证书序列号 */
public static String serial_no = "3075B63EF52666EDC3EAFC5D4FB35C02CE123A9C";
//public static String serial_no = "3075B63EF52666EDC3EAFC5D4FB35C02CE123A9C";
public static String serial_no = "7A55F5763A002C749F1AB10E1D52DE6688DCDDC0";
/** 商户APIV3密钥 */
public static String apiV3Key = "e85a203e8ca146102f5cd7ecff912580";
//public static String apiV3Key = "e85a203e8ca146102f5cd7ecff912580";
public static String apiV3Key = "damogangguanqunongcunyunshuizhex";
//微信小程序appid
public static String appId="wx308612d2a8423311";
//微信小程序appSecret
public static String appSecret="7f591f559929a3bf2dbea4e156b08ae9";
//微信支付公钥地址
public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
//public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
//public static String publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
//支付结果回调地址
public static String notify_url="https://3e744f6.r3.cpolar.cn/pay/getresult";//https://3e744f6.r3.cpolar.cn
@Override
/**
* 创建订单获取prepay_id和paySign
@ -192,4 +202,39 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
sign.update(message);
return Base64.getEncoder().encodeToString(sign.sign());
}
/**
* 获取openId
* @param code
* @return
*/
@Override
public Map<String, Object> GetOpenId(String code)
{
System.out.println(code);
//String url = String.format("https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code", appId, appSecret, code);
//String url="https://api.weixin.qq.com/sns/oauth2/access_token?appid="+appId+"&secret="+appSecret+"&code="+code+"&grant_type=authorization_code";
String url="https://api.weixin.qq.com/sns/jscode2session?appid="+appId+"&secret="+appSecret+"&js_code="+code+"&grant_type=authorization_code";
RestTemplate restTemplate = new RestTemplate();
Map<String, String> response = restTemplate.getForObject(url, Map.class);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(url);
try (CloseableHttpResponse response2 = httpClient.execute(httpGet)) {
String responseString = EntityUtils.toString(response2.getEntity());
Map<String, Object> responseMap = JSONUtil.toBean(responseString, Map.class);
//打印出返回前端的所有参数
// 获取键的集合
Set<String> keySet = responseMap.keySet();
// 遍历键集合
for (String key : keySet) {
System.out.println(key + ": " + responseMap.get(key));
}
// 解析responseString以获取openid
return responseMap; // 这里返回的是整个响应字符串需要自行解析出openid
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fastbee.rechargecard.mapper.NgIrrigationAreaMapper">
<resultMap type="NgIrrigationArea" id="NgIrrigationAreaResult">
<result property="id" column="id" />
<result property="name" column="name" />
<result property="merchantId" column="merchant_id" />
<result property="serialNo" column="serial_no" />
<result property="apiv3Key" column="apiv3_key" />
<result property="publicKey" column="public_key" />
<result property="privateKey" column="private_key" />
</resultMap>
<sql id="selectNgIrrigationAreaVo">
select id, name, merchant_id, serial_no, apiv3_key, public_key, private_key from ng_Irrigation_area
</sql>
<select id="selectNgIrrigationAreaList" parameterType="NgIrrigationArea" resultMap="NgIrrigationAreaResult">
<include refid="selectNgIrrigationAreaVo"/>
<where>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="merchantId != null and merchantId != ''"> and merchant_id = #{merchantId}</if>
<if test="serialNo != null and serialNo != ''"> and serial_no = #{serialNo}</if>
<if test="apiv3Key != null and apiv3Key != ''"> and apiv3_key = #{apiv3Key}</if>
<if test="publicKey != null and publicKey != ''"> and public_key = #{publicKey}</if>
<if test="privateKey != null and privateKey != ''"> and private_key = #{privateKey}</if>
</where>
</select>
<select id="selectNgIrrigationAreaById" parameterType="Long" resultMap="NgIrrigationAreaResult">
<include refid="selectNgIrrigationAreaVo"/>
where id = #{id}
</select>
<insert id="insertNgIrrigationArea" parameterType="NgIrrigationArea" useGeneratedKeys="true" keyProperty="id">
insert into ng_Irrigation_area
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">name,</if>
<if test="merchantId != null">merchant_id,</if>
<if test="serialNo != null">serial_no,</if>
<if test="apiv3Key != null">apiv3_key,</if>
<if test="publicKey != null">public_key,</if>
<if test="privateKey != null">private_key,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">#{name},</if>
<if test="merchantId != null">#{merchantId},</if>
<if test="serialNo != null">#{serialNo},</if>
<if test="apiv3Key != null">#{apiv3Key},</if>
<if test="publicKey != null">#{publicKey},</if>
<if test="privateKey != null">#{privateKey},</if>
</trim>
</insert>
<update id="updateNgIrrigationArea" parameterType="NgIrrigationArea">
update ng_Irrigation_area
<trim prefix="SET" suffixOverrides=",">
<if test="name != null">name = #{name},</if>
<if test="merchantId != null">merchant_id = #{merchantId},</if>
<if test="serialNo != null">serial_no = #{serialNo},</if>
<if test="apiv3Key != null">apiv3_key = #{apiv3Key},</if>
<if test="publicKey != null">public_key = #{publicKey},</if>
<if test="privateKey != null">private_key = #{privateKey},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteNgIrrigationAreaById" parameterType="Long">
delete from ng_Irrigation_area where id = #{id}
</delete>
<delete id="deleteNgIrrigationAreaByIds" parameterType="String">
delete from ng_Irrigation_area where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -259,8 +259,13 @@ public class SysDeptServiceImpl implements ISysDeptService
}
//设置祖级别列表
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
//设置项目id
dept.setProjectId(Long.valueOf(ProjectHolder.getProjectInfo().getProjectId()));
String projectIdStr = ProjectHolder.getProjectInfo().getProjectId();
if (projectIdStr != null && !projectIdStr.isEmpty()) {
dept.setProjectId(Long.valueOf(projectIdStr));
}
//dept.setProjectId(Long.valueOf(ProjectHolder.getProjectInfo().getProjectId()));
//处理机构所管理行政区划信息
parseAdministrativeDivisionInfo(dept);
dept.setCreateTime(DateUtils.getNowDate());