Browse Source

update tt

master
xhxu 3 years ago
parent
commit
ff84724877
2 changed files with 7 additions and 5 deletions
  1. +4
    -2
      mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenComponentServiceImpl.java
  2. +3
    -3
      mallinkService/src/main/java/com/iformall/service/toutiao/utils/ServerVerification.java

+ 4
- 2
mallinkService/src/main/java/com/iformall/service/toutiao/api/impl/TtOpenComponentServiceImpl.java View File

@@ -12,6 +12,7 @@ import com.iformall.service.toutiao.api.bean.TtOpenGsonBuilder;
import com.iformall.service.toutiao.api.bean.TtOpenRetrieveCode; import com.iformall.service.toutiao.api.bean.TtOpenRetrieveCode;
import com.iformall.service.toutiao.api.bean.TtOpenTicket; import com.iformall.service.toutiao.api.bean.TtOpenTicket;
import com.iformall.service.toutiao.utils.MsgDecrypt; import com.iformall.service.toutiao.utils.MsgDecrypt;
import com.iformall.service.toutiao.utils.ServerVerification;
import me.chanjar.weixin.common.error.WxError; import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.crypto.SHA1;
@@ -79,8 +80,9 @@ public class TtOpenComponentServiceImpl implements TtOpenComponentService {
@Override @Override
public boolean checkSignature(String timestamp, String nonce, String encrypt, String signature) { public boolean checkSignature(String timestamp, String nonce, String encrypt, String signature) {
try { try {
return SHA1.gen(getWxOpenConfigStorage().getComponentToken(), timestamp, nonce, encrypt)
.equals(signature);
ServerVerification verification = new ServerVerification();
String newMsgSignature = verification.getMsgSignature(getWxOpenConfigStorage().getComponentToken(),timestamp, nonce, encrypt);
return verification.verify(signature,newMsgSignature);
} catch (Exception e) { } catch (Exception e) {
this.log.error("Checking signature failed, and the reason is :" + e.getMessage()); this.log.error("Checking signature failed, and the reason is :" + e.getMessage());
return false; return false;


+ 3
- 3
mallinkService/src/main/java/com/iformall/service/toutiao/utils/ServerVerification.java View File

@@ -5,7 +5,7 @@ import java.security.MessageDigest;


public class ServerVerification { public class ServerVerification {


private String getMsgSignature(String tpToken, String timestamp, String nonce, String encrypt) throws Exception {
public String getMsgSignature(String tpToken, String timestamp, String nonce, String encrypt) throws Exception {
String[] values = new String[] {tpToken, timestamp, nonce, encrypt}; String[] values = new String[] {tpToken, timestamp, nonce, encrypt};
Arrays.sort(values); Arrays.sort(values);


@@ -41,9 +41,9 @@ public class ServerVerification {
} }
} }


private void verify(String msgSignature, String newMsgSignature) {
public boolean verify(String msgSignature, String newMsgSignature) {
boolean res = msgSignature.equals(newMsgSignature); boolean res = msgSignature.equals(newMsgSignature);
System.out.println(res);
return res;
} }


public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {


Loading…
Cancel
Save