在日常开发中用到签名的几种写法

第一种:

function getMd5(){

    $seqno = time();
    $apiid = 2;
    $ysid = 20170505011;
    $token =  urlencode('Token');
    $typeid = 1;
    $ip = urlencode('192.168.2.192');
    $clientid = 1;
    $sourceid = 6;
    $eipid = 1;
    $portid = 1103902;
    $isdes = 1;
    $return = urlencode('');
    $code = 0;
    $codemessage = urlencode('');
    $sendmessage = urlencode(json_encode([
        "SEND"      => '',
        "LISTID"    => '',
        "PAGEBASE"  => 10,
        "PAGEID"    =>  1,
        "PAGES"     =>  0,
        "ISDES"     =>  0,
        "ISSPECIAL" => '',
        "SWHERE"    => '',
        "SORDERBY"  => '',
        "IP"        => '192.168.2.192',
        "SKEYS"     => ''
    ], JSON_UNESCAPED_UNICODE));
    $params  = '';
    $params .= "SEQNO:{$seqno};";
    $params .= "APIID:{$apiid};";
    $params .= "YSID:{$ysid};";
    $params .= "TOKEN:{$token};";
    $params .= "TYPEID:{$typeid};";
    $params .= "IP:{$ip};";
    $params .= "CLIENTID:{$clientid};";
    $params .= "EIPID:{$eipid};";
    $params .= "SOURCEID:{$sourceid};";
    $params .= "PORTID:{$portid};";
    $params .= "ISDES:{$isdes};";
    $params .= "SEND:{$sendmessage};";
    $params .= "RETURN:{$return};";
    $params .= "CODE:{$code};";
    $params .= "CODEMESSAGE:{$codemessage};";
    return $params;
}

function getSign(){
    $seqno = time();
    $apiid = 2;
    $ysid = 20170505011;
    $token =  'Token';
    $typeid = 1;
    $ip = '192.168.2.192';
    $clientid = 1;
    $sourceid = 6;
    $eipid = 1;
    $portid = 1103902;
    $isdes = 1;
    $return = '';
    $code = 0;
    $codemessage = '';
    $md5 = strtoupper(MD5(getMd5()));
    $sendmessage = urlencode(json_encode([
        "SEND"      => '',
        "LISTID"    => '',
        "PAGEBASE"  => 10,
        "PAGEID"    =>  1,
        "PAGES"     =>  0,
        "ISDES"     =>  0,
        "ISSPECIAL" => '',
        "SWHERE"    => '',
        "SORDERBY"  => '',
        "IP"        => '192.168.2.192',
        "SKEYS"     => ''
    ], JSON_UNESCAPED_UNICODE));
    $params  = '';
    $params .= "SEQNO:{$seqno};";
    $params .= "APIID:{$apiid};";
    $params .= "YSID:{$ysid};";
    $params .= "TOKEN:{$token};";
    $params .= "TYPEID:{$typeid};";
    $params .= "IP:{$ip};";
    $params .= "CLIENTID:{$clientid};";
    $params .= "EIPID:{$eipid};";
    $params .= "SOURCEID:{$sourceid};";
    $params .= "PORTID:{$portid};";
    $params .= "ISDES:{$isdes};";
    $params .= "SEND:{$sendmessage};";
    $params .= "RETURN:{$return};";
    $params .= "CODE:{$code};";
    $params .= "CODEMESSAGE:{$codemessage};";
    $params .= "MD5:{$md5};";
    return $params;
}

上面两个组合一下:

function getResult($where='',$send='',$pid,$listid='',$skeys='',$pagebase='',$pageid='',$pages=''){

    $seqno = time();
    $apiid = APIID;
    $ysid = YSID;
    $token =  urlencode(TOKEN);
    $typeid = TYPEID;
    $ip = urlencode(IP);
    $clientid = CLIENTID;
    $sourceid = SOURCEID;
    $eipid = EIPID;
    $portid = $pid;
    $isdes = 1;
    $return = urlencode('');
    $code = CODE;
    $codemessage = urlencode('');
    $sendmessage = urlencode(json_encode([
        "SEND"      => $send,
        "LISTID"    => $listid,
        "PAGEBASE"  => $pagebase,
        "PAGEID"    => $pageid,
        "PAGES"     => $pages,
        "ISDES"     =>  0,
        "ISSPECIAL" => '',
        "SWHERE"    => $where,
        "SORDERBY"  => '',
        "IP"        => IP,
        "SKEYS"     => $skeys
    ], JSON_UNESCAPED_UNICODE));
    $param  = '';
    $param .= "SEQNO:{$seqno};";
    $param .= "APIID:{$apiid};";
    $param .= "YSID:{$ysid};";
    $param .= "TOKEN:{$token};";
    $param .= "TYPEID:{$typeid};";
    $param .= "IP:{$ip};";
    $param .= "CLIENTID:{$clientid};";
    $param .= "EIPID:{$eipid};";
    $param .= "SOURCEID:{$sourceid};";
    $param .= "PORTID:{$portid};";
    $param .= "ISDES:{$isdes};";
    $param .= "SEND:{$sendmessage};";
    $param .= "RETURN:{$return};";
    $param .= "CODE:{$code};";
    $param .= "CODEMESSAGE:{$codemessage};";
    $md5 = strtoupper(MD5($param));
    $sendmessage = urlencode(json_encode([
        "SEND"      => $send,
        "LISTID"    => $listid,
        "PAGEBASE"  => $pagebase,
        "PAGEID"    => $pageid,
        "PAGES"     => $pages,
        "ISDES"     =>  0,
        "ISSPECIAL" => '',
        "SWHERE"    => $where,
        "SORDERBY"  => '',
        "IP"        => IP,
        "SKEYS"     => $skeys
    ], JSON_UNESCAPED_UNICODE));
    $params  = '';
    $params .= "SEQNO:{$seqno};";
    $params .= "APIID:{$apiid};";
    $params .= "YSID:{$ysid};";
    $params .= "TOKEN:{$token};";
    $params .= "TYPEID:{$typeid};";
    $params .= "IP:{$ip};";
    $params .= "CLIENTID:{$clientid};";
    $params .= "EIPID:{$eipid};";
    $params .= "SOURCEID:{$sourceid};";
    $params .= "PORTID:{$portid};";
    $params .= "ISDES:{$isdes};";
    $params .= "SEND:{$sendmessage};";
    $params .= "RETURN:{$return};";
    $params .= "CODE:{$code};";
    $params .= "CODEMESSAGE:{$codemessage};";
    $params .= "MD5:{$md5};";
    return $params;
}

第二种:

<?php
class AppUtil{
	/**
	 * 将参数数组签名
	 */
	public static function SignArray(array $array,$appkey){
		$array['key'] = $appkey;// 将key放到数组中一起进行排序和组装
		ksort($array);
		$blankStr = AppUtil::ToUrlParams($array);
		$sign = md5($blankStr);
		return $sign;
	}
	
	public static function ToUrlParams(array $array)
	{
		$buff = "";
		foreach ($array as $k => $v)
		{
			if($v != "" && !is_array($v)){
				$buff .= $k . "=" . $v . "&";
			}
		}
		
		$buff = trim($buff, "&");
		return $buff;
	}
	
/**
	 * 校验签名
	 * @param array 参数
	 * @param unknown_type appkey
	 */
	public static function ValidSign(array $array,$appkey){
		$sign = $array['sign'];
		unset($array['sign']);
		$array['key'] = $appkey;
		$mySign = AppUtil::SignArray($array, $appkey);
		return strtolower($sign) == strtolower($mySign);
	}
	
	
}
?>

 

日常项目开发使用Spring Security,需要注意以下几点: 1. 配置正确的Security策略和过滤器链:Spring Security提供了多种策略和过滤器链,需要根据自己的需求进行正确的配置。配置不正确可能会导致安全漏洞或者无法正确通过认证。 2. 用户认证和授权:Spring Security提供了多种认证和授权方式,需要根据自己的需求进行选择。在进行用户认证和授权时,需要确保用户的密码安全存储,同时需要注意安全漏洞和攻击。 3. CSRF防御:跨站请求伪造是一种常见的网络攻击方式,Spring Security提供了多种防御CSRF攻击的方式,需要正确配置和使用。 4. 密码安全:在使用Spring Security进行用户认证时,需要确保用户密码的安全存储和加密,防止密码泄露和攻击。 5. 安全漏洞:在使用Spring Security进行开发时,需要注意常见的安全漏洞,如SQL注入、XSS攻击、文件上传漏洞等,并进行相应的防御措施。 在使用Spring Security进行开发时,可能会遇到以下难点: 1. 配置复杂:Spring Security提供了多种配置选项和策略,需要根据自己的需求进行正确的配置,有时可能会比较复杂。 2. 安全漏洞:在使用Spring Security进行开发时,需要注意常见的安全漏洞,如SQL注入、XSS攻击、文件上传漏洞等,并进行相应的防御措施。这需要开发人员具有一定的安全意识和经验。 3. 认证和授权:Spring Security提供了多种认证和授权方式,需要根据自己的需求进行选择。在进行用户认证和授权时,需要确保用户的密码安全存储,同时需要注意安全漏洞和攻击。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值