Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
aa24615 committed Nov 13, 2021
1 parent 6da9ac8 commit 350825a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
81 changes: 38 additions & 43 deletions src/main/java/com/php127/wework/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class Message {
public Message(String corpid, String secret, String prikey){

this.sdk = Finance.NewSdk();

this.corpid = corpid;
this.tableName = "message_"+this.corpid;
int state = Finance.Init(sdk,corpid,secret);
Expand Down Expand Up @@ -87,65 +88,59 @@ public long getSeq(){
return 0;
}
//获取列表
public void getList(){
public void getList() throws Exception{


System.out.println("======================================");
try {

long seqs = this.getSeq();
int limit = 1000;
long slice = Finance.NewSlice();
System.out.println("起始数:"+seqs);
int ret = Finance.GetChatData(this.sdk, seqs, limit, "", "", 100, slice);
if (ret != 0) {
System.out.println("失败:" + ret);
return;
}

String json = Finance.GetContentFromSlice(slice);
JSONObject jo = new JSONObject(json);
long seqs = this.getSeq();
int limit = 1000;
long slice = Finance.NewSlice();
System.out.println("起始数:"+seqs);
int ret = Finance.GetChatData(this.sdk, seqs, limit, "", "", 100, slice);
if (ret != 0) {
System.out.println("失败:" + ret);
return;
}

String errmsg = jo.getString("errmsg");
int errcode = jo.getInt("errcode");
String json = Finance.GetContentFromSlice(slice);
JSONObject jo = new JSONObject(json);

String errmsg = jo.getString("errmsg");
int errcode = jo.getInt("errcode");

// System.out.println("原始:"+json);

if(errcode==0){
System.out.println("获取成功:"+errmsg);
JSONArray chatdata = jo.getJSONArray("chatdata");
System.out.println("消息数:"+chatdata.length());
for (int i = 0; i < chatdata.length(); i++) {
String item = chatdata.get(i).toString();
JSONObject data = new JSONObject(item);
String encrypt_random_key = data.getString("encrypt_random_key");
String encrypt_chat_msg = data.getString("encrypt_chat_msg");
long seq = data.getLong("seq");
if(errcode==0){
System.out.println("获取成功:"+errmsg);
JSONArray chatdata = jo.getJSONArray("chatdata");
System.out.println("消息数:"+chatdata.length());
for (int i = 0; i < chatdata.length(); i++) {
String item = chatdata.get(i).toString();
JSONObject data = new JSONObject(item);
String encrypt_random_key = data.getString("encrypt_random_key");
String encrypt_chat_msg = data.getString("encrypt_chat_msg");
long seq = data.getLong("seq");
// System.out.println("密钥:"+encrypt_random_key);
// System.out.println("密文:"+encrypt_chat_msg);
String message = this.decryptData(encrypt_random_key,encrypt_chat_msg);
System.out.println("消息内容:"+message);
if(this.saveMessage(seq,message)){
if(this.seqs<seq){
this.seqs=seq;
}
String message = this.decryptData(encrypt_random_key,encrypt_chat_msg);
System.out.println("消息内容:"+message);
if(this.saveMessage(seq,message)){
if(this.seqs<seq){
this.seqs=seq;
}
}
}else{
System.out.println("获取失败:"+this.corpid);
System.out.println("errcode:"+errcode+":"+errmsg);
return;
}
}else{
System.out.println("获取失败:"+this.corpid);
System.out.println("errcode:"+errcode+":"+errmsg);
throw new Exception("获取失败");
}

//关闭
Finance.FreeSlice(slice);
//关闭
Finance.FreeSlice(slice);

Thread.sleep(10000);
this.getList();
}catch (InterruptedException e){
System.out.println("异常:"+this.corpid);
return;
}
}


Expand Down
15 changes: 13 additions & 2 deletions src/main/java/com/php127/wework/message/Threads.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ public Threads(String corpid, String secret, String prikey) {
public void run() {
System.out.println("开始运行: " + corpid );
try {
Message message = new Message(this.corpid,this.secret,this.prikey);
message.getList();
while (true){
try {
Message message = new Message(this.corpid,this.secret,this.prikey);
message.getList();
Thread.sleep( 5000) ;
}catch (InterruptedException e){
System.out.println("异常: " + e.getMessage() );
}
}
}catch (UnsatisfiedLinkError e){
System.out.println("找不到动态库 WeWorkFinanceSdk_Java.so" );
System.out.println("请使用linux系统,并将动态库拷贝到系统" );
}catch (Exception e) {
System.out.println("异常线程: " + corpid );
System.out.println(e.getMessage());
}

System.out.println("结束线程: " + corpid );
}

Expand Down

0 comments on commit 350825a

Please sign in to comment.