修改获取平台证书接口;创建设备操作日志表
This commit is contained in:
@ -115,14 +115,7 @@ sip:
|
|||||||
id: 34020000002000000001 # 同上,另外增加编号,(可保持默认)
|
id: 34020000002000000001 # 同上,另外增加编号,(可保持默认)
|
||||||
password: 12345678 # 监控设备接入的密码
|
password: 12345678 # 监控设备接入的密码
|
||||||
|
|
||||||
#微信支付
|
|
||||||
wx:
|
|
||||||
pay:
|
|
||||||
appId: wx308612d2a8423311 #微信公众号或者小程序等的appid
|
|
||||||
secret: 7f591f559929a3bf2dbea4e156b08ae9
|
|
||||||
mchId: #微信支付商户号
|
|
||||||
mchKey: #微信支付商户密钥
|
|
||||||
notifyUrl: http://192.168.1.5:13088/pay/wxCallback #支付回调地址
|
|
||||||
|
|
||||||
# 日志配置
|
# 日志配置
|
||||||
logging:
|
logging:
|
||||||
|
@ -176,3 +176,11 @@ http: # 最大连接数
|
|||||||
socketTimeout: 10000
|
socketTimeout: 10000
|
||||||
# 提交请求前测试连接是否可用
|
# 提交请求前测试连接是否可用
|
||||||
staleConnectionCheckEnabled: true
|
staleConnectionCheckEnabled: true
|
||||||
|
|
||||||
|
#微信支付
|
||||||
|
wx:
|
||||||
|
pay:
|
||||||
|
appId: "wx308612d2a8423311" #微信公众号或者小程序等的appid
|
||||||
|
appSecret: "7f591f559929a3bf2dbea4e156b08ae9"
|
||||||
|
notify_url: "https://farmh5.hze2.com/prod-api/pay/getresult" #生产环境支付回调地址
|
||||||
|
#notifyUrl: https://3ffb1c5f.r3.cpolar.cn/pay/getresult #开发环境支付回掉地址
|
||||||
|
@ -55,7 +55,7 @@ public class DeviceOtherMsgConsumer {
|
|||||||
public void consume(DeviceReportBo bo){
|
public void consume(DeviceReportBo bo){
|
||||||
try {
|
try {
|
||||||
//处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理
|
//处理emq订阅的非 property/post 属性上报的消息 ,因为其他消息量小,放在一起处理
|
||||||
Long productId;//产品id
|
Long productId;//产品id,设备所属产品
|
||||||
Long packetId;//包号
|
Long packetId;//包号
|
||||||
byte[] data = bo.getData();//数据
|
byte[] data = bo.getData();//数据
|
||||||
String topic=bo.getTopicName();//主题
|
String topic=bo.getTopicName();//主题
|
||||||
@ -70,13 +70,13 @@ public class DeviceOtherMsgConsumer {
|
|||||||
if(topic.endsWith("/info/up")){
|
if(topic.endsWith("/info/up")){
|
||||||
deviceDataReportHandler(new String(data));
|
deviceDataReportHandler(new String(data));
|
||||||
//更新设备在线状态
|
//更新设备在线状态
|
||||||
updateDeviceOnlineStatus( productId,serialNumber);
|
updateDeviceOnlineStatus( productId,serialNumber);//拼成一个唯一的key,只要key存在,则设备在线
|
||||||
// updateDeviceOnlineStatusDb(serialNumber);
|
// updateDeviceOnlineStatusDb(serialNumber);
|
||||||
//保存使用记录
|
//保存使用记录
|
||||||
NgWaterPumpUsageRecords pumpUsageRecords=new NgWaterPumpUsageRecords();
|
NgWaterPumpUsageRecords pumpUsageRecords=new NgWaterPumpUsageRecords();
|
||||||
pumpUsageRecords.setDeviceNumber(serialNumber);
|
pumpUsageRecords.setDeviceNumber(serialNumber);
|
||||||
JSONObject jsonObject = JSONUtil.parseObj(data);
|
JSONObject jsonObject = JSONUtil.parseObj(data);
|
||||||
jsonObject.set("time", (LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));
|
jsonObject.set("time", (LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))));//收到消息的当地时间
|
||||||
if(jsonObject.getStr("type")!=null){
|
if(jsonObject.getStr("type")!=null){
|
||||||
if(jsonObject.getStr("type").equals("waterEleData")){
|
if(jsonObject.getStr("type").equals("waterEleData")){
|
||||||
String data1 = jsonObject.getStr("data");
|
String data1 = jsonObject.getStr("data");
|
||||||
|
@ -0,0 +1,110 @@
|
|||||||
|
package com.fastbee.data.controller.deviceOperationRecords;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.fastbee.common.annotation.Log;
|
||||||
|
import com.fastbee.common.core.controller.BaseController;
|
||||||
|
import com.fastbee.common.core.domain.AjaxResult;
|
||||||
|
import com.fastbee.common.enums.BusinessType;
|
||||||
|
import com.fastbee.iot.domain.NgDeviceOperationRecords;
|
||||||
|
import com.fastbee.iot.service.INgDeviceOperationRecordsService;
|
||||||
|
import com.fastbee.common.utils.poi.ExcelUtil;
|
||||||
|
import com.fastbee.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备操作记录Controller
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2024-12-30
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/iot/records")
|
||||||
|
@Api(tags = "设备操作记录")
|
||||||
|
public class NgDeviceOperationRecordsController extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private INgDeviceOperationRecordsService ngDeviceOperationRecordsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:list')")
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("查询设备操作记录列表")
|
||||||
|
public TableDataInfo list(NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<NgDeviceOperationRecords> list = ngDeviceOperationRecordsService.selectNgDeviceOperationRecordsList(ngDeviceOperationRecords);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出设备操作记录列表
|
||||||
|
*/
|
||||||
|
@ApiOperation("导出设备操作记录列表")
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:export')")
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
List<NgDeviceOperationRecords> list = ngDeviceOperationRecordsService.selectNgDeviceOperationRecordsList(ngDeviceOperationRecords);
|
||||||
|
ExcelUtil<NgDeviceOperationRecords> util = new ExcelUtil<NgDeviceOperationRecords>(NgDeviceOperationRecords.class);
|
||||||
|
util.exportExcel(response, list, "设备操作记录数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取设备操作记录详细信息
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:query')")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
@ApiOperation("获取设备操作记录详细信息")
|
||||||
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||||
|
{
|
||||||
|
return success(ngDeviceOperationRecordsService.selectNgDeviceOperationRecordsById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备操作记录
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:add')")
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增设备操作记录")
|
||||||
|
public AjaxResult add(@RequestBody NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
return toAjax(ngDeviceOperationRecordsService.insertNgDeviceOperationRecords(ngDeviceOperationRecords));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备操作记录
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:edit')")
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改设备操作记录")
|
||||||
|
public AjaxResult edit(@RequestBody NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
return toAjax(ngDeviceOperationRecordsService.updateNgDeviceOperationRecords(ngDeviceOperationRecords));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备操作记录
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('iot:records:remove')")
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
@ApiOperation("删除设备操作记录")
|
||||||
|
public AjaxResult remove(@PathVariable Long[] ids)
|
||||||
|
{
|
||||||
|
return toAjax(ngDeviceOperationRecordsService.deleteNgDeviceOperationRecordsByIds(ids));
|
||||||
|
}
|
||||||
|
}
|
@ -81,12 +81,12 @@ public class WeChatPayController extends BaseController {
|
|||||||
* 获取平台证书
|
* 获取平台证书
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
/*@ApiOperation("获取平台证书")
|
@ApiOperation("获取平台证书")
|
||||||
@GetMapping("/getPlatformCertificate")
|
@GetMapping("/getPlatformCertificate")
|
||||||
public AjaxResult getPlatformCertificate()
|
public AjaxResult getPlatformCertificate(@RequestBody String mchId,@RequestBody String privateKey,@RequestBody String serial_no,@RequestBody String apiV3Key)
|
||||||
{
|
{
|
||||||
return success(userWechatPayService.getPlatformCertificat());
|
return success(userWechatPayService.getPlatformCertificat(mchId,privateKey,serial_no,apiV3Key));
|
||||||
}*/
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取openId
|
* 获取openId
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
package com.fastbee.iot.domain;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
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_device_operation_records
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2024-12-30
|
||||||
|
*/
|
||||||
|
@ApiModel(value = "NgDeviceOperationRecords",description = "设备操作记录 ng_device_operation_records")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class NgDeviceOperationRecords extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 主键自增 */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 用户id */
|
||||||
|
@Excel(name = "用户id")
|
||||||
|
@ApiModelProperty("用户id")
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/** 机构id */
|
||||||
|
@Excel(name = "机构id")
|
||||||
|
@ApiModelProperty("机构id")
|
||||||
|
private Long deptId;
|
||||||
|
|
||||||
|
/** 操作报文内容 */
|
||||||
|
@Excel(name = "操作报文内容")
|
||||||
|
@ApiModelProperty("操作报文内容")
|
||||||
|
private String operationMessage;
|
||||||
|
|
||||||
|
/** cmd的值如700,110 */
|
||||||
|
@Excel(name = "cmd的值如700,110")
|
||||||
|
@ApiModelProperty("cmd的值如700,110")
|
||||||
|
private Long operationType;
|
||||||
|
|
||||||
|
/** 操作内容,如开阀/关阀 */
|
||||||
|
@Excel(name = "操作内容,如开阀/关阀")
|
||||||
|
@ApiModelProperty("操作内容,如开阀/关阀")
|
||||||
|
private String operationContent;
|
||||||
|
|
||||||
|
/** 操作时间 */
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
@Excel(name = "操作时间", width = 30, dateFormat = "yyyy-MM-dd")
|
||||||
|
@ApiModelProperty("操作时间")
|
||||||
|
private Date operationTime;
|
||||||
|
|
||||||
|
/** 0=成功,1=失败 */
|
||||||
|
@Excel(name = "0=成功,1=失败")
|
||||||
|
@ApiModelProperty("0=成功,1=失败")
|
||||||
|
private Integer operationResult;
|
||||||
|
|
||||||
|
/** 失败原因 */
|
||||||
|
@Excel(name = "失败原因")
|
||||||
|
@ApiModelProperty("失败原因")
|
||||||
|
private String failureReason;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.fastbee.iot.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.fastbee.iot.domain.NgDeviceOperationRecords;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备操作记录Mapper接口
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2024-12-30
|
||||||
|
*/
|
||||||
|
@Repository
|
||||||
|
public interface NgDeviceOperationRecordsMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 设备操作记录
|
||||||
|
*/
|
||||||
|
public NgDeviceOperationRecords selectNgDeviceOperationRecordsById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录列表
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 设备操作记录集合
|
||||||
|
*/
|
||||||
|
public List<NgDeviceOperationRecords> selectNgDeviceOperationRecordsList(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备操作记录
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteNgDeviceOperationRecordsById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除设备操作记录
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteNgDeviceOperationRecordsByIds(Long[] ids);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.fastbee.iot.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.fastbee.iot.domain.NgDeviceOperationRecords;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备操作记录Service接口
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2024-12-30
|
||||||
|
*/
|
||||||
|
public interface INgDeviceOperationRecordsService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 设备操作记录
|
||||||
|
*/
|
||||||
|
public NgDeviceOperationRecords selectNgDeviceOperationRecordsById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录列表
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 设备操作记录集合
|
||||||
|
*/
|
||||||
|
public List<NgDeviceOperationRecords> selectNgDeviceOperationRecordsList(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除设备操作记录
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的设备操作记录主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteNgDeviceOperationRecordsByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备操作记录信息
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteNgDeviceOperationRecordsById(Long id);
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.fastbee.iot.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.fastbee.common.utils.DateUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.fastbee.iot.mapper.NgDeviceOperationRecordsMapper;
|
||||||
|
import com.fastbee.iot.domain.NgDeviceOperationRecords;
|
||||||
|
import com.fastbee.iot.service.INgDeviceOperationRecordsService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设备操作记录Service业务层处理
|
||||||
|
*
|
||||||
|
* @author kerwincui
|
||||||
|
* @date 2024-12-30
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class NgDeviceOperationRecordsServiceImpl implements INgDeviceOperationRecordsService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private NgDeviceOperationRecordsMapper ngDeviceOperationRecordsMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 设备操作记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public NgDeviceOperationRecords selectNgDeviceOperationRecordsById(Long id)
|
||||||
|
{
|
||||||
|
return ngDeviceOperationRecordsMapper.selectNgDeviceOperationRecordsById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询设备操作记录列表
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 设备操作记录
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<NgDeviceOperationRecords> selectNgDeviceOperationRecordsList(NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
return ngDeviceOperationRecordsMapper.selectNgDeviceOperationRecordsList(ngDeviceOperationRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insertNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
ngDeviceOperationRecords.setCreateTime(DateUtils.getNowDate());
|
||||||
|
return ngDeviceOperationRecordsMapper.insertNgDeviceOperationRecords(ngDeviceOperationRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备操作记录
|
||||||
|
*
|
||||||
|
* @param ngDeviceOperationRecords 设备操作记录
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateNgDeviceOperationRecords(NgDeviceOperationRecords ngDeviceOperationRecords)
|
||||||
|
{
|
||||||
|
ngDeviceOperationRecords.setUpdateTime(DateUtils.getNowDate());
|
||||||
|
return ngDeviceOperationRecordsMapper.updateNgDeviceOperationRecords(ngDeviceOperationRecords);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除设备操作记录
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的设备操作记录主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteNgDeviceOperationRecordsByIds(Long[] ids)
|
||||||
|
{
|
||||||
|
return ngDeviceOperationRecordsMapper.deleteNgDeviceOperationRecordsByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除设备操作记录信息
|
||||||
|
*
|
||||||
|
* @param id 设备操作记录主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteNgDeviceOperationRecordsById(Long id)
|
||||||
|
{
|
||||||
|
return ngDeviceOperationRecordsMapper.deleteNgDeviceOperationRecordsById(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,111 @@
|
|||||||
|
<?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.iot.mapper.NgDeviceOperationRecordsMapper">
|
||||||
|
|
||||||
|
<resultMap type="NgDeviceOperationRecords" id="NgDeviceOperationRecordsResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="userId" column="user_id" />
|
||||||
|
<result property="deptId" column="dept_id" />
|
||||||
|
<result property="operationMessage" column="operation_message" />
|
||||||
|
<result property="operationType" column="operation_type" />
|
||||||
|
<result property="operationContent" column="operation_content" />
|
||||||
|
<result property="operationTime" column="operation_time" />
|
||||||
|
<result property="operationResult" column="operation_result" />
|
||||||
|
<result property="failureReason" column="failure_reason" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
<result property="createTime" column="create_time" />
|
||||||
|
<result property="updateTime" column="update_time" />
|
||||||
|
<result property="createBy" column="create_by" />
|
||||||
|
<result property="updateBy" column="update_by" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectNgDeviceOperationRecordsVo">
|
||||||
|
select id, user_id, dept_id, operation_message, operation_type, operation_content, operation_time, operation_result, failure_reason, remark, create_time, update_time, create_by, update_by from ng_device_operation_records
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectNgDeviceOperationRecordsList" parameterType="NgDeviceOperationRecords" resultMap="NgDeviceOperationRecordsResult">
|
||||||
|
<include refid="selectNgDeviceOperationRecordsVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="userId != null "> and user_id = #{userId}</if>
|
||||||
|
<if test="deptId != null "> and dept_id = #{deptId}</if>
|
||||||
|
<if test="operationMessage != null and operationMessage != ''"> and operation_message = #{operationMessage}</if>
|
||||||
|
<if test="operationType != null "> and operation_type = #{operationType}</if>
|
||||||
|
<if test="operationContent != null and operationContent != ''"> and operation_content = #{operationContent}</if>
|
||||||
|
<if test="operationTime != null "> and operation_time = #{operationTime}</if>
|
||||||
|
<if test="operationResult != null "> and operation_result = #{operationResult}</if>
|
||||||
|
<if test="failureReason != null and failureReason != ''"> and failure_reason = #{failureReason}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectNgDeviceOperationRecordsById" parameterType="Long" resultMap="NgDeviceOperationRecordsResult">
|
||||||
|
<include refid="selectNgDeviceOperationRecordsVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertNgDeviceOperationRecords" parameterType="NgDeviceOperationRecords" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into ng_device_operation_records
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="userId != null">user_id,</if>
|
||||||
|
<if test="deptId != null">dept_id,</if>
|
||||||
|
<if test="operationMessage != null">operation_message,</if>
|
||||||
|
<if test="operationType != null">operation_type,</if>
|
||||||
|
<if test="operationContent != null">operation_content,</if>
|
||||||
|
<if test="operationTime != null">operation_time,</if>
|
||||||
|
<if test="operationResult != null">operation_result,</if>
|
||||||
|
<if test="failureReason != null">failure_reason,</if>
|
||||||
|
<if test="remark != null">remark,</if>
|
||||||
|
<if test="createTime != null">create_time,</if>
|
||||||
|
<if test="updateTime != null">update_time,</if>
|
||||||
|
<if test="createBy != null">create_by,</if>
|
||||||
|
<if test="updateBy != null">update_by,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="userId != null">#{userId},</if>
|
||||||
|
<if test="deptId != null">#{deptId},</if>
|
||||||
|
<if test="operationMessage != null">#{operationMessage},</if>
|
||||||
|
<if test="operationType != null">#{operationType},</if>
|
||||||
|
<if test="operationContent != null">#{operationContent},</if>
|
||||||
|
<if test="operationTime != null">#{operationTime},</if>
|
||||||
|
<if test="operationResult != null">#{operationResult},</if>
|
||||||
|
<if test="failureReason != null">#{failureReason},</if>
|
||||||
|
<if test="remark != null">#{remark},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
<if test="createBy != null">#{createBy},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateNgDeviceOperationRecords" parameterType="NgDeviceOperationRecords">
|
||||||
|
update ng_device_operation_records
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="userId != null">user_id = #{userId},</if>
|
||||||
|
<if test="deptId != null">dept_id = #{deptId},</if>
|
||||||
|
<if test="operationMessage != null">operation_message = #{operationMessage},</if>
|
||||||
|
<if test="operationType != null">operation_type = #{operationType},</if>
|
||||||
|
<if test="operationContent != null">operation_content = #{operationContent},</if>
|
||||||
|
<if test="operationTime != null">operation_time = #{operationTime},</if>
|
||||||
|
<if test="operationResult != null">operation_result = #{operationResult},</if>
|
||||||
|
<if test="failureReason != null">failure_reason = #{failureReason},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteNgDeviceOperationRecordsById" parameterType="Long">
|
||||||
|
delete from ng_device_operation_records where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteNgDeviceOperationRecordsByIds" parameterType="String">
|
||||||
|
delete from ng_device_operation_records where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.fastbee.rechargecard.domain.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WeChatPlatformCertificate {
|
||||||
|
private String mchId;//商户号
|
||||||
|
private String privateKey;//商户api证书私钥
|
||||||
|
private String serial_no;//商户api证书序列号
|
||||||
|
private String apiV3Key;//商户apiv3Key
|
||||||
|
}
|
@ -25,7 +25,7 @@ public interface IUserWechatPayService {
|
|||||||
/**
|
/**
|
||||||
* 获取平台证书
|
* 获取平台证书
|
||||||
*/
|
*/
|
||||||
//public Map<String,Object> getPlatformCertificat();
|
public Map<String,Object> getPlatformCertificat(String mchId,String privateKey,String serial_no,String apiV3Key);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,9 +8,6 @@ import com.fastbee.common.utils.pay.wxPayConfig;
|
|||||||
import com.fastbee.rechargecard.domain.NgMerchants;
|
import com.fastbee.rechargecard.domain.NgMerchants;
|
||||||
import com.fastbee.rechargecard.domain.dto.WeChatRecharge;
|
import com.fastbee.rechargecard.domain.dto.WeChatRecharge;
|
||||||
import com.fastbee.rechargecard.mapper.NgMerchantsMapper;
|
import com.fastbee.rechargecard.mapper.NgMerchantsMapper;
|
||||||
import com.fastbee.rechargecard.service.INgUserRechargeRecordsService;
|
|
||||||
import com.fastbee.rechargecard.service.IUserConsumptionDetailsService;
|
|
||||||
import com.fastbee.rechargecard.service.IUserRechargeCardsService;
|
|
||||||
import com.fastbee.rechargecard.service.IUserWechatPayService;
|
import com.fastbee.rechargecard.service.IUserWechatPayService;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
@ -21,10 +18,7 @@ import org.apache.http.impl.client.HttpClientBuilder;
|
|||||||
import org.apache.http.impl.client.HttpClients;
|
import org.apache.http.impl.client.HttpClients;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
|
||||||
import org.springframework.http.ResponseEntity;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.client.RestTemplate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -35,38 +29,43 @@ import java.util.*;
|
|||||||
@Service
|
@Service
|
||||||
public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private NgMerchantsMapper ngMerchantsMapper;
|
||||||
|
|
||||||
/** 商户号 */
|
/** 商户号 */
|
||||||
//public static String mchId = "1531795301";
|
//public static String mchId = "1531795301";
|
||||||
public static String mchId = "1503198881";
|
//public static String mchId = "1503198881";
|
||||||
/** 商户API私钥文件路径 */
|
/** 商户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";
|
// public static String privateKeyPath = "fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_apiclient_key.pem";
|
||||||
//TODO 生产环境私钥路径
|
//TODO 生产环境私钥路径
|
||||||
//public static String privateKeyPath = "/home/soft/hzwmiot/fastbee-admin/target/damogang_apiclient_key.pem";
|
//public static String privateKeyPath = "/home/soft/hzwmiot/fastbee-admin/target/damogang_apiclient_key.pem";
|
||||||
@Autowired
|
|
||||||
private NgMerchantsMapper ngMerchantsMapper;
|
|
||||||
|
|
||||||
/** 商户API证书序列号 */
|
/** 商户API证书序列号 */
|
||||||
//public static String serial_no = "3075B63EF52666EDC3EAFC5D4FB35C02CE123A9C";
|
//public static String serial_no = "3075B63EF52666EDC3EAFC5D4FB35C02CE123A9C";
|
||||||
public static String serial_no = "7A55F5763A002C749F1AB10E1D52DE6688DCDDC0";
|
// public static String serial_no = "7A55F5763A002C749F1AB10E1D52DE6688DCDDC0";
|
||||||
/** 商户APIV3密钥 */
|
/** 商户APIV3密钥 */
|
||||||
//public static String apiV3Key = "e85a203e8ca146102f5cd7ecff912580";
|
//public static String apiV3Key = "e85a203e8ca146102f5cd7ecff912580";
|
||||||
public static String apiV3Key = "damogangguanqunongcunyunshuizhex";
|
// 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 publicKeyPath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/wechat_public_key.pem";
|
||||||
//平台证书地址
|
//平台证书地址
|
||||||
public static String platformCertificatePath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_platformCertificate.pem";
|
// public static String platformCertificatePath="fastbee-common/src/main/java/com/fastbee/common/utils/pay/damogang_platformCertificate.pem";
|
||||||
|
|
||||||
//支付结果回调地址
|
//支付结果回调地址
|
||||||
// public static String notify_url="https://3ffb1c5f.r3.cpolar.cn/pay/getresult";//https://3ffb1c5f.r3.cpolar.cn
|
// public static String notify_url="https://3ffb1c5f.r3.cpolar.cn/pay/getresult";//https://3ffb1c5f.r3.cpolar.cn
|
||||||
//TODO 生产环境支付结果异步通知地址
|
//TODO 生产环境支付结果异步通知地址
|
||||||
public static String notify_url="https://farmh5.hze2.com/prod-api/pay/getresult";
|
public static String notify_url="https://farmh5.hze2.com/prod-api/pay/getresult";
|
||||||
//https://5f655ed0.r3.cpolar.cn
|
//https://5f655ed0.r3.cpolar.cn
|
||||||
|
//微信小程序appid
|
||||||
|
public static String appId="wx308612d2a8423311";
|
||||||
|
//微信小程序appSecret
|
||||||
|
public static String appSecret="7f591f559929a3bf2dbea4e156b08ae9";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
* 创建订单,获取prepay_id和paySign
|
* 创建订单,获取prepay_id和paySign
|
||||||
@ -166,6 +165,125 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
httpClient.close();
|
httpClient.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取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, Object> response = restTemplate.getForObject(url, Map.class);
|
||||||
|
|
||||||
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
||||||
|
String responseString = EntityUtils.toString(response.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取平台证书
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String,Object> getPlatformCertificat(String mchId,String privateKey,String serial_no,String apiV3Key)
|
||||||
|
{
|
||||||
|
String url="https://api.mch.weixin.qq.com/v3/certificates";
|
||||||
|
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||||
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
//生成签名
|
||||||
|
Map<String,String> signResult=getSign(null,"GET","/v3/certificates",privateKey);
|
||||||
|
Set<String> keySet2 = signResult.keySet();
|
||||||
|
// 遍历键集合
|
||||||
|
for (String key : keySet2) {
|
||||||
|
System.err.println(key + ": " + signResult.get(key));
|
||||||
|
}
|
||||||
|
String sign=signResult.get("sign").toString();
|
||||||
|
String nonce_str=signResult.get("nonce_str").toString();
|
||||||
|
String timeStamp=signResult.get("timeStamp").toString();
|
||||||
|
String Authorization="WECHATPAY2-SHA256-RSA2048 mchid=\""+mchId+"\",nonce_str=\""+nonce_str+"\",signature=\""+sign+"\",timestamp=\""+timeStamp+"\",serial_no=\""+serial_no+"\"";
|
||||||
|
System.err.println(Authorization);
|
||||||
|
httpGet.setHeader("Accept", "application/json");
|
||||||
|
httpGet.setHeader("Authorization",Authorization);
|
||||||
|
|
||||||
|
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
||||||
|
String responseString = EntityUtils.toString(response.getEntity());
|
||||||
|
System.err.println(responseString);
|
||||||
|
Map<String, Object> responseMap = JSONUtil.toBean(responseString, Map.class);
|
||||||
|
// 使用Optional来避免null检查
|
||||||
|
Optional<?> optionalObj = Optional.ofNullable(responseMap.get("data"));
|
||||||
|
System.err.println(optionalObj);
|
||||||
|
// 链式调用map和flatMap方法来安全地转换和获取Map
|
||||||
|
Map<?, ?> map = optionalObj
|
||||||
|
.filter(List.class::isInstance) // 确保obj是List类型
|
||||||
|
.map(List.class::cast) // 将obj转换为List
|
||||||
|
.filter(list -> !list.isEmpty() && list.get(0) instanceof Map) // 确保List不为空,并且第一个元素是Map类型
|
||||||
|
.map(list -> (Map<?, ?>) list.get(0)) // 将List中的第一个元素转换为Map
|
||||||
|
.orElse(null); // 如果任何检查失败,则返回null
|
||||||
|
System.err.println(map);
|
||||||
|
//解密jsonObject对象
|
||||||
|
Map<String,Object> encrypt_certificate= (Map<String, Object>) map.get("encrypt_certificate");
|
||||||
|
System.err.println("111");
|
||||||
|
System.err.println(encrypt_certificate);
|
||||||
|
String serial=map.get("serial_no").toString();
|
||||||
|
System.err.println("平台证书序列号:"+serial);
|
||||||
|
String associated_data=encrypt_certificate.get("associated_data").toString();//加密证书的附加数据,固定为“certificate"
|
||||||
|
String ciphertext=encrypt_certificate.get("ciphertext").toString();//加密证书的随机串
|
||||||
|
String nonce=encrypt_certificate.get("nonce").toString();//加密后的证书内容
|
||||||
|
System.err.println("ciphertext:"+ciphertext);
|
||||||
|
System.err.println("nonce:"+nonce);
|
||||||
|
System.err.println("associated_data:"+associated_data);
|
||||||
|
//使用apiv3key解密
|
||||||
|
String decryptData="";
|
||||||
|
try{
|
||||||
|
decryptData= new AesUtil(apiV3Key.getBytes(StandardCharsets.UTF_8)).decryptToString
|
||||||
|
(associated_data.getBytes(StandardCharsets.UTF_8),
|
||||||
|
nonce.getBytes(StandardCharsets.UTF_8),
|
||||||
|
ciphertext);
|
||||||
|
System.out.println("解密成功:\n"+decryptData);
|
||||||
|
}catch (Exception e)
|
||||||
|
{
|
||||||
|
System.out.println("解密失败");
|
||||||
|
}
|
||||||
|
Map<String,Object> result=new HashMap<>();
|
||||||
|
result.put("platformCertificate",responseMap.toString());
|
||||||
|
result.put("serial",serial);
|
||||||
|
Set<String> keys=result.keySet();
|
||||||
|
for(String key : keys)
|
||||||
|
{
|
||||||
|
System.out.println(key+":"+result.get(key));
|
||||||
|
}
|
||||||
|
// 解析responseString以获取openid
|
||||||
|
return result; // 这里返回的是整个响应字符串,需要自行解析出openid
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成签名
|
* 生成签名
|
||||||
*/
|
*/
|
||||||
@ -240,122 +358,6 @@ public class UserWechatPayServiceImpl implements IUserWechatPayService {
|
|||||||
return Base64.getEncoder().encodeToString(sign.sign());
|
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, Object> response = restTemplate.getForObject(url, Map.class);
|
|
||||||
|
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
||||||
HttpGet httpGet = new HttpGet(url);
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
|
||||||
String responseString = EntityUtils.toString(response.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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取平台证书
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
/*@Override*/
|
|
||||||
/*public Map<String,Object> getPlatformCertificat()
|
|
||||||
{
|
|
||||||
String url="https://api.mch.weixin.qq.com/v3/certificates";
|
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
||||||
HttpGet httpGet = new HttpGet(url);
|
|
||||||
//生成签名
|
|
||||||
Map<String,String> signResult=getSign(null,"GET","/v3/certificates");
|
|
||||||
Set<String> keySet2 = signResult.keySet();
|
|
||||||
// 遍历键集合
|
|
||||||
for (String key : keySet2) {
|
|
||||||
System.err.println(key + ": " + signResult.get(key));
|
|
||||||
}
|
|
||||||
String sign=signResult.get("sign").toString();
|
|
||||||
String nonce_str=signResult.get("nonce_str").toString();
|
|
||||||
String timeStamp=signResult.get("timeStamp").toString();
|
|
||||||
String Authorization="WECHATPAY2-SHA256-RSA2048 mchid=\""+mchId+"\",nonce_str=\""+nonce_str+"\",signature=\""+sign+"\",timestamp=\""+timeStamp+"\",serial_no=\""+serial_no+"\"";
|
|
||||||
System.err.println(Authorization);
|
|
||||||
httpGet.setHeader("Accept", "application/json");
|
|
||||||
httpGet.setHeader("Authorization",Authorization);
|
|
||||||
|
|
||||||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
|
||||||
String responseString = EntityUtils.toString(response.getEntity());
|
|
||||||
System.err.println(responseString);
|
|
||||||
Map<String, Object> responseMap = JSONUtil.toBean(responseString, Map.class);
|
|
||||||
// 使用Optional来避免null检查
|
|
||||||
Optional<?> optionalObj = Optional.ofNullable(responseMap.get("data"));
|
|
||||||
System.err.println(optionalObj);
|
|
||||||
// 链式调用map和flatMap方法来安全地转换和获取Map
|
|
||||||
Map<?, ?> map = optionalObj
|
|
||||||
.filter(List.class::isInstance) // 确保obj是List类型
|
|
||||||
.map(List.class::cast) // 将obj转换为List
|
|
||||||
.filter(list -> !list.isEmpty() && list.get(0) instanceof Map) // 确保List不为空,并且第一个元素是Map类型
|
|
||||||
.map(list -> (Map<?, ?>) list.get(0)) // 将List中的第一个元素转换为Map
|
|
||||||
.orElse(null); // 如果任何检查失败,则返回null
|
|
||||||
System.err.println(map);
|
|
||||||
//解密jsonObject对象
|
|
||||||
Map<String,Object> encrypt_certificate= (Map<String, Object>) map.get("encrypt_certificate");
|
|
||||||
System.err.println("111");
|
|
||||||
System.err.println(encrypt_certificate);
|
|
||||||
String serial=map.get("serial_no").toString();
|
|
||||||
System.err.println("平台证书序列号:"+serial);
|
|
||||||
String associated_data=encrypt_certificate.get("associated_data").toString();//加密证书的附加数据,固定为“certificate"
|
|
||||||
String ciphertext=encrypt_certificate.get("ciphertext").toString();//加密证书的随机串
|
|
||||||
String nonce=encrypt_certificate.get("nonce").toString();//加密后的证书内容
|
|
||||||
System.err.println("ciphertext:"+ciphertext);
|
|
||||||
System.err.println("nonce:"+nonce);
|
|
||||||
System.err.println("associated_data:"+associated_data);
|
|
||||||
//使用apiv3key解密
|
|
||||||
String decryptData="";
|
|
||||||
try{
|
|
||||||
decryptData= new AesUtil(apiV3Key.getBytes(StandardCharsets.UTF_8)).decryptToString
|
|
||||||
(associated_data.getBytes(StandardCharsets.UTF_8),
|
|
||||||
nonce.getBytes(StandardCharsets.UTF_8),
|
|
||||||
ciphertext);
|
|
||||||
System.out.println("解密成功:\n"+decryptData);
|
|
||||||
}catch (Exception e)
|
|
||||||
{
|
|
||||||
System.out.println("解密失败");
|
|
||||||
}
|
|
||||||
Map<String,Object> result=new HashMap<>();
|
|
||||||
result.put("platformCertificate",responseMap.toString());
|
|
||||||
result.put("serial",serial);
|
|
||||||
Set<String> keys=result.keySet();
|
|
||||||
for(String key : keys)
|
|
||||||
{
|
|
||||||
System.out.println(key+":"+result.get(key));
|
|
||||||
}
|
|
||||||
// 解析responseString以获取openid
|
|
||||||
return result; // 这里返回的是整个响应字符串,需要自行解析出openid
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user