第一种:
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);
}
}
?>