#获取到的微信返回内容
$xml = "
1
";
function xmlToArray($xml) {
//将XML转为array
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array_data;
}
$wx_back = xmlToArray($xml);
var_dump($wx_back);
//微信KEY
$wx_key="***********";
function getSign($data, $key) {
$String = formatParameters($data, false);
//签名步骤二:在string后加入KEY
$String = $String . "&key=" . $key;
echo "
parm:".$String."
";
//签名步骤三:MD5加密
$String = md5($String);
//签名步骤四:所有字符转为大写
$result_ = strtoupper($String);
return $result_;
}
function formatParameters($paraMap, $urlencode) {
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v) {
if($k=="sign"){
continue;
}
if ($urlencode) {
$v = urlencode($v);
}
$buff .= $k . "=" . $v . "&";
}
$reqPar;
if (strlen($buff) > 0) {
$reqPar = substr($buff, 0, strlen($buff) - 1);
}
return $reqPar;
}
$checkSign=getSign($wx_back, $wx_key);
echo "
getSign:".$checkSign;
if($checkSign==$wx_back['sign']){
#签名验证成功,核对价格后,执行逻辑代码
echo "
checkSign:success";
}