tatu

更新时间:2023-01-04 07:53:04 阅读: 评论:0


2023年1月4日发(作者:rang)

接⼝签名(sign)

⼀版

;

;

ject;

Req;

Utils;

ils;

Utils;

;

Map;

p;

/**

*Createdbywanggson2017/9/28.

*/

publicclassReadedCa{

@Test

publicvoidreadedTest(){

ReadedReqreadedReq=newReadedReq();

(1);

ipients("1");

JSONObjectobject=(JSONObject)(readedReq);

SortedMapmap=newTreeMap<>();

for(Stringkey:()){

if(("sign")){

continue;

}

Stringvalue=ing(key);

if(lank(value))

(key,value);

}

n(map);

Stringsign=nature(map);

("sign",sign);

StringjsonString=String();

n(jsonString);

Stringurl="localhost:8080/phatent-front/readed/";

Stringresult=ringBody(url,jsonString);

n(result);

}

}

⼆版

;

ist;

;

;

Map;

p;

luePair;

ameValuePair;

;

ject;

Utils;

ils;

/**

*Createdbywanggson2017/9/28.

*/

publicclassReadedCa{

@Test

publicvoidreadedTest(){

SortedMapmap=newTreeMap();

("noticeId","1");

("memberId","2");

Stringsign=nature(map);

n(sign);

("sign",sign);

ListnameValues=newArrayList();

for(entry:et()){

(newBasicNameValuePair((),ue()));

}

n("nameValues=========>>"+nameValues);

Stringurl=":9091/readed/";

JSONObjectresult=pJson(url,nameValues);

n(result);

}

}

签收加密

;

eDigest;

;

Map;

;

Key;

KeyFactory;

Spec;

meterSpec;

Utils;

;

Factory;

64;

nst;

/**

*CryptoUtils

*@author

*@version1.0

*@since2017年8⽉18⽇下午3:04:26

*/

publicclassCryptoUtils{

publicclassCryptoUtils{

privatestaticfinalLoggerLOGGER=ger();

privatestaticSecretKeyKEY;

privatestaticIvParameterSpecIV;

static{

try{

intkeyLength=8;

StringdesKey=ue(_KEY_CONF);

if(()>keyLength){

desKey=ing(0,keyLength);

}

byte[]rgbKey=es(T_CHARSET);

StringdesIv=ue(_IV_CONF);

if(()>keyLength){

desIv=ing(0,keyLength);

}

byte[]rgbIV=es(T_CHARSET);

SecretKeyFactorykeyFactory=tance("DES");

DESKeySpecdesKeySpec=newDESKeySpec(rgbKey);

KEY=teSecret(desKeySpec);

IV=newIvParameterSpec(rgbIV);

}catch(Exceptione){

("encryptkeyandiviniterror.",e);

}

}

publicstaticStringencrypt(Stringstr){

if(k(str))

returnnull;

if(KEY==null||IV==null)

returnnull;

byte[]byteArray=null;

try{

byte[]strByteArray=es(T_CHARSET);

Ciphercipher=tance("DES/CBC/PKCS5Padding");

(T_MODE,KEY,IV);

byteArray=l(strByteArray);

}catch(Exceptione){

("encrypterror.",e);

}

(byteArray);

}

publicstaticStringdecrypt(Stringstr){

if(k(str))

returnnull;

if(KEY==null||IV==null)

returnnull;

byte[]byteArray;

Stringresult=null;

try{

Ciphercipher=tance("DES/CBC/PKCS5Padding");

(T_MODE,KEY,IV);

byteArray=l((str));

result=newString(byteArray,T_CHARSET);

}catch(Exceptione){

("decrypterror.",e);

}

returnresult;

}

/**

*参数DM5加密并Ba64转码加密

*@paramstr

*@return

*/

publicstaticStringmd5AndBa64(Stringstr){

(md5Encrypt(str));

}

/**

*参数DM5签名字节码

*@paramencryptStr

*@return

*/

privatestaticbyte[]md5Encrypt(StringencryptStr){

try{

MessageDigestmd5=tance("MD5");

(es("utf8"));

();

}catch(Exceptione){

thrownewRuntimeException(e);

}

}

publicstaticStringgetSignature(SortedMapmap){

if(map!=null&&()>0){

StringBuilderbuilder=newStringBuilder();

for(Entryentry:et()){

if(().equals("sign")){

continue;

}

(()+"="+ue());

("&");

}

("key="+ue(5_KEY_CONF));

StringsignString=ng();

("signstring:{}",signString);

Stringresult=md5AndBa64(signString);

("datamd5AndBa64result:{}",result);

returnresult;

}

returnnull;

}

}

验证签名

;

ce;

Utils;

;

Factory;

ller;

tBody;

tMapping;

Body;

;

ject;

Req;

Bean;

Statu;

Utils;

;

;

;

ServiceBean;

ServiceBean;

ServiceBean;

cAction;

Map;

p;

/**

*Createdby

*消息阅读接⼝

*/

*/

@Controller

@RequestMapping("readed")

publicclassReadedActionextendsGenericAction{

privatestaticfinallongrialVersionUID=1L;

privatestaticLoggerlogger=ger();

@Resource

privateNoticeServiceBeannoticeServiceBean;

@Resource

privateMemberServiceBeanmemberServiceBean;

@Resource

privateReadedServiceBeanreadedServiceBean;

@ResponBody

@RequestMapping(CREATE)

publicJSONObjectreaded(@RequestBodyStringbody){

ResultBeanresult=null;

ReadedReqreq=null;

if(lank(body)){

//验证签名

JSONObjectresultSign=checkSign(body);

if(resultSign!=null)returnresultSign;

//反序列化json对象

req=bject(body,);

//校验参数

JSONObjectjsonObject=checkReq(req);

if(jsonObject!=null)

returnjsonObject;

//收件⼈不为空

if(lank(ipients())){

Membermember=GuidCode(ipients());

Noticenotice=ReceiveId(());

if(member!=null){

Readedread=newReaded();

berId(());

iceId(());

//保存

(read);

result=newResultBean(ResultStatu.X0000,null,"处理成功");

return(JSONObject)(result);

}

result=newResultBean(ResultStatu.X1004,null,"会员不存在");

return(JSONObject)(result);

}

}

result=newResultBean(ResultStatu.X1000,null,"参数为空");

return(JSONObject)(result);

}

/**

*验证签名

*@parambody

*@return

*/

privateJSONObjectcheckSign(@RequestBodyStringbody){

ResultBeanresult;

JSONObjectparamObject=bject(body);

if(paramObject==null){

result=newResultBean(ResultStatu.X1001,null,"参数格式错误");

return(JSONObject)(result);

}

SortedMapparamMap=newTreeMap();

Stringsign=null;

for(Stringkey:()){

if("sign".equals(key)){

sign=ing(key);

continue;

}

(key,ing(key));

}

("map>>>>>>>>>>>{}",paramMap);

if(k(sign)){

result=newResultBean(ResultStatu.X1000,null,"参数签名为空");

result=newResultBean(ResultStatu.X1000,null,"参数签名为空");

return(JSONObject)(result);

}

//⽣成签名

StringparamSign=nature(paramMap);

("sign>>>>>>>>>>>{},encryptsign>>>>>>>>>>{}",sign,paramSign);

//判断签名是否⼀致

if(!(sign)){

result=newResultBean(ResultStatu.X1000,null,"参数签名错误");

return(JSONObject)(result);

}

returnnull;

}

/**

*校验参数

*@paramreaded

*@return

*/

privateJSONObjectcheckReq(ReadedReqreaded){

ResultBeanresult;

if(()==null){

result=newResultBean(ResultStatu.X1000,null,"消息id为空");

return(JSONObject)(result);

}

Noticenotice=ReceiveId(());

if(notice==null){

result=newResultBean(ResultStatu.X1004,null,"数据不存在");

return(JSONObject)(result);

}

returnnull;

}

}

验证签名已经在拦截器中处理

;

ist;

;

ce;

Utils;

luePair;

ameValuePair;

;

Factory;

ller;

tMapping;

Body;

;

ject;

Req;

Bean;

onst;

tatu;

Statu;

Utils;

ils;

Utils;

;

;

;

ServiceBean;

ServiceBean;

ServiceBean;

cAction;

cAction;

/**

*Createdbywanggson2017/9/15.

*消息阅读接⼝

*/

@Controller

@RequestMapping("readed")

publicclassReadedActionextendsGenericAction{

privatestaticfinallongrialVersionUID=1L;

privatestaticLoggerlogger=ger();

@Resource

privateNoticeServiceBeannoticeServiceBean;

@Resource

privateMemberServiceBeanmemberServiceBean;

@Resource

privateReadedServiceBeanreadedServiceBean;

@ResponBody

@RequestMapping(CREATE)

publicJSONObjectreaded(ReadedReqform){

ResultBeanresult=null;

//校验参数

if(iceId()==null){

result=newResultBean(ResultStatu.X1000,null,"消息id为空");

return(JSONObject)(result);

}

IntegerreceiveId=eiveId();

IntegernoticeId=iceId();

Noticenotice=(noticeId);

if(notice==null||tu()==null||tu()!=D){

result=newResultBean(ResultStatu.X1004,null,"数据不存在");

return(JSONObject)(result);

}

IntegermemberId=berId();

//收件⼈不为空

if(memberId!=null){

IntegerreadedId=(memberId,noticeId);

if(readedId==null){

Readedread=newReaded();

berId(memberId);

iceId(noticeId);

(read);

}

if(receiveId!=null&&ue()>0&&eiveId().intValue()==ue()){

Membermember=(memberId);

if(member!=null&&lank(dCode())){

longtimeMillis=tTimeMillis();

Stringsign=5Encrypt(_KEY+timeMillis+_SECRET,null);

("paramsmd5sign>>>>>>>>>{}",sign);

Stringurl=ue(_EDU_NOTICE_CALLBACK_URL_CONF);

Listparams=newArrayList();

(newBasicNameValuePair("id",f(receiveId)));

(newBasicNameValuePair("key",_KEY));

(newBasicNameValuePair("t",f(timeMillis)));

(newBasicNameValuePair("s",sign));

(newBasicNameValuePair("guid",dCode()));

JSONObjectobject=pJson(url,params);

("callbackreadnoticeresult>>>>>>>>>{}",object);

}

}

result=newResultBean(ResultStatu.X0000,null,"处理成功");

return(JSONObject)(result);

}

result=newResultBean(ResultStatu.X1004,null,"会员不存在");

return(JSONObject)(result);

}

}

拦截器

ptor;

Map;

rvletRequest;

rvletRespon;

Utils;

;

Factory;

e;

rMethod;

ndView;

rInterceptorAdapter;

;

Bean;

Statu;

Utils;

Utils;

@Service

publicclassAccessInterceptorextendsHandlerInterceptorAdapter{

privatestaticfinalLoggerLOGGER=ger();

@Override

publicbooleanpreHandle(HttpServletRequestrequest,HttpServletResponrespon,Objecthandler)throwsException{

racterEncoding("utf-8");

HandlerMethodmethod=(HandlerMethod)handler;

("{}",hod());

if(tentLength()>0){

dle(request,respon,handler);

}

Stringsign=ameter("sign");

if(k(sign)){

ResultBeanresult=newResultBean(ResultStatu.X1000,null,"签名参数为空");

ter().print(String(result));

returnfal;

}

SortedMapparamMap=ametersMap(request);

StringparamSign=nature(paramMap);

if(!(paramSign)){

ResultBeanresult=newResultBean(ResultStatu.X1001,null,"参数签名不正确");

ter().print(String(result));

returnfal;

}

dle(request,respon,handler);

}

publicvoidpostHandle(HttpServletRequestrequest,HttpServletResponrespon,Objecthandler,ModelAndViewmodelAndView)throwsException{

ndle(request,respon,handler,modelAndView);

}

}

本文发布于:2023-01-04 07:53:04,感谢您对本站的认可!

本文链接:http://www.wtabcd.cn/fanwen/fan/90/89564.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

上一篇:shenme
下一篇:forests
标签:tatu
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图