예제 #1
0
        $params = array_merge($get, $post);
        $options['ca_cert_path'] = $config['ca_cert_path'];
        $options['sign_type'] = 'MD5';
        $options['request_params'] = $params;
        $cache->save(LAST_NOTIFY_CACHE_KEY, array('url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'get' => http_build_query($get), 'post' => http_build_query($post)));
        $response = $gateway->completePurchase($options)->send();
        if ($response->isSuccessful() && $response->isTradeStatusOk()) {
            //todo success
            // if u use the wap alipay u need to parse the trade info from .notify_data
            $params = \Omnipay\Utils\Utils::format_wap_alipay_notify($params);
            $no = $params['out_trade_no'];
            $opts = $cache->fetch($no);
            $opts['notify'] = array('_GET' => $get, '_POST' => $post);
            $opts['status'] = '支付成功';
            $cache->delete(LAST_ERROR_CACHE_KEY);
            $cache->save(LAST_NOTIFY_CACHE_KEY, array('url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'get' => http_build_query($get), 'post' => http_build_query($post), 'out_trade_no' => $no, 'status' => 'success'));
            $cache->save($no, $opts);
            // success return 'success' to response to tell alipay's server, to stop continuing notify request
            //            die('continue') //return continue just for debug;
            die('success');
        } else {
            $cache->save(LAST_ERROR_CACHE_KEY, $options);
            die('fail');
        }
    } catch (\Exception $e) {
        $cache->save(LAST_ERROR_CACHE_KEY, $e->getLine() . ': ' . $e->getMessage());
        die('exception');
    }
}
notify_callback($config, $_GET, $_POST);
예제 #2
0
function notify_callback($config, $get, $raw_post)
{
    $cache = get_cache();
    try {
        $gateway = new \Omnipay\Wechat\ExpressGateway();
        $gateway->setAppId($config['app_id']);
        $gateway->setKey($config['pay_sign_key']);
        $gateway->setPartner($config['partner']);
        $gateway->setPartnerKey($config['partner_key']);
        $cache->save(LAST_NOTIFY_CACHE_KEY, func_get_args());
        $response = $gateway->completePurchase(array('request_params' => $get, 'body' => $raw_post))->send();
        if ($response->isSuccessful() && $response->isTradeStatusOk()) {
            //todo success
            $serial = $cache->fetch($get['out_trade_no']);
            $serial['notify'] = array('status' => 'success', 'param' => http_build_query($get), 'body' => $raw_post);
            $data = json_decode(json_encode(simplexml_load_string($raw_post, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
            $cache->save($get['out_trade_no'], $serial);
            $cache->save(LAST_NOTIFY_CACHE_KEY, array('param' => http_build_query($get), 'body' => $raw_post, 'data' => $data, 'status' => $response->getMessage()));
            $cache->delete(LAST_ERROR_CACHE_KEY);
            die($response->getMessage());
            //            die('success');
        } else {
            die($response->getMessage());
        }
    } catch (\Exception $e) {
        $cache->save(LAST_ERROR_CACHE_KEY, $e->getLine() . ': ' . $e->getMessage());
        die('exception: ' . $e->getLine() . ' - ' . $e->getMessage());
    }
}
notify_callback($config, $_GET, empty($_POST) ? file_get_contents('php://input') : $_POST);