About callback verification process after the micro-channel pay

Reference Source:

https://www.php.cn/php-weizijiaocheng-407545.html

https://blog.csdn.net/rain_silently/article/details/79390377

https://blog.csdn.net/chenrui310/article/details/80830798

 

Ado, directly on the code:

 public  function Demo () 
    { 
        // Get micro-channel data callback 
        $ notifiedData = file_get_contents ( 'PHP: // INPUT' ); 

        // the XML format conversion 
        $ xmlObj = simplexml_load_string ( $ notifiedData , 'the SimpleXMLElement', LIBXML_NOCDATA);
         $ xmlObj = of json_decode (json_encode ( $ xmlObj ), to true ); 
        
        $ Key = "number of public Key" ; 

        // request back to the data format 
// $ xmlObj = [ 
// 'AppID' => 'wxf546a8df41c2ce18', 
// 'the attach' => 'product', 
// 'bank_type' => 'CFT', 
// 'cash_fee' => '1',
//            'fee_type' => 'CNY',
//            'is_subscribe' => 'Y',
//            'mch_id' => '1534940151',
//            'nonce_str' => 'jld6md2ky75emve7spsrf2tolturngrm',
//            'openid' => 'oyljP5y2HbOHsEAuOLpHP2dXQChw',
//            'out_trade_no' => '20190808164259728748651734197807',
//            'result_code' => 'SUCCESS',
//            'return_code' => 'SUCCESS',
//            'sign' => 'A68DC8C8E61DCA90D4454963982A7B12',
//            'time_end' => '20190808164308',
//            'total_fee' => '1',
//            'transaction_id' => '4200000342201908088760422065',
        

        $ xmlObj(IF
        // whether successful payment
//];
// 'trade_type' => 'JSAPI',[ 'the return_code'] == "SUCCESS" && $ xmlObj [ 'RESULT_CODE'] == "SUCCESS" ) { 

            // the signature remove 
            $ xmlSign = $ xmlObj [ 'Sign' ];
             the unset ( $ xmlObj [ 'Sign' ] ); 


            $ Sign = $ the this -> appgetSign ( $ xmlObj , $ Key ); 

            IF ( $ Sign === $ xmlSign ) 
            { 
                // verified, confirmation has been paid

                // Tell micro-channel not repeat notification 
return "<xml> <return_code> </ return_code> <return_msg> </ return_msg> </ xml> <[CDATA [SUCCESS]]!> <[CDATA [OK]]!>";
            } 
            
        } 
    } 


    / * 
     * Url parameter formatted into formatting parameters to generate a signature Sign 
     * / 
    Private  function appgetSign ( $ the Obj , $ appwxpay_key ) 
    { 

        the foreach ( $ the Obj  AS  $ K => $ V ) 
        { 
            $ the Parameters [ $ K ] = $ V ; 
        } 


        // signing step a: lexicographically ordered according to parameters 
        ksort ( $ the parameters );
         $ String = $ the this -> ToUrlParams ( $ the parameters ); 


        //Signature Step Two: After adding KEY String 

        IF ( $ appwxpay_key ) {
             $ String = $ String "Key = &.". $ Appwxpay_key ; 
        } 


        // signing step three: the MD5 encrypted 
        $ String = MD5 ( $ String ); 



        // signature step four: All characters to upper 
        $ result_ = the strtoupper ( $ String ); 


        return  $ result_ ; 
    } 


    Private  function ToUrlParams ( $ the Parameters ) 
    { 
        $ BUFF = "" ;
         the foreach ($Parameters as $k => $v)
        {
            if($k != "sign" && $v != "" && !is_array($v)){
                $buff .= $k . "=" . $v . "&";
            }
        }

        $buff = trim($buff, "&");
        return $buff;
    }

 

Guess you like

Origin www.cnblogs.com/laijinquan/p/11325249.html