$value){ if($value === 0 || !empty($value)){ $stringA .=$key.'='.$value; if($i != count($parm)){ $stringA .= '&'; } } $i++; } }else{ return ResultWrapper::fail('对参数排序出错', ErrorCode::$paramError); } echo $stringA.PHP_EOL; //在stringA最后拼接上key=商户支付密钥 $stringSignTemp = $stringA.'45c87Fa0352211e78D40d4977a9Ea871'; $signValue = md5($stringSignTemp); return $signValue; } function getSignContent($params , $app_secret='', $charset='UTF-8') { unset($params['risk_info']); unset($params['sign']); ksort($params); $stringToBeSigned = ""; $i = 0; foreach ($params as $k => $v) { if(!isset($v) || $v === null || trim($v) === "" || "@" == substr($v, 0, 1)){ continue; } // 转换成目标字符集 if (!empty($v)) { $fileType = "UTF-8"; if (strcasecmp($fileType, $charset) != 0) { $v = mb_convert_encoding($v, $charset, $fileType); } } if ($i == 0) { $stringToBeSigned .= "$k" . "=" . "$v"; } else { $stringToBeSigned .= "&" . "$k" . "=" . "$v"; } $i++; } unset ($k, $v); var_dump($stringToBeSigned); return md5($stringToBeSigned.'45c87Fa0352211e78D40d4977a9Ea871'); }