php端-微信支付的異步通知獲取&解析&回調結果通知


獲取微信返回的數據

  file_get_contents("php://input");

微信支付通知結果的參數字典

https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7

獲取的通知數據轉換為Array

  public function xmlToArray($xml=''){
    $temp  = json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA));
    return json_decode($temp, true);
  }
  $testxml  = file_get_contents("php://input");
  $jsonxml = json_encode(simplexml_load_string($testxml, 'SimpleXMLElement', LIBXML_NOCDATA));
  $result = json_decode($jsonxml, true);//轉成數組,

在回調里面給微信通知-回調成功

  echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';

數組轉xml


function arrayToXml($arr) {
    $xml = "<xml>";
    foreach ($arr as $key => $val){
        if (is_numeric($val)){
            $xml.="<$key>$val</$key>";
        }
        else
            $xml.="<$key><![CDATA[$val]]></$key>";
    }
    $xml.="</xml>";
    return $xml;
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM