一、接口定义
/** * 功能描述:获取filecoin数据,通过企业微信,固定模板定时发送 * @author: jinjian * @Date: 2021-11-04 17:58 * @Description: */ public interface IQwService { /** * 发送消息 */ void sendWeChatMsgText(); void sendWeChatMsgWeekText(); void sendWeChatMsgMonthText(); void sendWeChatMsgBalanceText(); }
二、接口实现
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.dj.activemq.service.qwSyncFileCoin.IQwService; import com.dj.domain.qywxFilecoin.Filecoin230; import com.dj.wechat.util.HttpInvoke; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import javax.net.ssl.HttpsURLConnection; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 功能描述: 数据中心仓库实现类 * @author: jinjian * @Date: 2022-02-15 18:00 * @Description: */ @Service public class QwServiceImpl implements IQwService { @Autowired private StringRedisTemplate stringRedisTemplate; /** * 发送消息 */ /** * 企业接口向下属关注用户发送微信消息(实现方式二) * * @param touser * 成员ID列表(消息接收者,多个接收者用‘|’分隔,最多支持1000个)。特殊情况:指定为@all, * 则向关注该企业应用的全部成员发送 * @param toparty * 部门ID列表,多个接收者用‘|’分隔,最多支持100个。当touser为@all时忽略本参数 * @param content * 消息内容 * @param safe * 消息是否保密 * @return */ // 系统properties文件名称 // private static final String EMAILCONFIG = "emailAndMsgConfig"; // 发送消息类型 private final static String MSGTYPE = "markdown"; // 发送消息分组所有成员TOPARTY = "@all" "toparty" : "PartyID1|PartyID2", private final static String TOPARTY = "4|7"; // 发送消息分组 "touser" : "UserID1|183011|1350Ji", private final static String TOUSER = "JinJian|13534906880321"; private final static String TOUSER1 = "JinJian|13534906630"; // 需要自己申请,AgentId private final static String AgentId= "100003"; // 需要自己申请,AgentId private final static String AgentId1= "53,227.7232 FIL"; // 需要自己申请,AgentId private final static String AgentId2= "11,600.2235 FIL"; private final static String fileColor= "info"; // 定义消息类型 String ACCESS_TOKEN = getAccessToken(); //String blocksMined = getFilecoin230(); //String luckyValue = getFilecoin795(); // private final static String content= "ff01660795截止目前24小时:\n"+ // "存储服务效率:"+"0.0133 FIL/TiB"+" \n" + // "算力增速:"+"339.13 TiB"+" \n" + // "出块数量:"+"6"+" \n" + // "幸运值:"+"68.23%"+" \n" + // "出块奖励:"+"132.8613 FIL (0.04%)"+" \n" + // "账户余额:"+ AgentId1 +" \n" + // " " +" \n" + // "f01472330截止目前24小时:\n"+ // "存储服务效率:"+"0.0108 FIL/TiB"+" \n" + // "算力增速:"+"0.00 TiB"+" \n" + // "出块数量:"+"1"+" \n" + // "幸运值:"+"55.70%"+" \n" + // "出块奖励:"+"132.8613 FIL (0.04%)"+" \n" + // "账户余额:"+ AgentId2 +" \n" + // " " +" \n" + // "企业测试定时发送区块消息" +" \n" + // ""; // 获取配置文件中的值 CompanyID private final static String CORPID = "wx0f300db";// 需要自己申请,官网有试用企业号 // 获取配置文件中的值Secret View private final static String CORPSECRET = "*****"; // 获取访问权限码URL private final static String ACCESS_TOKEN_URL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"; // 创建会话请求URL private final static String CREATE_SESSION_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="; @Override public void sendWeChatMsgText() { URL uRl; String ACCESS_TOKEN = getAccessToken(); // 拼接请求串 //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); //Date date = new Date(); // SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); //Date date = new Date(System.currentTimeMillis()); String timeStr1= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String action = CREATE_SESSION_URL + ACCESS_TOKEN; Filecoin230 file230=getFilecoin230(); Filecoin230 miner230=getFilecoinF230(); Filecoin230 file795=getFilecoin795(); Filecoin230 miner795=getFilecoinF795(); Filecoin230 fileF230=getFilecoinF230(); Filecoin230 fileF795=getFilecoinF795(); String content= ">[f01795](https://filfox.info/zh/address/f0166095)<font color =\\\"info\\\">截止目前24小时:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file795.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file795.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB / 天 \n" + "扇区状态: "+ fileF795.getLive()+"全部,"+fileF795.getActive()+"有效,"+fileF795.getFaulty()+"错误,"+fileF795.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF795.getActive())*32/1024/1024).substring(0, 6) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file795.getBlocksMined())==0?"0.00":file795.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (Float.parseFloat(file795.getLuckyValue())==0?"0.00":String.valueOf(Float.parseFloat(file795.getLuckyValue().substring(0, 6))*100) )+"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (Float.parseFloat(file795.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file795.getTotalRewards())*0.000000000000000001).substring(0, 6) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF795.getBalance())*0.000000000000000001).substring(0, 9) +"FIL \n" + ">" +" \n" + ">[f01472330](https://filfox.info/zh/address/f0147230)<font color =\\\"info\\\">截止目前24小时:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file230.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file230.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB / 天 \n" + "扇区状态:"+ fileF230.getLive()+"全部,"+fileF230.getActive()+"有效,"+fileF230.getFaulty()+"错误,"+fileF230.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF230.getActive())*32/1024/1024).substring(0, 4) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file230.getBlocksMined())==0?"0.00":file230.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (String.valueOf(Float.parseFloat(file230.getLuckyValue())==0?"0.00":Float.parseFloat(file230.getLuckyValue().substring(0, 6))*100)) +"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (String.valueOf(Float.parseFloat(file230.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file230.getTotalRewards())*0.000000000000000001).substring(0, 6)) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF230.getBalance())*0.000000000000000001).substring(0, 9) +" FIL \n" + " " +" \n" + //"01、09、13、18、点定时发送" +" \n" + " " +"最新节点数据每天跟进"+" \n" + // "https://filfox.info/zh/address/f01660795" +" \n" + // " " +" \n" + // "https://filfox.info/zh/address/f01472330" +" \n" + "" ; // 封装发送消息请求json StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"touser\":" + "\"" + TOUSER + "\","); //sb.append("\"toparty\":" + "\"" + TOPARTY + "\","); //sb.append("\"totag\":" + "\"" + totag + "\","); sb.append("\"msgtype\":" + "\"" + MSGTYPE + "\","); sb.append("\"markdown\":" + "{"); sb.append("\"content\":" + "\"" + content + "\""); sb.append("}"); sb.append(",\"safe\":" + "\"" + 0 + "\","); sb.append("\"agentid\":" + "\"" + AgentId + "\","); sb.append("\"debug\":" + "\"" + "1" + "\""); sb.append("}"); String json = sb.toString(); System.out.println("=========================="); System.out.println(json); System.out.println("=========================="); try { uRl = new URL(action); HttpsURLConnection http = (HttpsURLConnection) uRl.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// // 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // // 读取超时30秒 http.connect(); OutputStream os = http.getOutputStream(); os.write(json.getBytes("UTF-8"));// 传入参数 InputStream is = http.getInputStream(); int size = is.available(); byte[] jsonBytes = new byte[size]; is.read(jsonBytes); String result = new String(jsonBytes, "UTF-8"); System.out.println("请求返回结果:" + result); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } public void sendWeChatMsgWeekText() { URL uRl; String ACCESS_TOKEN = getAccessToken(); // 拼接请求串 //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); //Date date = new Date(); // SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); //Date date = new Date(System.currentTimeMillis()); String timeStr1= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String action = CREATE_SESSION_URL + ACCESS_TOKEN; Filecoin230 file230=getFilecoinWeek230(); Filecoin230 miner230=getFilecoinF230(); Filecoin230 file795=getFilecoinWeek795(); Filecoin230 miner795=getFilecoinF795(); Filecoin230 fileF230=getFilecoinF230(); Filecoin230 fileF795=getFilecoinF795(); String content= ">[f01660795](https://filfox.info/zh/address/f01795)<font color =\\\"info\\\">截止目前7天:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file795.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file795.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB / 天 \n" + "扇区状态: "+ fileF795.getLive()+"全部,"+fileF795.getActive()+"有效,"+fileF795.getFaulty()+"错误,"+fileF795.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF795.getActive())*32/1024/1024).substring(0, 6) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file795.getBlocksMined())==0?"0.00":file795.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (Float.parseFloat(file795.getLuckyValue())==0?"0.00":String.valueOf(Float.parseFloat(file795.getLuckyValue().substring(0, 6))*100) )+"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (Float.parseFloat(file795.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file795.getTotalRewards())*0.000000000000000001).substring(0, 6) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF795.getBalance())*0.000000000000000001).substring(0, 9) +"FIL \n" + ">" +" \n" + ">[f01472330](https://filfox.info/zh/address/f01472330)<font color =\\\"info\\\">截止目前7天:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file230.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file230.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB / 天 \n" + "扇区状态:"+ fileF230.getLive()+"全部,"+fileF230.getActive()+"有效,"+fileF230.getFaulty()+"错误,"+fileF230.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF230.getActive())*32/1024/1024).substring(0, 4) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file230.getBlocksMined())==0?"0.00":file230.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (String.valueOf(Float.parseFloat(file230.getLuckyValue())==0?"0.00":Float.parseFloat(file230.getLuckyValue().substring(0, 6))*100)) +"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (String.valueOf(Float.parseFloat(file230.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file230.getTotalRewards())*0.000000000000000001).substring(0, 6)) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF230.getBalance())*0.000000000000000001).substring(0, 9) +" FIL \n" + " " +" \n" + //"01、09、13、18、点定时发送" +" \n" + " " +"最新节点数据每周跟进"+" \n" + // "https://filfox.info/zh/address/f01660795" +" \n" + // " " +" \n" + // "https://filfox.info/zh/address/f01472330" +" \n" + "" ; // 封装发送消息请求json StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"touser\":" + "\"" + TOUSER + "\","); //sb.append("\"toparty\":" + "\"" + TOPARTY + "\","); //sb.append("\"totag\":" + "\"" + totag + "\","); sb.append("\"msgtype\":" + "\"" + MSGTYPE + "\","); sb.append("\"markdown\":" + "{"); sb.append("\"content\":" + "\"" + content + "\""); sb.append("}"); sb.append(",\"safe\":" + "\"" + 0 + "\","); sb.append("\"agentid\":" + "\"" + AgentId + "\","); sb.append("\"debug\":" + "\"" + "1" + "\""); sb.append("}"); String json = sb.toString(); System.out.println("=========================="); System.out.println(json); System.out.println("=========================="); try { uRl = new URL(action); HttpsURLConnection http = (HttpsURLConnection) uRl.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// // 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // // 读取超时30秒 http.connect(); OutputStream os = http.getOutputStream(); os.write(json.getBytes("UTF-8"));// 传入参数 InputStream is = http.getInputStream(); int size = is.available(); byte[] jsonBytes = new byte[size]; is.read(jsonBytes); String result = new String(jsonBytes, "UTF-8"); System.out.println("请求返回结果:" + result); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } public void sendWeChatMsgMonthText() { URL uRl; String ACCESS_TOKEN = getAccessToken(); // 拼接请求串 //SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); //Date date = new Date(); // SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); //Date date = new Date(System.currentTimeMillis()); String timeStr1= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String action = CREATE_SESSION_URL + ACCESS_TOKEN; Filecoin230 file230=getFilecoinMonth230(); Filecoin230 miner230=getFilecoinF230(); Filecoin230 file795=getFilecoinMonth795(); Filecoin230 miner795=getFilecoinF795(); Filecoin230 fileF230=getFilecoinF230(); Filecoin230 fileF795=getFilecoinF795(); String content= ">[f01795](https://filfox.info/zh/address/f01795)<font color =\\\"info\\\">截止目前30天:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file795.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file795.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB \n" + "扇区状态: "+ fileF795.getLive()+"全部,"+fileF795.getActive()+"有效,"+fileF795.getFaulty()+"错误,"+fileF795.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF795.getActive())*32/1024/1024).substring(0, 6) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file795.getBlocksMined())==0?"0.00":file795.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (Float.parseFloat(file795.getLuckyValue())==0?"0.00":String.valueOf(Float.parseFloat(file795.getLuckyValue().substring(0, 6))*100) )+"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (Float.parseFloat(file795.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file795.getTotalRewards())*0.000000000000000001).substring(0, 6) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF795.getBalance())*0.000000000000000001).substring(0, 9) +"FIL \n" + ">" +" \n" + ">[f01472330](https://filfox.info/zh/address/f01472330)<font color =\\\"info\\\">截止目前30天:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "<font color =\\\"warning\\\">算力增速: </font>"+ (Float.parseFloat(file230.getRawBytePowerDelta())==0?"0.00":String.valueOf(Float.parseFloat(file230.getRawBytePowerDelta())*1/1024/1024/1024/1024).substring(0, 6) )+" TiB \n" + "扇区状态:"+ fileF230.getLive()+"全部,"+fileF230.getActive()+"有效,"+fileF230.getFaulty()+"错误,"+fileF230.getRecovering()+"恢复中"+" \n" + "<font color =\\\"warning\\\">有效算力: </font>"+ String.valueOf(Float.parseFloat(fileF230.getActive())*32/1024/1024).substring(0, 4) +" PiB \n" + "<font color =\\\"comment\\\">出块数量: </font>"+ (Float.parseFloat(file230.getBlocksMined())==0?"0.00":file230.getBlocksMined()) +" \n" + "<font color =\\\"warning\\\">幸运值: </font>"+ (String.valueOf(Float.parseFloat(file230.getLuckyValue())==0?"0.00":Float.parseFloat(file230.getLuckyValue().substring(0, 6))*100)) +"% \n" + "<font color =\\\"warning\\\">出块奖励: </font>"+ (String.valueOf(Float.parseFloat(file230.getTotalRewards())==0?"0.00":String.valueOf(Float.parseFloat(file230.getTotalRewards())*0.000000000000000001).substring(0, 6)) )+" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF230.getBalance())*0.000000000000000001).substring(0, 9) +" FIL \n" + " " +" \n" + //"01、09、13、18、点定时发送" +" \n" + " " +"最新节点数据每月跟进"+" \n" + // "https://filfox.info/zh/address/f01660795" +" \n" + // " " +" \n" + // "https://filfox.info/zh/address/f01472330" +" \n" + "" ; // 封装发送消息请求json StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"touser\":" + "\"" + TOUSER + "\","); //sb.append("\"toparty\":" + "\"" + TOPARTY + "\","); //sb.append("\"totag\":" + "\"" + totag + "\","); sb.append("\"msgtype\":" + "\"" + MSGTYPE + "\","); sb.append("\"markdown\":" + "{"); sb.append("\"content\":" + "\"" + content + "\""); sb.append("}"); sb.append(",\"safe\":" + "\"" + 0 + "\","); sb.append("\"agentid\":" + "\"" + AgentId + "\","); sb.append("\"debug\":" + "\"" + "1" + "\""); sb.append("}"); String json = sb.toString(); System.out.println("=========================="); System.out.println(json); System.out.println("=========================="); try { uRl = new URL(action); HttpsURLConnection http = (HttpsURLConnection) uRl.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// // 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // // 读取超时30秒 http.connect(); OutputStream os = http.getOutputStream(); os.write(json.getBytes("UTF-8"));// 传入参数 InputStream is = http.getInputStream(); int size = is.available(); byte[] jsonBytes = new byte[size]; is.read(jsonBytes); String result = new String(jsonBytes, "UTF-8"); System.out.println("请求返回结果:" + result); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } public void sendWeChatMsgBalanceText() { URL uRl; String ACCESS_TOKEN = getAccessToken(); // 拼接请求串 // SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm"); //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); //Date date = new Date(); // SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z"); // Date date = new Date(System.currentTimeMillis()); String timeStr1= LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); String action = CREATE_SESSION_URL + ACCESS_TOKEN; Filecoin230 file230=getFilecoin230(); Filecoin230 miner230=getFilecoinF230(); Filecoin230 file795=getFilecoin795(); Filecoin230 miner795=getFilecoinF795(); Filecoin230 fileF230=getFilecoinF230(); Filecoin230 fileF795=getFilecoinF795(); String content= ">[f01795](https://filfox.info/zh/address/f01795)<font color =\\\"info\\\">目前钱包信息:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "[owner余额: ](https://filfox.info/zh/address/f3wc7xyevfmsueya3mfdd2jrfbzk5wpntu5boaww45nxrglk7rux6anqa3q6e5oaifeis4pdtf3p4kcfm2jjyq)"+ String.valueOf(Float.parseFloat(fileF795.getBalanceOwner())*0.000000000000000001).substring(0, 6) +" FIL \n" + "[worker余额: ](https://filfox.info/zh/address/f3qygnsauuwtghn56uhkoxrrtzj5evkwv5n5gdle4thttcfddgkkzfgoabatqmfuaiiitvqufdpvcgr5xgvwpa)"+ String.valueOf(Float.parseFloat(fileF795.getBalanceWorker())*0.000000000000000001).substring(0, 6) +" FIL \n" + "[control余额: ](https://filfox.info/zh/address/f3vp6yfvdbzlzopel7ru42l6du7epofynkiga7mvqgg6oer5xrzfqcz5k2ict7p6k4sc43snszc3so4ffh76aq)"+ String.valueOf(Float.parseFloat(fileF795.getBalanceControl())*0.000000000000000001).substring(0, 6) +" FIL \n" + "可用余额: "+ String.valueOf(Float.parseFloat(fileF795.getAvailableBalance())*0.000000000000000001).substring(0, 6) +" FIL \n" + "扇区抵押: "+ String.valueOf(Float.parseFloat(fileF795.getSectorPledgeBalance())*0.000000000000000001).substring(0, 6) +" FIL \n" + "服务锁仓: "+ String.valueOf(Float.parseFloat(fileF795.getVestingFunds())*0.000000000000000001).substring(0, 6) +" FIL \n" + "<font color =\\\"warning\\\">累计出块:</font>"+ miner795.getWeightedBlocksMined() +" \n" + "<font color =\\\"warning\\\">累计奖励:</font>"+String.valueOf(Float.parseFloat(miner795.getTotalRewards())*0.000000000000000001).substring(0, 6) +" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF795.getBalance())*0.000000000000000001).substring(0, 9) +" FIL \n" + ">" +" \n" + ">[f01330](https://filfox.info/zh/address/f01472330)<font color =\\\"info\\\">目前钱包信息:</font>\n"+ "<font color =\\\"info\\\"> "+ timeStr1 +"</font> \n" + "[owner余额: ](https://filfox.info/zh/address/f3wq2qynrmb6uqy4q7gugtxpxnmyn5uxwjhy2a6bvfgoc2sfdmpzwd7llsipy26qmwtl2idgexkxxn3nfjfpia)"+ String.valueOf(Float.parseFloat(fileF230.getBalanceOwner())*0.000000000000000001).substring(0, 6) +" FIL \n" + "[worker余额: ](https://filfox.info/zh/address/f3sre3kym3azhkh5vr2rx7swcmjpfotviatx7wyrqs2f7iakrjxmf3u3n47kwoeq7lfol372lsoe6v7bdauzpa)"+ String.valueOf(Float.parseFloat(fileF230.getBalanceWorker())*0.000000000000000001).substring(0, 6) +" FIL \n" + "[control余额: ](https://filfox.info/zh/address/f3vcotgacbjjfsjytc4gwzfdg3uqhb7qapv7hcoj55ysqkkqrctdv2xeiut7mtr32ix5lmujvwmdqut3imaj5q)"+ String.valueOf(Float.parseFloat(fileF230.getBalanceControl())*0.000000000000000001).substring(0, 6) +" FIL \n" + "可用余额: "+ String.valueOf(Float.parseFloat(fileF230.getAvailableBalance())*0.000000000000000001).substring(0, 6) +" FIL \n" + "扇区抵押: "+ String.valueOf(Float.parseFloat(fileF230.getSectorPledgeBalance())*0.000000000000000001).substring(0, 6) +" FIL \n" + "服务锁仓: "+ String.valueOf(Float.parseFloat(fileF230.getVestingFunds())*0.000000000000000001).substring(0, 6) +" FIL \n" + "<font color =\\\"warning\\\">累计出块: </font>"+ miner230.getWeightedBlocksMined() +" \n" + "<font color =\\\"warning\\\">累计奖励: </font>"+ String.valueOf(Float.parseFloat(miner230.getTotalRewards())*0.000000000000000001).substring(0, 6) +" FIL \n" + "账户余额: "+ String.valueOf(Float.parseFloat(fileF230.getBalance())*0.000000000000000001).substring(0, 9) +" FIL \n" + " " +" \n" + //"00、10、14、21定时发送" +" \n" + "" +"最新钱包资产每天跟进"+" \n" + // "https://filfox.info/zh/address/f01660795" +" \n" + // " " +" \n" + // "https://filfox.info/zh/address/f01472330" +" \n" + "" ; // 封装发送消息请求json StringBuffer sb = new StringBuffer(); sb.append("{"); sb.append("\"touser\":" + "\"" + TOUSER + "\","); //sb.append("\"toparty\":" + "\"" + TOPARTY + "\","); //sb.append("\"totag\":" + "\"" + totag + "\","); sb.append("\"msgtype\":" + "\"" + MSGTYPE + "\","); sb.append("\"markdown\":" + "{"); sb.append("\"content\":" + "\"" + content + "\""); sb.append("}"); sb.append(",\"safe\":" + "\"" + 0 + "\","); sb.append("\"agentid\":" + "\"" + AgentId + "\","); sb.append("\"debug\":" + "\"" + "1" + "\""); sb.append("}"); // sb.append("{"); // sb.append("\"touser\":" + "\"" + TOUSER1 + "\","); // sb.append("\"msgtype\": \"textcard\","); // sb.append("\"agentid\":" + "\"" + AgentId + "\","); sb.append("\"text\": {"); sb.append("\"content\": \"你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\\\"http://work.weixin.qq.com\\\">邮件中心视频实况</a>,聪明避开排队。\""); sb.append("},"); // // sb.append("\"textcard\" : {"); // sb.append("\"title\" : \"领奖通知\","); // sb.append("\"description\" : \"<div class=\\\"gray\\\">2016年9月26日</div> <div class=\\\"normal\\\">恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class=\\\"highlight\\\">请于2016年10月10日前联系行政同事领取</div>\","); // sb.append("\"url\": \"URL\","); // sb.append("\"btntxt\":\"更多\"},"); // sb.append("\"enable_id_trans\": 0,"); // // sb.append("\"enable_duplicate_check\": 0,"); // sb.append("\"duplicate_check_interval\": 1800"); // sb.append("}"); String json = sb.toString(); System.out.println("=========================="); System.out.println(json); System.out.println("=========================="); try { uRl = new URL(action); HttpsURLConnection http = (HttpsURLConnection) uRl.openConnection(); http.setRequestMethod("POST"); http.setRequestProperty("Content-Type", "application/json;charset=UTF-8"); http.setDoOutput(true); http.setDoInput(true); System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// // 连接超时30秒 System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // // 读取超时30秒 http.connect(); OutputStream os = http.getOutputStream(); os.write(json.getBytes("UTF-8"));// 传入参数 InputStream is = http.getInputStream(); int size = is.available(); byte[] jsonBytes = new byte[size]; is.read(jsonBytes); String result = new String(jsonBytes, "UTF-8"); System.out.println("请求返回结果:" + result); os.flush(); os.close(); } catch (Exception e) { e.printStackTrace(); } } private String getAccessToken() { Map<String, String> map = new HashMap<>(); map.put("CORPID", "wx0fb748300db"); map.put("CORPSECRET", "AhvHCvu1PbYOUYsPRk4gNhvK87KUiWAzt8eNw"); String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); //JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); String token = jsonObject.getString("access_token"); System.out.println("------------ 发送企微消息执行完毕 --------- 企业微信token: "+token); System.out.println("返回码:"+jsonObject.getString("errcode")); System.out.println("提示语:"+jsonObject.getString("errmsg")); System.out.println("token:"+jsonObject.getString("access_token")); System.out.println("有效时间:"+jsonObject.getString("expires_in")); //return token; return token; } public void getToken() { Map<String, String> map = new HashMap<>(); map.put("CORPID", "wx0fb79971340db"); map.put("CORPSECRET", "AhvHCvu1PbYOUYsPRk4gNOUsQfZhvK87KUiWAzt8eNw"); String url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); //JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); String token = jsonObject.getString("access_token"); System.out.println("------------ 发送企微消息执行完毕 --------- 企业微信token: "+token); System.out.println("返回码:"+jsonObject.getString("errcode")); System.out.println("提示语:"+jsonObject.getString("errmsg")); System.out.println("token:"+jsonObject.getString("access_token")); System.out.println("有效时间:"+jsonObject.getString("expires_in")); //return token; } // public String getFilecoin230() { // Map<String, String> map = new HashMap<>(); // String url = "https://filfox.info/api/v1/address/f012330/mining-stats?duration=24h"; // String tt = HttpInvoke.doGet(url, map); // JSONObject jsonObject = JSONObject.parseObject(tt); // // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); // String blocksMined = jsonObject.getString("blocksMined"); // String luckyValue = jsonObject.getString("luckyValue"); // String totalRewards = jsonObject.getString("totalRewards"); // System.out.println("------------ 获取Filecoin消息执行完毕 --------- FileCoin24小时爆块:"+blocksMined+tt); // System.out.println("区块奖励:"+jsonObject.getString("blocksMined")); // System.out.println("幸运值:"+jsonObject.getString("luckyValue")); // System.out.println("存储服务效率:"+jsonObject.getString("totalRewards")); // return blocksMined; // } public Filecoin230 getFilecoin230() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f0230/mining-stats?duration=24h"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 file230 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return file230; } public Filecoin230 getFilecoin795() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f01660795/mining-stats?duration=24h"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 file795 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return file795; } public Filecoin230 getFilecoinWeek230() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f01472330/mining-stats?duration=7d"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 fileWeek230 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return fileWeek230; } public Filecoin230 getFilecoinWeek795() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f0195/mining-stats?duration=7d"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 fileWeek795 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return fileWeek795; } public Filecoin230 getFilecoinMonth230() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f012330/mining-stats?duration=30d"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 fileMonth230 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return fileMonth230; } public Filecoin230 getFilecoinMonth795() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f01695/mining-stats?duration=30d"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); Filecoin230 fileMonth795 = JSON.toJavaObject(jsonObject, Filecoin230.class); // JSONObject data = JSONObject.parseObject(jsonObject.getString("data")); return fileMonth795; } public Filecoin230 getFilecoinF795() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f016795"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); JSONObject miner = JSONObject.parseObject(jsonObject.getString("miner")); JSONObject owner = JSONObject.parseObject(miner.getString("owner")); JSONObject worker = JSONObject.parseObject(miner.getString("worker")); JSONObject sectors = JSONObject.parseObject(miner.getString("sectors")); JSONObject control = JSONObject.parseObject(miner.getString("controlAddresses").replace("[","").replace("]","")); // controlAddresses = $('#billTypeId').val() ? JSON.stringify($('#billTypeId').val()).replace("[","").replace("]",""):""; System.out.println("control值:"+ control +""); Filecoin230 filecoin230=new Filecoin230(); filecoin230.setBalanceWorker(worker.getString("balance")); filecoin230.setBalanceOwner(owner.getString("balance")); filecoin230.setBalanceControl(control.getString("balance")); filecoin230.setAddressWorker(worker.getString("address")); filecoin230.setLive(sectors.getString("live")); filecoin230.setActive(sectors.getString("active")); filecoin230.setFaulty(sectors.getString("faulty")); filecoin230.setRecovering(sectors.getString("recovering")); filecoin230.setBalance(jsonObject.getString("balance")); // filecoin230.setPledgeBalance(jsonObject.getString("pledgeBalance")); // filecoin230.setSectorPledgeBalance(jsonObject.getString("sectorPledgeBalance")); // filecoin230.setAvailableBalance(jsonObject.getString("availableBalance")); // filecoin230.setInitialPledgeRequirement(jsonObject.getString("initialPledgeRequirement")); // filecoin230.setVestingFunds(jsonObject.getString("vestingFunds")); // filecoin230.setPreCommitDeposits(jsonObject.getString("preCommitDeposits")); // filecoin230.setRawBytePowerRank(jsonObject.getString("rawBytePowerRank")); Filecoin230 miner795 = JSON.toJavaObject(miner, Filecoin230.class); filecoin230.setAvailableBalance( miner795.getAvailableBalance()); filecoin230.setSectorPledgeBalance( miner795.getSectorPledgeBalance()); filecoin230.setPledgeBalance( miner795.getPledgeBalance()); filecoin230.setVestingFunds( miner795.getVestingFunds()); filecoin230.setTotalRewards( miner795.getTotalRewards()); filecoin230.setWeightedBlocksMined( miner795.getWeightedBlocksMined()); System.out.println("测试F795对象转换rawbytepower值:"+miner795.getBlocksMined()+"爆块"+miner795.getAvailableBalance()+""); System.out.println("可用余额:"+ miner795.getAvailableBalance() +""); System.out.println("扇区抵押:"+ miner795.getSectorPledgeBalance() +""); System.out.println("服务锁仓:"+ miner795.getPledgeBalance() +""); //filecoin230.setRawBytePower(jsonObject.getString("rawbytepower)); return filecoin230; } // public List<Filecoin230> getFilecoinF230() { // Map<String, String> map = new HashMap<>(); // String url = "https://filfox.info/api/v1/address/f01330"; // String tt = HttpInvoke.doGet(url, map); // JSONObject jsonObject = JSONObject.parseObject(tt); // //JSONArray jsonArray = JSONArray.fromObject(jsonObject.getString("transfers")); // JSONArray objects = JSONArray.parseArray(jsonObject.getString("transfers")); // List<Filecoin230> listfilecoin230 = objects.toJavaList(Filecoin230.class); // // return listfilecoin230; // } public Filecoin230 getFilecoinF230() { Map<String, String> map = new HashMap<>(); String url = "https://filfox.info/api/v1/address/f014330"; String tt = HttpInvoke.doGet(url, map); JSONObject jsonObject = JSONObject.parseObject(tt); JSONObject miner = JSONObject.parseObject(jsonObject.getString("miner")); JSONObject owner = JSONObject.parseObject(miner.getString("owner")); JSONObject worker = JSONObject.parseObject(miner.getString("worker")); JSONObject sectors = JSONObject.parseObject(miner.getString("sectors")); JSONObject control = JSONObject.parseObject(miner.getString("controlAddresses").replace("[","").replace("]","")); // billTypeIds = $('#billTypeId').val() ? JSON.stringify($('#billTypeId').val()).replace("[","").replace("]",""):""; System.out.println("control值:"+ control +""); Filecoin230 filecoin230=new Filecoin230(); filecoin230.setBalanceWorker(worker.getString("balance")); filecoin230.setBalanceControl(control.getString("balance")); filecoin230.setBalanceOwner(owner.getString("balance")); filecoin230.setAddressWorker(worker.getString("address")); filecoin230.setLive(sectors.getString("live")); filecoin230.setActive(sectors.getString("active")); filecoin230.setFaulty(sectors.getString("faulty")); filecoin230.setRecovering(sectors.getString("recovering")); filecoin230.setBalance(jsonObject.getString("balance")); // filecoin230.setPledgeBalance(jsonObject.getString("pledgeBalance")); // filecoin230.setSectorPledgeBalance(jsonObject.getString("sectorPledgeBalance")); // filecoin230.setAvailableBalance(jsonObject.getString("availableBalance")); // filecoin230.setInitialPledgeRequirement(jsonObject.getString("initialPledgeRequirement")); // filecoin230.setVestingFunds(jsonObject.getString("vestingFunds")); // filecoin230.setPreCommitDeposits(jsonObject.getString("preCommitDeposits")); // filecoin230.setRawBytePowerRank(jsonObject.getString("rawBytePowerRank")); Filecoin230 miner230 = JSON.toJavaObject(miner, Filecoin230.class); filecoin230.setAvailableBalance( miner230.getAvailableBalance()); filecoin230.setSectorPledgeBalance( miner230.getSectorPledgeBalance()); filecoin230.setPledgeBalance( miner230.getPledgeBalance()); filecoin230.setVestingFunds( miner230.getVestingFunds()); filecoin230.setTotalRewards( miner230.getTotalRewards()); filecoin230.setWeightedBlocksMined( miner230.getWeightedBlocksMined()); System.out.println("测试F230对象转换rawbytepower值:"+miner230.getAvailableBalance()+"爆块"+miner230.getBlocksMined()+""); System.out.println("可用余额:"+ miner230.getAvailableBalance() +""); System.out.println("扇区抵押:"+ miner230.getSectorPledgeBalance() +""); System.out.println("服务锁仓:"+ miner230.getPledgeBalance() +""); return filecoin230; } }
三、定时任务
import com.dj.activemq.service.erp.IErpInfoService; import com.dj.activemq.service.erpSqlServer.IJewelryInfoService; import com.dj.activemq.service.qwSyncFileCoin.IQwService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; /** * 功能描述: 同步数据至数据中心 * @author: jinjian * @Date: 2022-02-15 17:41 * @Description:****** */ @Component @EnableScheduling public class QwScheduler { @Autowired private IQwService qwService; @Scheduled(cron = "0 0 1,9,13,18,22 * * ?") // @Scheduled(cron = "*/20000 * * * * ?") public void QwMapper(){ qwService.sendWeChatMsgText( ); } @Scheduled(cron = "0 0 21 * * ?") public void QwMapperBalance(){ qwService.sendWeChatMsgBalanceText( ); } @Scheduled(cron = "0 15 10 ? * MON") public void QwMapperWeek(){ qwService.sendWeChatMsgWeekText(); } @Scheduled(cron = "0 8 0 1 * ?") public void QwMapperMonth(){ qwService.sendWeChatMsgMonthText(); } }