php微信支付回调验证
//字典排序拼接字符串 function getWxPaySignature($arr){ ksort($arr); $str = ''; foreach ($arr as $k=>$v){ if($k != "sign" && $v != "" && !is_array($v)){ $str .= $k . "=" . $v . "&"; } } $str = trim($str,'&'); return $str; } //微信回调验证 function weCallbackCheck($xml){ $signArr = (array)$xml; $sign = $signArr['sign']; $stringA = getWxPaySignature($signArr);//数组字典排序拼接字符串 $stringSignTemp = $stringA.'&key=xxx';//设置的key $signValue = md5($stringSignTemp); $signValue = strtoupper($signValue); if($signValue == $sign){ return 'success';//支付成功 }else{ return 'failure'; } } //使用方法 $xmlstr = file_get_contents("php://input"); $xml=simplexml_load_string($xmlstr, 'SimpleXMLElement', LIBXML_NOCDATA); if(weCallbackCheck($xml)=="success"){ //todo }