PFinal\Wechat\Service\PayService::notify PHP Method

notify() public static method

获取微信支付异步通知。(支付金额单位已转为元) 成功返回通知信息数组,失败返回null
public static notify ( ) : array
return array [ $mch_id //微信支付分配的商户号 $appid //微信分配的公众账号ID $openid //用户在商户appid下的唯一标识 $transaction_id //微信支付订单号 $out_trade_no //商户订单号 $total_fee //订单总金额单位默认为分,已转为元 $is_subscribe //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效 $attach //商家数据包,原样返回 $time_end //支付完成时间 ]
    public static function notify()
    {
        $config = self::getConfig();
        $postStr = file_get_contents('php://input');
        /*
        $postStr = '<xml>
        <appid><![CDATA[wx00e5904efec77699]]></appid>
        <attach><![CDATA[支付测试]]></attach>
        <bank_type><![CDATA[CMB_CREDIT]]></bank_type>
        <cash_fee><![CDATA[1]]></cash_fee>
        <fee_type><![CDATA[CNY]]></fee_type>
        <is_subscribe><![CDATA[Y]]></is_subscribe>
        <mch_id><![CDATA[1220647301]]></mch_id>
        <nonce_str><![CDATA[a0tZ41phiHm8zfmO]]></nonce_str>
        <openid><![CDATA[oU3OCt5O46PumN7IE87WcoYZY9r0]]></openid>
        <out_trade_no><![CDATA[550bf2990c51f]]></out_trade_no>
        <result_code><![CDATA[SUCCESS]]></result_code>
        <return_code><![CDATA[SUCCESS]]></return_code>
        <sign><![CDATA[F6F519B4DD8DB978040F8C866C1E6250]]></sign>
        <time_end><![CDATA[20150320181606]]></time_end>
        <total_fee>1</total_fee>
        <trade_type><![CDATA[JSAPI]]></trade_type>
        <transaction_id><![CDATA[1008840847201503200034663980]]></transaction_id>
        </xml>';
        */
        $postObj = @simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
        if ($postObj === false) {
            Log::error('parse xml error: ' . $postStr);
            return;
        }
        if ($postObj->return_code != 'SUCCESS') {
            Log::error($postObj->return_msg);
            return;
        }
        if ($postObj->result_code != 'SUCCESS') {
            Log::error($postObj->result_code);
            return;
        }
        $arr = (array) $postObj;
        unset($arr['sign']);
        if (self::getSign($arr, $config['key']) === "{$postObj->sign}") {
            // $mch_id = $postObj->mch_id;  //微信支付分配的商户号
            // $appid = $postObj->appid; //微信分配的公众账号ID
            // $openid = $postObj->openid; //用户在商户appid下的唯一标识
            // $transaction_id = $postObj->transaction_id;//微信支付订单号
            // $out_trade_no = $postObj->out_trade_no;//商户订单号
            // $total_fee = $postObj->total_fee; //订单总金额,单位为分
            // $is_subscribe = $postObj->is_subscribe; //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
            // $attach = $postObj->attach;//商家数据包,原样返回
            // $time_end = $postObj->time_end;//支付完成时间
            echo '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
            //金额单位转为元
            $postObj->total_fee = self::calc($postObj->total_fee, 100, '/', 2);
            return $postObj;
        } else {
            Log::error('sign error');
        }
    }