Commit e10ff338 authored by liuyuzhen's avatar liuyuzhen

测试

parent 8a860b4d
...@@ -128,11 +128,13 @@ class TencentPay { ...@@ -128,11 +128,13 @@ class TencentPay {
/** /**
* 作用:设置标配的请求参数,生成签名,生成接口参数xml * 作用:设置标配的请求参数,生成签名,生成接口参数xml
*/ */
function createXml() function createXml($signType='MD5')
{ {
if($signType=='MD5'){
$this->parameters["sign"] = $this->getSign($this->parameters);//签名 $this->parameters["sign"] = $this->getSign($this->parameters);//签名
}else{
$this->parameters["sign"] = $this->getHMACSHA1Sign($this->parameters,'sha256');
}
return $this->arrayToXml($this->parameters); return $this->arrayToXml($this->parameters);
} }
...@@ -258,7 +260,9 @@ class TencentPay { ...@@ -258,7 +260,9 @@ class TencentPay {
//签名步骤一:按字典序排序参数 //签名步骤一:按字典序排序参数
ksort($Parameters); ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false); $String = $this->formatBizQueryParaMap($Parameters, false);
$String = $String."&key=".$this->key; $String = $String."&key=".$this->key;
\Our\Log::getInstance()->write($this->key,'/data/log/applognew');
//签名步骤三:MD5加密 //签名步骤三:MD5加密
$String = md5($String); $String = md5($String);
$result_ = strtoupper($String); $result_ = strtoupper($String);
...@@ -269,7 +273,7 @@ class TencentPay { ...@@ -269,7 +273,7 @@ class TencentPay {
/** /**
* 作用:生成签名(按照HMAC-SHA1规则签名) * 作用:生成签名(按照HMAC-SHA1规则签名)
*/ */
public function getHMACSHA1Sign($Obj) public function getHMACSHA1Sign($Obj,$signType ='sha1')
{ {
foreach ($Obj as $k => $v) foreach ($Obj as $k => $v)
{ {
...@@ -280,7 +284,7 @@ class TencentPay { ...@@ -280,7 +284,7 @@ class TencentPay {
$String = $this->formatBizQueryParaMap($Parameters, false); $String = $this->formatBizQueryParaMap($Parameters, false);
//$String = $String."&key=".$this->key; //$String = $String."&key=".$this->key;
//签名步骤三:HMAC-SHA1加密 //签名步骤三:HMAC-SHA1加密
$String = hash_hmac('sha1',$String,$this->key); $String = hash_hmac($signType,$String,$this->key);
$result_ = base64_encode($String); $result_ = base64_encode($String);
return $result_; return $result_;
} }
...@@ -350,6 +354,19 @@ class TencentPay { ...@@ -350,6 +354,19 @@ class TencentPay {
} }
/**
* 作用:产生随机字符串,不长于32位
*/
public function createNoncestr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}
/** /**
* 将xml数据返回微信 * 将xml数据返回微信
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment